<template>
  <div class="sidebarBox">
    <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">
              <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">
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: "/home",
      items: [
        {
          index: "/home",
          title: "首页",
        },
        {
          index: "/report",
          title: "状态报表",
        },
        {
          index: "/log",
          title: "日志列表",
        },
        {
          index: "/upgradation",
          title: "上传APK/OTA",
        },
        {
          index: "/activity",
          title: "活动列表",
        },
        {
          index: "/msgAuth",
          title: "短信授权",
        },

        {
          index: "/aaa",
          title: "运维报表",
          subs: [
            {
              index: "/picReport",
              title: "在线率报表",
            },
            {
              index: "/historyReport",
              title: "运维历史数据",
            },
          ],
        },
      ],
    };
  },
  watch: {
    $route() {
      this.setCurrentRoute();
    },
  },
  created() {
    this.setCurrentRoute();
  },
  methods: {
    setCurrentRoute() {
      console.log(this.$route.path);
      this.$nextTick(() => {
        this.activeIndex = this.$route.path; // 通过他就可以监听到当前路由状态并激活当前菜单
        console.log(this.activeIndex);
        localStorage.setItem("menuActive", this.activeIndex);
      });
    },
  },
};
</script>

<style lang="less">
.sidebarBox {
  // width: 55%;
  // margin: 0 auto;
  display: flex;
  align-items: center;
  .el-menu--horizontal {
    background: #169e8c;

    .el-menu-item {
      height: 56px;
      line-height: 56px;
    }
    .el-submenu .el-submenu__title {
      height: 56px;
      line-height: 56px;
    }
    .el-submenu__title {
      padding: 0 10px;
      .iconfont {
        margin-right: 5px;
      }
    }
    .el-dropdown-menu__item,
    .el-menu-item,
    .el-submenu__title {
      font-size: 14px;
    }
    .el-menu-item i {
      color: #666;
    }
    .el-menu-item.is-active {
      i {
        color: #169e8c;
      }
    }
    .el-submenu.is-active .el-submenu__title > i {
      &:first-child {
        color: #333;
      }
    }
  }
  .el-menu {
    background: #169e8c;

    i {
      color: #fff !important;
    }
    .el-menu-item {
      color: #fff;
    }
    .el-submenu .el-submenu__title {
      color: #fff;
    }
    .el-menu-item:not(.is-disabled):focus,
    .el-menu-item:not(.is-disabled):hover {
      color: #fff;
      background-color: #128071;
      border-bottom: 2px solid #128071;
      i {
        color: #fff !important;
      }
    }
    .el-submenu:focus .el-submenu__title,
    .el-submenu:hover .el-submenu__title {
      color: #fff !important;
      background-color: #128071;
      border-bottom: 2px solid #128071;
      i {
        color: #fff !important;
      }
    }
  }
  .el-menu--horizontal > .el-menu-item.is-active {
    border-bottom: 2px solid #128071 !important;
    color: #fff !important;
    background-color: #128071 !important;
    i {
      color: #fff !important;
    }
  }
  .el-submenu.is-active {
    .el-submenu__title {
      border-bottom: 2px solid #128071 !important;
      color: #fff !important;
      background-color: #128071;
      i {
        color: #fff !important;
      }
    }
  }
  .gallery-thumbs .swiper-slide-active {
    border: 3px solid #169e8c !important;
  }
  .tags-li.active {
    border: 1px solid #169e8c;
    background-color: #169e8c;
  }
  .el-menu-item [class^="iconfont"] {
    margin-right: 5px;
    width: 24px;
    text-align: center;
    font-size: 18px;
    vertical-align: middle;
  }
  // .menuBoxUl {
  //   flex: 1;
  //   display: flex;
  //   align-items: center;
  //   justify-content: space-around;
  //   .menuItem {
  //     list-style: none;
  //     display: flex;
  //     height: 40px;
  //     justify-content: center;
  //     align-items: center;
  //     cursor: pointer;
  //     font-size: 14px;
  //     margin-right: 32px;
  //     a {
  //       color: #fff;
  //       //background: #e8f5f4;
  //       height: 40px;
  //       line-height: 40px;
  //       padding: 0 12px;
  //       background-size: 100% 100%;
  //       background-repeat: no-repeat;
  //       overflow: hidden;
  //       border-radius: 8px;
  //       &:hover {
  //         background: #128071;
  //       }
  //     }
  //     .router-link-active {
  //       background: #128071;
  //     }
  //   }
  // }
}
</style>
