import axios from "axios";

import router from "@/router";
import Layout from "@/layout/index.vue";

// 声明变量
const state = {
  collapse: false,
  activeIndex: "",
  username: "",
  password: "",
  api: "/hotel/ihotel/auto", // 线上
  // api: "/ihotel/auto", // 测试
  islogin: 1,
  hasRoutes: false,
  level: 1,
  roles: [
    {
      name: "roomStatus",
      meta: { isAuth: true, title: "房态管理" },
    },
    // 房型管理
    {
      name: "roomTypes",
      meta: { isAuth: true, title: "房型管理", sign: "roomTypes" },
      children: [
        {
          name: "roomType",
          meta: { isAuth: true, title: "房型管理" },
        },
        {
          name: "roomPrice",
          meta: { isAuth: true, title: "房价管理" },
        },
      ],
    },
    {
      name: "order",
      meta: { isAuth: true, title: "订单管理" },
    },
    // 授权管理
    {
      name: "classs",
      meta: { isAuth: true, title: "授权管理", sign: "classs" },
      children: [
        {
          name: "class",
          meta: { isAuth: true, title: "课表管理" },
        },
        {
          name: "process",
          meta: { isAuth: true, title: "流程管理" },
        },
      ],
    },
    {
      name: "statement",
      meta: { isAuth: true, title: "统计报表" },
    },
    // 设备管理
    {
      name: "doorLocks",
      meta: { isAuth: true, title: "设备管理", sign: "doorLocks" },
      children: [
        {
          name: "doorLock",
          meta: { isAuth: true, title: "门锁管理" },
        },
        {
          name: "meter",
          meta: { isAuth: true, title: "水电表管理" },
        },
      ],
    },
    // 组织架构
    {
      name: "users",
      meta: { isAuth: true, title: "组织架构", sign: "users" },
      children: [
        {
          name: "user",
          meta: { isAuth: true, title: "用户管理" },
        },
        {
          name: "userRoles",
          meta: { isAuth: true, title: "用户角色" },
        },
      ],
    },
    // {
    //   name: "accounts",
    //   meta: { isAuth: true, title: "账号管理", sign: "users" },
    //   children: [
    //     {
    //       name: "account",
    //       meta: { isAuth: true, title: "账号管理" },
    //     },
    //     {
    //       name: "roles",
    //       meta: { isAuth: true, title: "角色管理" },
    //     },
    //   ],
    // },
    {
      name: "account",
      meta: { isAuth: true, title: "账号管理" },
    },
    {
      name: "system",
      meta: { isAuth: true, title: "系统通知" },
    },
    // {
    //   path: "home/ICcard",
    //   name: "icCard",
    //   meta: { isAuth: true, title: "IC卡管理" },
    //   component: () => import("@/views/icCard"),
    // },
    // {
    //   path: "home/fingerprint",
    //   name: "fingerprint",
    //   meta: { isAuth: true, title: "指纹管理" },
    //   component: () => import("@/views/fingerprint"),
    // },
  ],
  statRoutes: {
    path: "/hotel",
    name: "hotel",
    component: Layout,
    meta: { isAuth: true, title: "公寓", icons: "" },
    children: [
      {
        path: "roomStatus",
        name: "roomStatus",
        meta: { isAuth: true, title: "房态管理" },
        component: () => import("@/views/roomStatus/roomStatus.vue"),
      },
      {
        path: "roomType",
        name: "roomType",
        meta: { isAuth: true, title: "房型管理", sign: "roomTypes" },
        component: () => import("@/views/roomType/roomType.vue"),
      },
      {
        path: "roomPrice",
        name: "roomPrice",
        meta: { isAuth: true, title: "房价管理", sign: "roomTypes" },
        component: () => import("@/views/roomPrice/roomPrice.vue"),
      },
      {
        path: "order",
        name: "order",
        meta: { isAuth: true, title: "订单管理" },
        component: () => import("@/views/order/order.vue"),
      },
      {
        path: "class",
        name: "class",
        meta: { isAuth: true, title: "课表管理", sign: "classs" },
        component: () => import("@/views/class/class.vue"),
      },
      {
        path: "process",
        name: "process",
        meta: { isAuth: true, title: "流程管理", sign: "classs" },
        component: () => import("@/views/process/process.vue"),
      },
      {
        path: "statement",
        name: "statement",
        meta: { isAuth: true, title: "统计报表" },
        component: () => import("@/views/statement/statement.vue"),
      },
      {
        path: "user",
        name: "user",
        meta: { isAuth: true, title: "用户管理", sign: "users" },
        component: () => import("@/views/user/user.vue"),
      },
      {
        path: "userRoles",
        name: "userRoles",
        meta: { isAuth: true, title: "用户角色", sign: "userRoles" },
        component: () => import("@/views/userRoles/userRoles.vue"),
      },
      {
        path: "roles",
        name: "roles",
        meta: { isAuth: true, title: "角色管理", sign: "users" },
        component: () => import("@/views/roles/roles.vue"),
      },
      {
        path: "doorLock",
        name: "doorLock",
        meta: { isAuth: true, title: "门锁管理", sign: "doorLocks" },
        component: () => import("@/views/doorLock/doorLock.vue"),
      },
      {
        path: "meter",
        name: "meter",
        meta: { isAuth: true, title: "水电表管理", sign: "doorLocks" },
        component: () => import("@/views/meter/meter.vue"),
      },
      {
        path: "account",
        name: "account",
        meta: { isAuth: true, title: "账号管理" },
        component: () => import("@/views/account/account.vue"),
      },
      {
        path: "system",
        name: "system",
        meta: { isAuth: true, title: "系统设置" },
        component: () => import("@/views/system/system.vue"),
      },
      // {
      //   path: "icCard",
      //   name: "icCard",
      //   meta: { isAuth: true, title: "IC卡管理" },
      //   component: () => import("@/views/icCard/icCard.vue"),
      // },
      // {
      //   path: "fingerprint",
      //   name: "fingerprint",
      //   meta: { isAuth: true, title: "指纹管理" },
      //   component: () => import("@/views/fingerprint/fingerprint.vue"),
      // },
    ],
  },
};

// 修改变量（state不能直接赋值修改，只能通过mutations）
const mutations = {
  menuClose: (state, value) => {
    state.collapse = value;
  },
  indexUp: (state, value) => {
    state.activeIndex = value;
    console.log(value);
    sessionStorage.setItem("sidevarItem", value);
  },
  userName: (state, value) => {
    state.username = value;
  },
  passWord: (state, value) => {
    state.password = value;
  },
  SET_ROUTES_STATE: (state, value) => {
    state.hasRoutes = value;
  },
  LEVEL: (state, value) => {
    state.level = value;
    console.log("设置level", value);
  },
  ADDROUTE: async (state, value) => {
    let roleList = JSON.parse(sessionStorage.getItem("roleList"));
    console.log(roleList);
    if (roleList) {
      router.addRoute({
        path: "/hotel",
        name: "hotel",
        component: Layout,
        children: [],
      });
      roleList.forEach((item) => {
        let list = item.route.split("/");
        let arr = {
          path: list[2],
          name: list[2],
          meta: { isAuth: true, title: item.name },
          component: () => import(`../../views/${list[2]}/${list[2]}.vue`),
        };
        router.addRoute("hotel", arr);
      });
      console.log("动态添加路由");
    }
  },
  ROLELIST: async (state, value) => {
    let datas = {
      permissionSettingId: value,
    };
    let ress = await axios({
      method: "get",
      url: state.api + "/login/menuBar",
      params: datas,
    });
    console.log(ress, "菜单权限");
    let roleList = [];
    let arrFlag = {};
    ress.data.data.forEach((i) => {
      if (i.name == "房态管理") {
        let roomStatus = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "预定") {
            roomStatus.yuding = j.status;
          } else if (j.functionPoint == "退房") {
            roomStatus.tuifang = j.status;
          } else if (j.functionPoint == "维修") {
            roomStatus.weixiu = j.status;
          } else if (j.functionPoint == "关房") {
            roomStatus.guanfang = j.status;
          } else if (j.functionPoint == "置脏") {
            roomStatus.zhizang = j.status;
          } else if (j.functionPoint == "置净") {
            roomStatus.zhijing = j.status;
          } else if (j.functionPoint == "退款") {
            roomStatus.tuikuan = j.status;
          } else if (j.functionPoint == "入住") {
            roomStatus.ruzhu = j.status;
          } else if (j.functionPoint == "锁房") {
            roomStatus.suofang = j.status;
          } else if (j.functionPoint == "换房") {
            roomStatus.huanfang = j.status;
          } else if (j.functionPoint == "开房") {
            roomStatus.kaifang = j.status;
          } else if (j.functionPoint == "开电") {
            roomStatus.kaidian = j.status;
          } else if (j.functionPoint == "关电") {
            roomStatus.guandian = j.status;
          } else if (j.functionPoint == "取消预定") {
            roomStatus.quxiaoyuding = j.status;
          } else if (j.functionPoint == "取消维修") {
            roomStatus.quxiaoweixiu = j.status;
          } else if (j.functionPoint == "查看密码") {
            roomStatus.chakanmima = j.status;
          } else if (j.functionPoint == "查看界面") {
            roomStatus.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "房态管理",
                path: "roomStatus",
                route: "/hotel/roomStatus",
              });
            }
          }
        });
        arrFlag.roomStatus = roomStatus;
        // sessionStorage.setItem("roomStatus", JSON.stringify(roomStatus));
      } else if (i.name == "楼栋单元管理") {
        let building = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            building.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            building.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            building.shanchu = j.status;
          } else if (j.functionPoint == "查看界面") {
            building.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "楼栋单元管理",
                path: "building",
                route: "/hotel/building",
              });
            }
          }
        });
        arrFlag.building = building;
        // sessionStorage.setItem("roomType", JSON.stringify(roomType));
      } else if (i.name == "房型管理") {
        let roomType = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            roomType.tianjia = j.status;
          } else if (j.functionPoint == "修改") {
            roomType.xiugai = j.status;
          } else if (j.functionPoint == "删除") {
            roomType.shanchu = j.status;
          } else if (j.functionPoint == "批量改价") {
            roomType.pilianggaijia = j.status;
          } else if (j.functionPoint == "改价记录") {
            roomType.gaijiajilu = j.status;
          } else if (j.functionPoint == "查看界面") {
            roomType.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "房型管理",
                path: "roomType",
                route: "/hotel/roomType",
              });
            }
          }
        });
        arrFlag.roomType = roomType;
        // sessionStorage.setItem("roomType", JSON.stringify(roomType));
      } else if (i.name == "房间列表") {
        let roomList = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            roomList.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            roomList.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            roomList.shanchu = j.status;
          } else if (j.functionPoint == "导入") {
            roomList.daoru = j.status;
          } else if (j.functionPoint == "查看界面") {
            roomList.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "房间列表",
                path: "roomList",
                route: "/hotel/roomList",
              });
            }
          }
        });
        arrFlag.roomList = roomList;
        // sessionStorage.setItem("roomType", JSON.stringify(roomType));
      } else if (i.name == "房价管理") {
        let roomPrice = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "批量改价") {
            roomPrice.pilianggaijia = j.status;
          } else if (j.functionPoint == "改价记录") {
            roomPrice.gaijiajilu = j.status;
          } else if (j.functionPoint == "查看界面") {
            roomPrice.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "房价管理",
                path: "roomPrice",
                route: "/hotel/roomPrice",
              });
            }
          }
        });
        arrFlag.roomPrice = roomPrice;
        // sessionStorage.setItem("roomPrice", JSON.stringify(roomPrice));
      } else if (i.name == "订单管理") {
        let order = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "取消") {
            order.quxiao = j.status;
          } else if (j.functionPoint == "详情") {
            order.xiangqing = j.status;
          } else if (j.functionPoint == "入住") {
            order.ruzhu = j.status;
          } else if (j.functionPoint == "退款") {
            order.tuikuan = j.status;
          } else if (j.functionPoint == "退房") {
            order.tuifang = j.status;
          } else if (j.functionPoint == "换房") {
            order.huanfang = j.status;
          } else if (j.functionPoint == "导出") {
            order.daochu = j.status;
          } else if (j.functionPoint == "备注") {
            order.beizhu = j.status;
          } else if (j.functionPoint == "查看界面") {
            order.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "订单管理",
                path: "order",
                route: "/hotel/order",
              });
            }
          }
        });
        arrFlag.order = order;
        // sessionStorage.setItem("order", JSON.stringify(order));
      } else if (i.name == "课表管理") {
        let classs = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "导入值班") {
            classs.daoruzhiban = j.status;
          } else if (j.functionPoint == "导出") {
            classs.daochu = j.status;
          } else if (j.functionPoint == "删除") {
            classs.shanchu = j.status;
          } else if (j.functionPoint == "添加") {
            classs.tianjia = j.status;
          } else if (j.functionPoint == "查看界面") {
            classs.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "课表管理",
                path: "class",
                route: "/hotel/class",
              });
            }
          }
        });
        arrFlag.classs = classs;
        // sessionStorage.setItem("classs", JSON.stringify(classs));
      } else if (i.name == "流程管理") {
        let process = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "同意") {
            process.tongyi = j.status;
          } else if (j.functionPoint == "驳回") {
            process.bohui = j.status;
          } else if (j.functionPoint == "规则设置") {
            process.guizeshezhi = j.status;
          } else if (j.functionPoint == "查看界面") {
            process.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "流程管理",
                path: "process",
                route: "/hotel/process",
              });
            }
          }
        });
        arrFlag.process = process;
        // sessionStorage.setItem("process", JSON.stringify(process));
      } else if (i.name == "统计报表") {
        let statement = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "导出") {
            statement.daochu = j.status;
          } else if (j.functionPoint == "详情") {
            statement.xiangqing = j.status;
          } else if (j.functionPoint == "查看界面") {
            statement.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "统计报表",
                path: "statement",
                route: "/hotel/statement",
              });
            }
          }
        });
        arrFlag.statement = statement;
        // sessionStorage.setItem("statement", JSON.stringify(statement));
      } else if (i.name == "黑名单管理") {
        let blackList = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "移除") {
            blackList.yichu = j.status;
          } else if (j.functionPoint == "查看界面") {
            blackList.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "黑名单管理",
                path: "blackList",
                route: "/hotel/blackList",
              });
            }
          }
        });
        arrFlag.blackList = blackList;
        // sessionStorage.setItem("statement", JSON.stringify(statement));
      } else if (i.name == "门锁管理") {
        let doorLock = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "导入") {
            doorLock.daoru = j.status;
          } else if (j.functionPoint == "钥匙管理") {
            doorLock.yaoshiguanli = j.status;
          } else if (j.functionPoint == "消息列表") {
            doorLock.xiaoxiliebiao = j.status;
          } else if (j.functionPoint == "远程开锁") {
            doorLock.yuanchengkaisuo = j.status;
          } else if (j.functionPoint == "解绑设备") {
            doorLock.jiesuoshebei = j.status;
          } else if (j.functionPoint == "NFC设置") {
            doorLock.nfcshezhi = j.status;
          } else if (j.functionPoint == "查看界面") {
            doorLock.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "门锁管理",
                path: "doorLock",
                route: "/hotel/doorLock",
              });
            }
          }
        });
        arrFlag.doorLock = doorLock;
        // sessionStorage.setItem("doorLock", JSON.stringify(doorLock));
      } else if (i.name == "水电表管理") {
        let meter = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "导出") {
            meter.daochu = j.status;
          } else if (j.functionPoint == "添加") {
            meter.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            meter.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            meter.shanchu = j.status;
          } else if (j.functionPoint == "导入") {
            meter.daoru = j.status;
          } else if (j.functionPoint == "查看界面") {
            meter.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "水电表管理",
                path: "meter",
                route: "/hotel/meter",
              });
            }
          }
        });
        arrFlag.meter = meter;
        // sessionStorage.setItem("meter", JSON.stringify(meter));
      } else if (i.name == "用户管理") {
        let user = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            user.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            user.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            user.shanchu = j.status;
          } else if (j.functionPoint == "查看界面") {
            user.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "用户管理",
                path: "user",
                route: "/hotel/user",
              });
            }
          }
        });
        arrFlag.user = user;
        // sessionStorage.setItem("user", JSON.stringify(user));
      } else if (i.name == "角色管理") {
        let userRoles = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            userRoles.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            userRoles.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            userRoles.shanchu = j.status;
          } else if (j.functionPoint == "查看界面") {
            userRoles.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "角色管理",
                path: "userRoles",
                route: "/hotel/userRoles",
              });
            }
          }
        });
        arrFlag.userRoles = userRoles;
        // sessionStorage.setItem("userRoles", JSON.stringify(userRoles));
      } else if (i.name == "账号管理") {
        let account = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            account.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            account.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            account.shanchu = j.status;
          } else if (j.functionPoint == "查看界面") {
            account.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "账号管理",
                path: "account",
                route: "/hotel/account",
              });
            }
          }
        });
        arrFlag.account = account;
        // sessionStorage.setItem("account", JSON.stringify(account));
      } else if (i.name == "员工管理") {
        let staff = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "添加") {
            staff.tianjia = j.status;
          } else if (j.functionPoint == "编辑") {
            staff.bianji = j.status;
          } else if (j.functionPoint == "删除") {
            staff.shanchu = j.status;
          } else if (j.functionPoint == "查看界面") {
            staff.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "员工管理",
                path: "staff",
                route: "/hotel/staff",
              });
            }
          }
        });
        arrFlag.staff = staff;
        // sessionStorage.setItem("roomType", JSON.stringify(roomType));
      } else if (i.name == "系统设置") {
        let system = {};
        i.functionPoints.forEach((j) => {
          if (j.functionPoint == "退房设置") {
            system.tuifangshezhi = j.status;
          } else if (j.functionPoint == "公寓设置") {
            system.gongyushezhi = j.status;
          } else if (j.functionPoint == "补助设置") {
            system.buzhushezhi = j.status;
          } else if (j.functionPoint == "催缴设置") {
            system.cuijiaoshezhi = j.status;
          } else if (j.functionPoint == "设施服务设置") {
            system.sheshifuwushezhi = j.status;
          } else if (j.functionPoint == "黑名单设施设置") {
            system.heimingdanshezhi = j.status;
          } else if (j.functionPoint == "查看界面") {
            system.chakanjiemian = j.status;
            if (j.status == 1) {
              roleList.push({
                name: "系统管理",
                path: "system",
                route: "/hotel/system",
              });
            }
          }
        });
        arrFlag.system = system;
        // sessionStorage.setItem("system", JSON.stringify(system));
      }
    });
    console.log(arrFlag, "按钮权限");

    sessionStorage.setItem("roleList", JSON.stringify(roleList));
    sessionStorage.setItem("btnflag", JSON.stringify(arrFlag));
    // window.location.reload();
  },
};
// mutations的值由actions传入(异步)
const actions = {
  newsAsync: async ({ commit, state }) => {
    let data = new FormData();
    let res = await axios({
      method: "post",
      url: state.api + "/carBook/usermesUnRead.action",
      headers: {
        token: sessionStorage.getItem("token"),
      },
      data: data,
    });
    console.log(res, "系统消息");

    commit("newsUp", res.data.u_count);
    sessionStorage.setItem("newsNum", res.data.u_count);
    console.log("vuex", res.data.u_count);
  },
  // 登录
  login: async ({ commit, state }, data) => {
    return new Promise(async (resolve, reject) => {
      let res = await axios({
        method: "post",
        url: state.api + "/login/Login",
        data: data,
      });

      console.log(res, "登录账号");
      if (res.data.code == 200) {
        // sessionStorage.setItem("name", data.userName);
        sessionStorage.setItem("token", res.data.data.token);
        sessionStorage.setItem("id", res.data.data.id);
        sessionStorage.setItem("adminMenuParentId", res.data.data.adminMenuParentId);
        sessionStorage.setItem("user_head", res.data.data.user_head);
        sessionStorage.setItem(
          "permissionSettingId",
          res.data.data.permissionSettingId
        );
        sessionStorage.setItem("username", res.data.data.userName);
        sessionStorage.setItem("organizations", JSON.stringify(res.data.data.organizations));
        console.log(res.data.data.userName, "名字账号");
        let datas = {
          permissionSettingId: res.data.data.permissionSettingId,
        };
        let ress = await axios({
          method: "get",
          url: state.api + "/login/menuBar",
          params: datas,
        });
        console.log(ress, "菜单权限");
        let roleList = [];
        let arrFlag = {};
        ress.data.data.forEach((i) => {
          if (i.name == "房态管理") {
            let roomStatus = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "预定") {
                roomStatus.yuding = j.status;
              } else if (j.functionPoint == "退房") {
                roomStatus.tuifang = j.status;
              } else if (j.functionPoint == "维修") {
                roomStatus.weixiu = j.status;
              } else if (j.functionPoint == "关房") {
                roomStatus.guanfang = j.status;
              } else if (j.functionPoint == "置脏") {
                roomStatus.zhizang = j.status;
              } else if (j.functionPoint == "置净") {
                roomStatus.zhijing = j.status;
              } else if (j.functionPoint == "退款") {
                roomStatus.tuikuan = j.status;
              } else if (j.functionPoint == "入住") {
                roomStatus.ruzhu = j.status;
              } else if (j.functionPoint == "锁房") {
                roomStatus.suofang = j.status;
              } else if (j.functionPoint == "换房") {
                roomStatus.huanfang = j.status;
              } else if (j.functionPoint == "开房") {
                roomStatus.kaifang = j.status;
              } else if (j.functionPoint == "开电") {
                roomStatus.kaidian = j.status;
              } else if (j.functionPoint == "关电") {
                roomStatus.guandian = j.status;
              } else if (j.functionPoint == "取消预定") {
                roomStatus.quxiaoyuding = j.status;
              } else if (j.functionPoint == "取消维修") {
                roomStatus.quxiaoweixiu = j.status;
              } else if (j.functionPoint == "查看密码") {
                roomStatus.chakanmima = j.status;
              } else if (j.functionPoint == "查看界面") {
                roomStatus.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "房态管理",
                    path: "roomStatus",
                    route: "/hotel/roomStatus",
                  });
                }
              }
            });
            arrFlag.roomStatus = roomStatus;
            // sessionStorage.setItem("roomStatus", JSON.stringify(roomStatus));
          } else if (i.name == "楼栋单元管理") {
            let building = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                building.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                building.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                building.shanchu = j.status;
              } else if (j.functionPoint == "查看界面") {
                building.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "楼栋单元管理",
                    path: "building",
                    route: "/hotel/building",
                  });
                }
              }
            });
            arrFlag.building = building;
            // sessionStorage.setItem("roomType", JSON.stringify(roomType));
          } else if (i.name == "房型管理") {
            let roomType = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                roomType.tianjia = j.status;
              } else if (j.functionPoint == "修改") {
                roomType.xiugai = j.status;
              } else if (j.functionPoint == "删除") {
                roomType.shanchu = j.status;
              } else if (j.functionPoint == "批量改价") {
                roomType.pilianggaijia = j.status;
              } else if (j.functionPoint == "改价记录") {
                roomType.gaijiajilu = j.status;
              } else if (j.functionPoint == "查看界面") {
                roomType.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "房型管理",
                    path: "roomType",
                    route: "/hotel/roomType",
                  });
                }
              }
            });
            arrFlag.roomType = roomType;
            // sessionStorage.setItem("roomType", JSON.stringify(roomType));
          } else if (i.name == "房间列表") {
            let roomList = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                roomList.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                roomList.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                roomList.shanchu = j.status;
              } else if (j.functionPoint == "导入") {
                roomList.daoru = j.status;
              } else if (j.functionPoint == "查看界面") {
                roomList.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "房间列表",
                    path: "roomList",
                    route: "/hotel/roomList",
                  });
                }
              }
            });
            arrFlag.roomList = roomList;
            // sessionStorage.setItem("roomType", JSON.stringify(roomType));
          } else if (i.name == "房价管理") {
            let roomPrice = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "批量改价") {
                roomPrice.pilianggaijia = j.status;
              } else if (j.functionPoint == "改价记录") {
                roomPrice.gaijiajilu = j.status;
              } else if (j.functionPoint == "查看界面") {
                roomPrice.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "房价管理",
                    path: "roomPrice",
                    route: "/hotel/roomPrice",
                  });
                }
              }
            });
            arrFlag.roomPrice = roomPrice;
            // sessionStorage.setItem("roomPrice", JSON.stringify(roomPrice));
          } else if (i.name == "订单管理") {
            let order = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "取消") {
                order.quxiao = j.status;
              } else if (j.functionPoint == "详情") {
                order.xiangqing = j.status;
              } else if (j.functionPoint == "入住") {
                order.ruzhu = j.status;
              } else if (j.functionPoint == "退款") {
                order.tuikuan = j.status;
              } else if (j.functionPoint == "退房") {
                order.tuifang = j.status;
              } else if (j.functionPoint == "换房") {
                order.huanfang = j.status;
              } else if (j.functionPoint == "导出") {
                order.daochu = j.status;
              } else if (j.functionPoint == "备注") {
                order.beizhu = j.status;
              } else if (j.functionPoint == "查看界面") {
                order.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "订单管理",
                    path: "order",
                    route: "/hotel/order",
                  });
                }
              }
            });
            arrFlag.order = order;
            // sessionStorage.setItem("order", JSON.stringify(order));
          } else if (i.name == "课表管理") {
            let classs = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "导入值班") {
                classs.daoruzhiban = j.status;
              } else if (j.functionPoint == "导出") {
                classs.daochu = j.status;
              } else if (j.functionPoint == "删除") {
                classs.shanchu = j.status;
              } else if (j.functionPoint == "添加") {
                classs.tianjia = j.status;
              } else if (j.functionPoint == "查看界面") {
                classs.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "课表管理",
                    path: "class",
                    route: "/hotel/class",
                  });
                }
              }
            });
            arrFlag.classs = classs;
            // sessionStorage.setItem("classs", JSON.stringify(classs));
          } else if (i.name == "流程管理") {
            let process = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "同意") {
                process.tongyi = j.status;
              } else if (j.functionPoint == "驳回") {
                process.bohui = j.status;
              } else if (j.functionPoint == "规则设置") {
                process.guizeshezhi = j.status;
              } else if (j.functionPoint == "查看界面") {
                process.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "流程管理",
                    path: "process",
                    route: "/hotel/process",
                  });
                }
              }
            });
            arrFlag.process = process;
            // sessionStorage.setItem("process", JSON.stringify(process));
          } else if (i.name == "统计报表") {
            let statement = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "导出") {
                statement.daochu = j.status;
              } else if (j.functionPoint == "详情") {
                statement.xiangqing = j.status;
              } else if (j.functionPoint == "查看界面") {
                statement.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "统计报表",
                    path: "statement",
                    route: "/hotel/statement",
                  });
                }
              }
            });
            arrFlag.statement = statement;
            // sessionStorage.setItem("statement", JSON.stringify(statement));
          } else if (i.name == "黑名单管理") {
            let blackList = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "移除") {
                blackList.yichu = j.status;
              } else if (j.functionPoint == "查看界面") {
                blackList.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "黑名单管理",
                    path: "blackList",
                    route: "/hotel/blackList",
                  });
                }
              }
            });
            arrFlag.blackList = blackList;
            // sessionStorage.setItem("statement", JSON.stringify(statement));
          } else if (i.name == "门锁管理") {
            let doorLock = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "导入") {
                doorLock.daoru = j.status;
              } else if (j.functionPoint == "钥匙管理") {
                doorLock.yaoshiguanli = j.status;
              } else if (j.functionPoint == "消息列表") {
                doorLock.xiaoxiliebiao = j.status;
              } else if (j.functionPoint == "远程开锁") {
                doorLock.yuanchengkaisuo = j.status;
              } else if (j.functionPoint == "解绑设备") {
                doorLock.jiesuoshebei = j.status;
              } else if (j.functionPoint == "NFC设置") {
                doorLock.nfcshezhi = j.status;
              } else if (j.functionPoint == "查看界面") {
                doorLock.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "门锁管理",
                    path: "doorLock",
                    route: "/hotel/doorLock",
                  });
                }
              }
            });
            arrFlag.doorLock = doorLock;
            // sessionStorage.setItem("doorLock", JSON.stringify(doorLock));
          } else if (i.name == "水电表管理") {
            let meter = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "导出") {
                meter.daochu = j.status;
              } else if (j.functionPoint == "添加") {
                meter.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                meter.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                meter.shanchu = j.status;
              } else if (j.functionPoint == "导入") {
                meter.daoru = j.status;
              } else if (j.functionPoint == "查看界面") {
                meter.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "水电表管理",
                    path: "meter",
                    route: "/hotel/meter",
                  });
                }
              }
            });
            arrFlag.meter = meter;
            // sessionStorage.setItem("meter", JSON.stringify(meter));
          } else if (i.name == "用户管理") {
            let user = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                user.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                user.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                user.shanchu = j.status;
              } else if (j.functionPoint == "查看界面") {
                user.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "用户管理",
                    path: "user",
                    route: "/hotel/user",
                  });
                }
              }
            });
            arrFlag.user = user;
            // sessionStorage.setItem("user", JSON.stringify(user));
          } else if (i.name == "角色管理") {
            let userRoles = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                userRoles.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                userRoles.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                userRoles.shanchu = j.status;
              } else if (j.functionPoint == "查看界面") {
                userRoles.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "角色管理",
                    path: "userRoles",
                    route: "/hotel/userRoles",
                  });
                }
              }
            });
            arrFlag.userRoles = userRoles;
            // sessionStorage.setItem("userRoles", JSON.stringify(userRoles));
          } else if (i.name == "账号管理") {
            let account = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                account.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                account.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                account.shanchu = j.status;
              } else if (j.functionPoint == "查看界面") {
                account.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "账号管理",
                    path: "account",
                    route: "/hotel/account",
                  });
                }
              }
            });
            arrFlag.account = account;
            // sessionStorage.setItem("account", JSON.stringify(account));
          } else if (i.name == "员工管理") {
            let staff = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "添加") {
                staff.tianjia = j.status;
              } else if (j.functionPoint == "编辑") {
                staff.bianji = j.status;
              } else if (j.functionPoint == "删除") {
                staff.shanchu = j.status;
              } else if (j.functionPoint == "查看界面") {
                staff.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "员工管理",
                    path: "staff",
                    route: "/hotel/staff",
                  });
                }
              }
            });
            arrFlag.staff = staff;
            // sessionStorage.setItem("roomType", JSON.stringify(roomType));
          } else if (i.name == "系统设置") {
            let system = {};
            i.functionPoints.forEach((j) => {
              if (j.functionPoint == "退房设置") {
                system.tuifangshezhi = j.status;
              } else if (j.functionPoint == "公寓设置") {
                system.gongyushezhi = j.status;
              } else if (j.functionPoint == "补助设置") {
                system.buzhushezhi = j.status;
              } else if (j.functionPoint == "催缴设置") {
                system.cuijiaoshezhi = j.status;
              } else if (j.functionPoint == "设施服务设置") {
                system.sheshifuwushezhi = j.status;
              } else if (j.functionPoint == "黑名单设施设置") {
                system.heimingdanshezhi = j.status;
              } else if (j.functionPoint == "查看界面") {
                system.chakanjiemian = j.status;
                if (j.status == 1) {
                  roleList.push({
                    name: "系统管理",
                    path: "system",
                    route: "/hotel/system",
                  });
                }
              }
            });
            arrFlag.system = system;
            // sessionStorage.setItem("system", JSON.stringify(system));
          }
        });
        sessionStorage.setItem("roleList", JSON.stringify(roleList));
        sessionStorage.setItem("btnflag", JSON.stringify(arrFlag));

        resolve("success");
      } else {
        resolve({ name: "reject", data: res });
      }
    });
  },
};

export default {
  state,
  mutations,
  actions,
};
