import { getSiteBusiness, getDepartment, getWindow } from "@/api/site";
export default {
  namespaced: true,
  state: {
    menus: [], // 菜单
    token: "",
    siteId: "", // 站点id
    userInfo: {}, // 用户信息
    sysName: "", // 系统名称
    sysLogo: "", // 系统logo
    path: "", // 门户跳转过来的路由
    areaTree: [], // 个人区域树
    businessList: [], // 站点业务列表
    deptList: [], // 站点部门列表
    windowList: [], // 站点窗口列表
  },
  getters: {
    siteId(state) {
      return state.siteId;
    },
    deptList(state) {
      return state.deptList;
    },
    userInfo(state) {
      return state.userInfo;
    },
    token(state) {
      return state.token;
    },
    path(state) {
      return state.path;
    },
  },
  mutations: {
    SET_path(state, path) {
      state.path = path;
    },
    SET_menus(state, menus) {
      state.menus = menus;
    },
    SET_siteId(state, siteId) {
      state.siteId = siteId;
    },
    SET_userInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
    SET_sysName(state, sysName) {
      state.sysName = sysName;
    },
    SET_sysLogo(state, sysLogo) {
      state.sysLogo = sysLogo;
    },
    SET_token(state, token) {
      state.token = token;
    },
    SET_areaTree(state, areaTree) {
      state.areaTree = areaTree;
    },
    SET_businessList(state, businessList) {
      state.businessList = businessList;
    },
    SET_deptList(state, deptList) {
      state.deptList = deptList;
    },
    SET_windowList(state, windowList) {
      state.windowList = windowList;
    },

    // 重置所有仓库状态
    reset: () => {},
  },
  actions: {
    // 获取站点业务列表
    getBusiness: async (context, siteId) => {
      let res = await getSiteBusiness({
        page: 1,
        size: -1,
        siteId,
      });
      if (res.data.code == 1) {
        let { data } = res.data.data;
        context.commit("SET_businessList", data);
      }
    },
    // 获取站点部门列表
    getDeptList: async (context, siteId) => {
      let res = await getDepartment({
        page: 1,
        size: -1,
        siteId,
      });
      if (res.data.code == 1) {
        let { data } = res.data.data;
        context.commit("SET_deptList", data);
      }
    },
    // 获取站点窗口列表
    getWindowList: async (context, siteId) => {
      let res = await getWindow({
        page: 1,
        size: -1,
        siteId,
      });
      if (res.data.code == 1) {
        let { data } = res.data.data;
        context.commit("SET_windowList", data);
      }
    },
  },
};
