import apiRulesApi from "@/js/api/apiRulesApi";

const state = {
    table: [],
    count: 0,
    isLoading: true
}
const mutations = {
    setTable(state, data) {
        state.table = data;
    },
    setCount(state, data) {
        state.count = data;
    },
    setLoading(state, status) {
        state.isLoading = status
    }
}

const actions = {
    queryPageable({commit}, pageData) {
        commit('setLoading', true);
        apiRulesApi.queryPageable(pageData.data, pageData.index, pageData.size, (response) => {
            if (response.data.code === 200) {
                commit('setTable', response.data.content);
                commit('setCount', parseInt(response.data.message));
                commit('setLoading', false);
            } else {
                commit('setLoading', false);
            }
        })
    }
}

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