<template>
  <el-menu class="aside-menu-box" :default-openeds="menuList.map(el => el.menuCode)">
    <el-submenu class="aside-menu-list" v-for="el in getMenuList" :index="el.menuCode" :key="el.menuCode">
      <div class="aside-menu-list-title" slot="title">
        <i :class="['menu-icon iconfont-hb3', el.iconUrl]"></i>
        <span>{{ el.menuName }}</span>
      </div>
      <el-menu-item :class="['aside-menu-title', { actived: activedCode == item.menuCode }]" v-for="item in el.childList" :index="item.menuCode" :key="item.menuCode" @click="toPage(item)">
        {{ item.menuName }}
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: 'AsideMenu',
  props: {
    menuList: {
      type: Array,
      default: () => []
    },
    activedCode: String
  },
  computed: {
    getMenuList() {
      return this.menuList
        .filter(el => {
          if (el.hasRight && el.isShow && Array.isArray(el.childList)) {
            el.childList = el.childList.filter(item => item.hasRight && item.isShow);
          }
          return el.hasRight && el.isShow;
        })
        .filter(el => Array.isArray(el.childList) && el.childList.length > 0);
    }
  },
  methods: {
    toPage(menu) {
      // if (this.$route.patch == '/' + menu.menuUrl) return;
      this.$router.push('/' + menu.menuUrl);
    }
  }
};
</script>

<style lang="scss" scoped>
.aside-menu-box {
  flex-shrink: 0;
  margin-right: 16px;
  padding: 8px 10px;
  width: 190px;
  height: calc(100% - 60px);
  box-sizing: border-box;
  overflow-y: auto;
  .aside-menu-list {
    .aside-menu-list-title {
      position: relative;
      .menu-icon {
        position: absolute;
        top: 50%;
        left: 12px;
        z-index: 1;
        transform: translate(0, -50%);
        font-size: 16px;
        color: #303133;
      }
    }
    .aside-menu-list-title,
    .aside-menu-title {
      padding-left: 36px;
      min-width: auto;
      height: 44px;
      font-size: 14px;
      font-weight: 400;
      color: #303133;
      line-height: 44px;
      box-sizing: border-box;
      border-radius: 2px;
      &:hover,
      &:focus {
        background: #f2f3f5;
      }
      &.actived {
        font-size: 14px;
        font-weight: 600;
        color: #2f54eb;
        background: rgba(47, 84, 235, 0.05);
      }
    }
  }
}
</style>

<style lang="scss">
.aside-menu-list {
  .el-submenu__title {
    padding: 0 !important;
    height: auto;
    &:hover {
      background: transparent;
    }
    .el-icon-arrow-down {
      font-family: 'iconfont-hb3' !important;
      color: #303133;
      &::before {
        content: '\E9E9';
      }
    }
  }
}
</style>
