import { queryDepartments } from "@/service/network";

// states
const state = {
  // deptList
  deptList: undefined
};

// mutations
const mutations = {
  SET_DEPART_LIST: (state, deptList) => {
    state.deptList = deptList;
  }
};

// actions
const actions = {
  // 部门级别数据查询
  async syncDepartInfo ({ commit, state }) {
    let deptList = state.deptList;
    if (!deptList) {
      const rsp = await queryDepartments();
      deptList = rsp.data;
      commit("SET_DEPART_LIST", deptList);
    }
    return deptList;
  }
};

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