import globalFn from '@/util/utils' import { http } from '@/api/APIindex' import nozzle from "@/util/interface" const common = { namespaced: true, state: { allDept:[], allRole:[], allCity:[], }, mutations: { //设置所有部门 SET_ALLDEPT:(state, allDept)=>{ state.allDept = allDept; }, //设置所有角色 SET_ALLROLE:(state, allRole)=>{ state.allRole = allRole; }, //设置所有城市 SET_ALLCITY:(state, allCity)=>{ state.allCity = allCity; } }, actions: { //获取所有部门 getAllDept({ commit }){ return new Promise((resolve, reject) => { http.post(nozzle.orgGetCurrentOrgTree,{}).then(res =>{ if(res.data.code === 1 || res.data.code === 200) { const treeArr = globalFn.handleTree(res.data.data,'orgId'); commit('SET_ALLDEPT',treeArr); resolve(res); }else{ reject() console.log(888); } }).catch(e =>{ reject(e) // console.log(999,e); }) }) }, //获取所有角色 getAllRole({ commit }){ http.post(nozzle.roleGetRoles,{}).then(res =>{ if(res.data.code === 1 || res.data.code === 200) { const treeArr = globalFn.handleTree(res.data.data,'roleId'); commit('SET_ALLROLE',treeArr); } }).catch(e =>{ console.log(e); }) }, //获取所有城市 getAllCity({ commit }){ http.post(nozzle.sysCityList,{}).then(res =>{ if(res.data.code === 1 || res.data.code === 200) { const treeArr = globalFn.handleTree(res.data.data,'id'); commit('SET_ALLCITY',treeArr); } }).catch(e =>{ console.log(e); }) } } } export default common