<template>
  <div class="sidebar">
    <el-menu
      :default-active="activeIndex"
      class="sidebar-el-menu"
      mode="horizontal"
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>
              <el-menu-item
                v-else
                :index="subItem.index"
                :key="subItem.index"
                >{{ subItem.title }}</el-menu-item
              >
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: "/realTimeMonitor",
      items: [
        // {
        //   icon: "el-icon-s-home",
        //   index: "stritl",
        //   title: "首页",
        // },
        {
          icon: "el-icon-camera",
          index: "/realTimeMonitor",
          title: "实时监控",
        },

        {
          icon: "el-icon-film",
          index: "/pictureRotation",
          title: "图片轮巡",
        },
        {
          icon: "el-icon-bell",
          index: "/photoAlarm",
          title: "告警处理",
        },

        {
          icon: "el-icon-search",
          index: "/realTimeSearch",
          title: "历史图片",
        },
        {
          icon: "el-icon-files",
          index: "/property",
          title: "资产管理",
          subs: [
            {
              index: "/lineInformation",
              title: "线路信息管理",
            },
            {
              index: "/towerInformation",
              title: "杆塔信息管理",
            },

            {
              index: "/cameraChannel",
              title: "通道管理",
            },
            {
              index: "/photographicDevice",
              title: "拍照装置管理",
            },
            {
              index: "/devicePhotoSchedule",
              title: "拍照时间表设置",
            },
            {
              index: "/deviceUpgrade",
              title: "装置升级",
            },
            // {
            //   icon: "el-icon-picture-outline",
            //   index: "imageSettings",
            //   title: "图像采集参数设置",
            // },
          ],
        },
        {
          icon: "el-icon-monitor",
          index: "/system",
          title: "系统管理",
          subs: [
            {
              index: "/userManagement",
              title: "用户管理",
            },
          ],
        },
      ],
      items2: [
        // {
        //   icon: "el-icon-s-home",
        //   index: "stritl",
        //   title: "首页",
        // },
        {
          icon: "el-icon-camera",
          index: "/realTimeMonitor",
          title: "实时监控",
        },

        {
          icon: "el-icon-film",
          index: "/pictureRotation",
          title: "图片轮巡",
        },
        // {
        //   icon: "el-icon-bell",
        //   index: "photoAlarm",
        //   title: "告警处理",
        // },

        {
          icon: "el-icon-search",
          index: "/realTimeSearch",
          title: "历史图片",
        },
        {
          icon: "el-icon-files",
          index: "/property",
          title: "资产管理",
          subs: [
            {
              index: "/lineInformation",
              title: "线路信息管理",
            },
            {
              index: "/towerInformation",
              title: "杆塔信息管理",
            },

            {
              index: "/cameraChannel",
              title: "通道管理",
            },
            {
              index: "/photographicDevice",
              title: "拍照装置管理",
            },
            {
              index: "/devicePhotoSchedule",
              title: "拍照时间表设置",
            },
            // {
            //   index: "/deviceUpgrade",
            //   title: "装置升级",
            // },
            // {
            //   icon: "el-icon-picture-outline",
            //   index: "imageSettings",
            //   title: "图像采集参数设置",
            // },
          ],
        },
      ],
      role: "",
    };
  },
  watch: {
    $route() {
      this.setCurrentRoute();
    },
  },
  methods: {
    setCurrentRoute() {
      this.activeIndex = this.$route.path; // 通过他就可以监听到当前路由状态并激活当前菜单
    },
  },
  created() {
    this.setCurrentRoute();
    this.role = localStorage.getItem("role");
    console.log("用户管理");
    console.log(this.role);

    if (this.role == 1) {
      this.items = this.items;
    } else {
      this.items = this.items2;
    }
    console.log(this.items);
  },
};
</script>

<style lang="less">
.sidebar {
  float: left;
  .el-menu--horizontal {
    .el-menu-item {
      height: 70px;
      line-height: 70px;
    }
    .el-submenu .el-submenu__title {
      height: 70px;
      line-height: 70px;
    }
    .el-dropdown-menu__item,
    .el-menu-item,
    .el-submenu__title {
      font-size: 16px;
    }
    .el-menu-item i {
      color: @color-text-secondary;
    }
    .el-menu-item.is-active {
      i {
        color: @color-primary;
      }
    }
    .el-submenu.is-active .el-submenu__title > i {
      &:first-child {
        color: @color-primary;
      }
    }
  }
}
</style>
