/**
 * 固定接口获取
 */

import {getparameteritem} from "@/api/system/dictionary.js";
import {listdept} from "@/api/system/department.js"
import {listCommonuser} from "@/api/common.js"


const state = {
  unitTypeList: null, //数据字典--任务类型
  userList: null,
  askList:null,
  depList:null
}

const mutations = {
  setUnitTypeList(state, payload) {
    state.unitTypeList = payload;
  },
  setUserList(state, payload) {
    state.userList = payload;
  },
  setDepList(state, payload) {
    state.depList = playload
  }

}
const actions = {
  async getUnitTypeListApi({
    commit,
    state
  }) {
    if (!state.unitTypeList) {
      const res = await getparameteritem('unitTypeList');
      const data = res.detail;
      commit('setUnitTypeList', data);
    }
  },
  async getAskListApi({
    commit,
    state
  }) {
    if (!state.askList) {
      const res = await getparameteritem('askList');
      const data = res.detail;
      commit('setAskList', data);
    }
  },
  async getUserListApi({
    commit,
    state
  }) {
    if (!state.userList) {
      await listCommonuser({
          page_size: 999,
        }).
        then((res) => {
          let data = res.data ? res.data.reverse() : [];
          commit('setUserList', data);
        }).catch(error => {
          console.log(error)
        })
    }
  },
  async getDepListApi({
    commit,
    state
  }) {
    if (!state.depList) {
      const res = await listdept()
      commit('setDepList', data);
    }
  },
}
const getters = {
  getUnitTypeList: (state) => state.unitTypeList,
  getUserList: (state) => state.userList,
  getAskList: (state) => state.askList,
  getDepList: (state) => state.depList
}

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