<template>
  <div class="fwgl_container">
    <side-nav-bar
      v-if="showNavbar"
      title="权限管理"
      :title-icon="require('@/assets/imgs/tool_quanxian.png')"
      :nav-list="navList"
      :title-path="navList[0] && navList[0].path"
    ></side-nav-bar>
    <div class="main_container">
      <router-view :key="'type_' + $route.params.type"></router-view>
    </div>
  </div>
</template>

<script>
import sideNavBar from "@/components/side-nav-bar";

export default {
  components: {
    sideNavBar,
  },
  data: () => ({
    userNav: [
      {
        name: "组织管理",
        path: `/authority/organization`,
      },
      {
        name: "用户管理",
        path: `/authority/users`,
      },
      {
        name: "菜单管理",
        path: `/authority/menu`,
      },
      {
        name: "角色管理",
        path: `/authority/roles`,
      },
    ],
    navList: [],
    showNavbar: false,
  }),
  watch: {
    "$route.fullPath"(path) {
      this.initNavList();
    },
  },
  methods: {
    initNavList() {
      this.navList = this.userNav;
    },
  },
  mounted() {
    this.$api.user.getNowUser().then(({ data }) => {
      if (data.success == 1) {
        this.$store.commit("userInfofun", data.data);

        const userLevel = this.$store.getters.level;

        if (userLevel == 0) {
          this.$message({
            message: `您没有权限管理模块的权限.`,
            type: "warning",
          });
          this.$router.push(`/index`);
        } else if (userLevel == 1) {
          this.$router.push(
            `/authority/organization/detail/${data.data.department_id}`
          );
        } else {
          this.showNavbar = true;
          this.initNavList();
        }
      }
    });
  },
};
</script>

<style scoped>
.fwgl_container {
  height: calc(100vh - 84px);
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
}
.side_nav_bar {
  width: 180px;
  flex-shrink: 0;
}
.main_container {
  width: calc(100% - 180px);
  flex-grow: 1;
  flex-shrink: 1;
  background-color: #f6f7fb;
  overflow: auto;
}
</style>
