<template>
  <el-aside width="auto" height="auto">
    <el-menu :collapse="isCollapse" :default-active="onRoutes" background-color="#232323" text-color="#ccc"
      active-text-color="#ddd" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subItems" v-show="item.status !=-1">
          <el-submenu :index="item.path">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{item.title}}</span>
            </template>
            <el-menu-item v-for="(subItem, i) in item.subItems" :index="subItem.path" :key="i">
              {{subItem.title}}
            </el-menu-item>
          </el-submenu>
        </template>
        <template v-else v-show="item.status !=-1">
          <el-menu-item :index="item.path">
            <i :class="item.icon"></i>
            <span slot="title">{{item.title}}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </el-aside>
</template>

<script>
  import Bus from "./bus";
  export default {
    name: "Sidebar",
    data() {
      return {
        isCollapse: false,
        items: [
          {
            title: '首页',
            path: '/index',
            icon: 'iconfont icon-shouye-shouye',
            status: '1'
          },
          {
            title: '设备管理',
            path: '/EquipmentList',
            status: '1',
            icon: 'iconfont icon-menci',
            subItems: [
              {
                title: '设备列表',
                status: '1',
                path: '/EquipmentList'
              },
            ]
          },
          {
            title: '报警管理',
            path: 'echarts',
            icon: 'iconfont icon-baojingshezhi',
            status: '1',
            subItems: [
              {
                title: '报警记录',
                status: '1',
                path: '/alarmRecord'
              },
              // {
              //   title: '复杂图表',
              //   path: '/chart-complex'
              // }
            ]
          },
          {
            title: '安装管理',
            path: '/Architecture',
            status: '1',
            icon: 'iconfont icon-jianzhu',
            subItems: [
              {
                title: '建筑物管理',
                status: '1',
                path: '/Architecture'
              },
              {
                title: '接警联系人管理',
                status: '1',
                path: '/Linkman'
              },
            ]
          },
          {
            title: '用户与单位',
            path: '/subordinateUnit',
            status: '1',
            icon: 'iconfont icon-tianjiayonghu',
            subItems: [
              {
                title: '下级单位管理',
                status: '1',
                path: '/subordinateUnit'
              },
              {
                title: '用户管理',
                status: '1',
                path: '/userManagement'
              },
            ]
          },
          // {
          //   title: '错误页面',
          //   path: '/error',
          //   icon: 'el-icon-warning'
          // },
          // {
          //   title: '404页面',
          //   path: '/404',
          //   icon: 'el-icon-error'
          // },
        ]
      }
    },
    computed: {
      onRoutes() {

        return this.$route.fullPath;
      }
    },
    created() {
      var info=JSON.parse(localStorage.getItem('userInfo'))
      if(info.username=="test091"){
        console.log(info)
        this.items=[
        {
            title: '报警管理',
            path: 'echarts',
            icon: 'iconfont icon-baojingshezhi',
            status: '1',
            subItems: [
              {
                title: '报警记录',
                status: '1',
                path: '/alarmRecord'
              },
              // {
              //   title: '复杂图表',
              //   path: '/chart-complex'
              // }
            ]
          },
        ]
      }
      // 通过 event bus进行组件间的通信 来折叠和展开侧边栏
      Bus.$on('collapse', isCollapse => {

        this.isCollapse = isCollapse;
      });
    }
  }
</script>

<style scoped lang="less">
  .el-menu {
    height: 100%;
    border: none;

    &:not(.el-menu--collapse) {
      width: 200px;
    }
  }

  .el-menu-item.is-active {
    border-left: 3px solid @mainColor;
    background-color: #171717 !important;
  }
</style>