<template>
  <div></div>
</template>
<script>
import { getToken } from "@/utils/auth";
let obj = {};
if (getToken()) {
  obj = JSON.parse(getToken()) || {};
}
/**左侧边 */
export default {
  async mounted() {
    if (!getToken()) {
      this.$router.push({ path: "/login" });
      return;
    }
    const loading = this.$loading({
      lock: true,
      text: "初始化中",
      spinner: "el-icon-loading",
      background: "rgba(0, 0, 0, 0.7)"
    });
    if (obj.final_admin) {
      // 终极管理员
      loading.close();
      this.$router.replace({ path: "/index" });
    } else if (obj.super_admin) {
      // 超级管理员
      this.$router.options.routes[4].meta.show = "no";
      this.$router.options.routes[5].meta.show = "no";
      this.$router.options.routes[6].meta.show = "no";
      this.$router.options.routes[7].meta.show = "no";
      this.$router.options.routes[9].children[1].meta.show = "no";
      this.$router.replace({ path: "/operManagement/operManagement" });
      loading.close();
    } else if (obj.enterprise_admin) {
      // 企业管理员
      this.$router.options.routes[8].meta.show = "no";
      this.$router.options.routes[9].children[0].meta.show = "no";
      this.$router.options.routes[9].children[2].meta.show = "no";
      loading.close();
      this.$router.replace({ path: "/index" });
    } else {
      this.getPermList();
      loading.close();
      this.$router.replace({ path: "/index" });
    }
  },
  methods: {
    getPermList() {
      for (let i = 0; i < 7; i++) {
        this.$router.options.routes[5].children[i].meta.show = "no";
        this.$router.options.routes[7].children[2].children[i].meta.show = "no";
      }
      for (let i = 0; i < 2; i++) {
        // this.$router.options.routes[7].children[0].children[i].meta.show = 'no'
      }
      for (let i = 0; i < 5; i++) {
        this.$router.options.routes[7].children[1].children[i].meta.show = "no";
      }
      for (let i = 0; i < 3; i++) {
        this.$router.options.routes[6].children[i].meta.show = "no";
        this.$router.options.routes[9].children[i].meta.show = "no";
        this.$router.options.routes[7].children[i].meta.show = "no";
        this.$router.options.routes[7].children[0].children[i].meta.show = "no";
      }
      this.$router.options.routes[4].meta.show = "yes";
      this.$router.options.routes[5].meta.show = "no";
      this.$router.options.routes[6].meta.show = "no";
      this.$router.options.routes[7].meta.show = "no";
      this.$router.options.routes[8].meta.show = "no";
      this.$router.options.routes[9].meta.show = "no";
      let arr = ["", "", "", "", "", "A", "B", "C", "", "D"];
      let perm_list = obj.perm_list;
      // perm_list记录的是路由权限
      perm_list.map((val, index) => {
        let tag = val.substring(0, 1); // tag是字母ABCD
        let i = val.substring(1); // 记录二级菜单 i是字母后面的数字
        arr.map((item, num) => {
          // num 记录一级菜单
          if (tag == item) {
            this.$router.options.routes[num].meta.show = "yes";
            if (num == 5) {
              if (i < 3) {
                this.$router.options.routes[num].children[i - 1].meta.show =
                  "yes";
              } else {
                if (i == 7) {
                  this.$router.options.routes[num].children[3].meta.show =
                    "yes";
                } else {
                  this.$router.options.routes[num].children[i].meta.show =
                    "yes";
                }
              }
            } else if (num == 7) {
              if (i < 3) {
                // 司机
                this.$router.options.routes[num].children[0].children[
                  i - 1
                ].meta.show = "yes";
                this.$router.options.routes[7].children[0].meta.show = "yes";
              } else if (i < 7) {
                // 客户
                // this.$router.options.routes[num].children[1].children[i-3].meta.show = 'yes'
                if (val == "C3")
                  this.$router.options.routes[
                    num
                  ].children[1].children[3].meta.show = "yes";
                if (val == "C4")
                  this.$router.options.routes[
                    num
                  ].children[1].children[0].meta.show = "yes";
                if (val == "C5")
                  this.$router.options.routes[
                    num
                  ].children[1].children[1].meta.show = "yes";
                if (val == "C6")
                  this.$router.options.routes[
                    num
                  ].children[1].children[4].meta.show = "yes";
                this.$router.options.routes[7].children[1].meta.show = "yes";
              } else if (i == 13) {
                // 运费利润
                this.$router.options.routes[7].children[0].meta.show = "yes";
                this.$router.options.routes[
                  num
                ].children[0].children[2].meta.show = "yes";
              } else if (i == 14) {
                // 配送管-运费单价
                this.$router.options.routes[6].meta.show = "yes";
                this.$router.options.routes[6].children[2].meta.show = "yes";
              } else if (i == 15) {
                // 客户-退款明细
                this.$router.options.routes[7].children[1].meta.show = "yes";
                this.$router.options.routes[
                  num
                ].children[1].children[2].meta.show = "yes";
              } else {
                // 供应商
                // this.$router.options.routes[num].children[2].children[
                //   i - 7
                // ].meta.show = "yes";
                if (val == "C7")
                  this.$router.options.routes[
                    num
                  ].children[2].children[4].meta.show = "yes";
                if (val == "C8")
                  this.$router.options.routes[
                    num
                  ].children[2].children[0].meta.show = "yes";
                if (val == "C9")
                  this.$router.options.routes[
                    num
                  ].children[2].children[1].meta.show = "yes";
                if (val == "C10")
                  this.$router.options.routes[
                    num
                  ].children[2].children[2].meta.show = "yes";
                if (val == "C11")
                  this.$router.options.routes[
                    num
                  ].children[2].children[3].meta.show = "yes";
                if (val == "C12")
                  this.$router.options.routes[
                    num
                  ].children[2].children[5].meta.show = "yes";
                this.$router.options.routes[7].children[2].meta.show = "yes";
              }
            } else if (num == 9) {
              // 企业子账号屏蔽系统管理
              this.$router.options.routes[num].children[i].meta.show = "no";
            } else {
              this.$router.options.routes[num].children[i - 1].meta.show =
                "yes";
            }
          }
        });
      });
    }
  }
};
</script>
