import taskApi from '../api/taskApi'

const state = {
    tasks: [],
    total: 0,
    isLoading: false
}


const mutations = {
    setTasks(state, data) {
        state.tasks = data;
    },
    setTotal(state, data) {
        state.total = data;
    },
    setLoading(state, status) {
        state.isLoading = status
    }
}
const actions = {
    queryPageable({commit}, params) {
        commit('setLoading', true);
        taskApi.queryPageable(params.index, params.size, params.dataBody, (response) => {
            if (response.data.code === 200) {
                commit('setTasks', response.data.content);
                commit('setTotal', parseInt(response.data.message));
                commit('setLoading', false);
            } else {
                commit('setLoading', false);
            }
        })

    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}