<template>
  <div>
    <div class="home-title">
      <!-- <img src="@/assets/logo.png" alt="" /> -->
      <span class="title-span">镇江管理后台</span>
    </div>
    <el-menu :default-active="routerPath" :unique-opened="true" class="el-menu-vertical-demo" text-color="#666">
      <MenuTree :menuData="menuList" @change="changeRouterName"></MenuTree>
    </el-menu>
  </div>
</template>

<script>
// import _ from 'lodash'
import { getMenuList } from "@/utils/auth";
import MenuTree from "./MenuTree.vue";
export default {
  name: "Sidebar",
  data() {
    return {
      menuList: [],
      routerPath: ''
    };
  },
  components: {
    MenuTree,
  },
  created() {
    this.init(JSON.parse(getMenuList()))
    this.routerPath = localStorage.getItem('activeId')
  },
  methods: {
    changeRouterName(activeId) {
      this.routerPath = activeId
    },
    init(list) {
      let menuList = []
      let childrens = []
      list.forEach(element => {
        if (element.parentId === 0) {
          menuList.push(element)
        } else {
          childrens.push(element)
        }
      });
      childrens.forEach((item) => {
        let parent = menuList.find(i => i.id === item.parentId)
        if (!parent?.children) return parent.children = [item];
        parent.children.push(item)
      })
      this.menuList = menuList;
      this.menuList.sort((x,z)=> Number(x.sequence)-Number(z.sequence) )
    }
  },
};
</script>
<style>
.el-menu-vertical-demo {
  height: calc(100vh - 60px);
  overflow: auto;

}

.el-menu-vertical-demo::-webkit-scrollbar {
  display: none;
}
</style>
<style lang="stylus" scoped>

.home-title {
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 50px;
  // padding: 0 20px;
  font-size: 16px;
  font-family: YouSheBiaoTiHei;
  color: #fff;
  background #4885ff;

  img {
    display: inline;
    width: 25px;
    height: 25px;
    margin-right: 5px;
  }
}
.title-span {
  font-weight: bold;
  letter-spacing: 2px;
}
.el-menu {
  padding: 0 10px;
  box-sizing: border-box;
}
.el-menu-item {
  height: 40px;
  line-height: 40px;
  margin: 14px 0;
  box-sizing: border-box;
}
.el-menu-item.is-active {
  // background-color: pink;
  color: #fff;
  // background-image: linear-gradient(to right, #ffaa4f, #ff600f);
  border-radius: 50px;
  font-size: 16px;
  /* padding: 0 20px; */
}
.el-submenu__title {
  height: 40px;
  line-height: 40px;
}
.el-submenu .el-menu-item {
  min-width: 0px;
  padding-left: 20px !important;
  height: 40px;
  line-height: 40px;
}
</style>
