<template>
  <div :class="['left-aside', { widthZoom: isZoom }]">
    <div class="left-logo">
      <!--      <b style="font-size:  24px;">ESB控制台</b>-->
      <img class="logo" :src="logo" alt />
    </div>
    <div class="menu-wrap">
      <el-menu
        class="left-menu"
        unique-opened
        router
        :default-active="$route.path"
        :collapse-transition="false"
        :collapse="isCollapse"
      >
        <div v-for="(item, index) in options" :key="item.path">
          <div
            v-if="
              (item.subNodes && item.subNodes.length === 0) ||
              item.url === '/project_list'
            "
          >
            <el-menu-item :index="item.url">
              <template slot="title">
                <span @click="clickHandle(item)" slot="title">{{
                  item.name
                }}</span>
              </template>
            </el-menu-item>
          </div>
          <el-submenu class="padnone" v-else :index="index + ''">
            <template slot="title">
              <span slot="title" @click="clickHandle(item)">{{
                item.name
              }}</span>
            </template>
            <div v-for="(menu, index1) in item.subNodes" :key="menu.url">
              <el-submenu
                class="padnone"
                v-if="menu.subNodes && menu.subNodes.length > 0"
                :index="menu.url"
              >
                <span slot="title" @click="clickHandle(menu)">{{
                  menu.name
                }}</span>
                <el-menu-item
                  v-for="(menus, index2) in menu.subNodes"
                  :key="menus.url"
                  :index="menus.url"
                  @click="clickHandle(menus)"
                >
                  {{ menus.name }}
                </el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="menu.url" @click="clickHandle(menu)">
                <template slot="title">
                  <span slot="title">{{ menu.name }}</span>
                </template>
              </el-menu-item>
            </div>
          </el-submenu>
        </div>
      </el-menu>
    </div>
    <div class="zoomButton" @click="isZoom = !isZoom">
      <i v-if="isZoom" class="el-icon-caret-right"></i>
      <i v-else class="el-icon-caret-left"></i>
    </div>
  </div>
</template>

<script>
import logo from '@/assets/img/common/logo-w.png'
// import { getAllGroups2, getNavAll3, getSubTree } from '@/api/system_manage'
import { getUserAll3 } from '@/api/system_manage'
export default {
  name: 'LeftMenu',
  components: {},
  data() {
    return {
      isZoom: false,
      options: [],
      logo: logo,
      isCollapse: false,
      recordsVisible: false,
      hasLeftMenu: false,
      pathName: '',
      pathList: null
    }
  },
  computed: {},
  watch: {},
  mounted() {
    this.getNavigationMenu()
  },
  methods: {
    getNavigationMenu() {
      // var that = this
      getUserAll3(this.$store.state.app.userInfo.id).then((rt) => {
        if (rt.data.length < 1) {
          this.$message.error('没权限登陆失败')
          location.href = '#/login'
        } else {
          this.options = rt.data
        }
      })
    },
    clickHandle(item) {
      this.$router.push({ path: item.url })
    }
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
.menu-wrap {
  overflow: hidden;
  padding: 12px 5px 0;
  box-sizing: border-box;
  height: 100%;
  margin: 0 auto;
}
$border-color: #ebeef5;
.left-aside {
  position: relative;
  left: 0;
  top: 0;
  height: 100vh;
  margin-right: 10px;
  // min-width: 40px;
  width: 200px;
  background: rgb(45, 66, 175);
  .zoomButton {
    position: absolute;
    top: 50%;
    right: -13px;
    z-index: 12;
    width: 12px;
    padding: 16px 0;
    margin-top: -20px;
    text-align: center;
    color: #fff;
    border-left: 1px solid #7180c8;
    border-radius: 0 4px 4px 0;
    background-color: #2d42af;
    cursor: pointer;
    -webkit-transform: scale(0.8);
    transform: scale(0.8);
  }
  .left-logo {
    width: 200px;
    margin-right: 40px;
    background: rgba(0, 0, 0, 0.1);
    padding: 10px;
    box-sizing: border-box;

    img {
      width: 100%;
    }
  }
  .tool-bal {
    height: 100%;
    width: 40px;
    float: left;

    .el-dropdown {
      width: 100%;
    }

    span {
      display: inline-block;
      width: 100%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      font-size: 26px;
      margin-top: 10px;
      color: #ffffff;
      background-color: $active-color;
      cursor: pointer;
    }

    span.setting {
      background-color: $bc6;
    }
  }
}
.widthZoom {
  width: 0;
  .left-logo {
    display: none;
  }
  .left-menu {
    display: none;
  }
}
.left-menu:not(.el-menu--collapse) {
  min-width: 180px;
  width: 10vw;
}

.left-menu.el-menu--collapse {
  width: 0;
}

.el-submenu {
  &__title {
    height: 48px !important;
    line-height: 48px !important;
    font-size: 14px;
    padding: 0 12px 0 29px !important;
    font-weight: bold;

    i {
      left: 8px;
      right: inherit;
      color: $active-color !important;
      font-weight: 600;
      font-size: 16px;
    }
  }

  .el-menu-item {
    min-width: 150px !important;
  }
}

.el-submenu > .el-submenu__title .el-submenu__icon-arrow {
  transform: rotateZ(-90deg);
}

.el-submenu.is-opened > .el-submenu__title .el-submenu__icon-arrow {
  transform: rotateZ(0deg) !important;
}

.left-menu {
  // height: calc(100% - 12px);
  padding-top: 12px;
  border: none !important;
  overflow-y: auto;

  h3 {
    text-align: right;
    padding: 2px 6px;
    border-bottom: 1px solid $border-color;

    span {
      display: inline-block;
      width: 28px;
      height: 28px;
      line-height: 28px;
      font-size: 20px;
      text-align: center;
      cursor: pointer;
    }
  }

  /deep/ .el-submenu__title {
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    color: #fff;
    &:hover {
      color: #2d42af;
      border-radius: 5px;
    }
  }

  /deep/ .el-menu {
    // padding: 0px 20px;
  }

  /deep/ .el-menu-item-group__title {
    padding: 0px 0 7px 20px;
  }

  .el-menu-item {
    height: 39px !important;
    line-height: 39px !important;
    // padding: 0 0 0 20px !important;
    position: relative;
    font-size: 16px;
    color: #fff;
    /*&:before {*/
    /*content: '';*/
    /*position: absolute;*/
    /*left: 0;*/
    /*top: 0;*/
    /*bottom: 0;*/
    /*width: 2px;*/
    /*background-color: $active-color;*/
    /*display: none;*/
    /*}*/
    i {
      font-size: 18px;
      margin-right: 6px;
      color: $tc1;
    }
  }

  .el-menu-item.is-active,
  .el-menu-item:hover {
    color: $active-color;
    background-color: #fff;
    border-radius: 5px;
    i {
      color: $active-color;
    }

    /*&:before {*/
    /*display: block;*/
    /*}*/
  }
}

.left-menu::-webkit-scrollbar {
  width: 3px;
  background-color: transparent;
}

.left-menu::-webkit-scrollbar-track {
  width: 3px;
  background-color: transparent;
}

.left-menu::-webkit-scrollbar-thumb {
  border-radius: 3px;
  width: 0;
  height: 3px;
  background-color: #aaaaaa;
}
</style>

<style lang="scss">
.left-aside .el-menu {
  // width: 80% !important;
  background-color: #2d42af;
  color: #fff;
  .el-menu-item.is-active,
  .el-menu-item:hover {
    color: $active-color;
    background-color: #fff;
    border-radius: 5px;
    i {
      color: $active-color;
    }

    /*&:before {*/
    /*display: block;*/
    /*}*/
  }
}
.padnone {
  .el-submenu__title {
    // padding: 0 60px 0 20px!important;
    min-width: 150px;
    color: #fff;
  }
}
</style>
