<template>
  <div
    class="sidebar"
    :style="collapse ? 'width:85px' : 'width:220px'"
  >
    <div
      class="logo"
      v-if="!collapse"
    >
      <img
        style="width: rem(90); height: rem(24)"
        src="@/assets/img/img_logo2.png"
      />
      <div class="title"><span class="point"></span>{{ $store.getters['getThisDetai'].name || sessSetThisDetai }}</div>
    </div>
    <div
      class="logo shrink"
      v-else
    >
      <div class="text">{{ $store.getters['getThisDetai'].name || sessSetThisDetai }}</div>
    </div>
    <div class="menu-wrap no-scrollbar">
      <el-menu
        class="sidebar-el-menu"
        ref="sidebarelmenu"
        :default-active="onRoutes"
        :collapse="collapse"
        background-color="#171F32"
        text-color="#aaadba"
        active-text-color="#0EAEFF"
        unique-opened
        collapse-transition
        router
        :style="collapse ? 'width:84px' : 'width:220px'"
      >
        <menu-tree
          :menuList="menuList"
          :collapse="collapse"
          :openArray="openArray"
        ></menu-tree>
      </el-menu>
    </div>
    <div class="footer">
      <img
        :class="[collapse ? 'expandhover' : 'packuphover']"
        :src="collapse ? btnCollpaseright : btnCollpaseleft"
        @click="collapseChage"
      />
    </div>
  </div>
</template>

<script>
import MenuTree from './MenuTree.vue';
export default {
  data () {
    return {
      btnCollpaseright: require('@assets/img/btn_collpaseright.png'),
      btnCollpaseleft: require('@assets/img/btn_collpaseleft.png'),
      openList: []
    };
  },
  components: {
    MenuTree
  },
  computed: {
    onRoutes () {
      return this.$route.path;
    },
    collapse () {
      return this.$store.getters['getCollapse'];
    },
    menuList () {
      let list = this.$store.getters['getMenuList'];
      return list;
    },
    openArray () {
      return this.openList;
    },
    sessSetThisDetai () {
      let text = '';
      if (!!window.sessionStorage.getItem('setThisDetai')) {
        text = JSON.parse(window.sessionStorage.getItem('setThisDetai')).name;
      }
      return text;
    }
  },
  methods: {
    // 侧边栏折叠
    collapseChage () {
      this.$store.dispatch('collapse', !this.collapse);
    },
    thisfindMen (arr, indexPath) {
      let status = [];
      arr.map((v, index) => {
        if (v.children && v.id != '405') {
          v.children.map((s) => {
            if ('/' + s.linkPath === indexPath) {
              status.push(v.linkPath, s.linkPath);
            }
          });
        } else if (v.id == '405') {
          for (let i = 0; i < v.children[v.children.length - 1].children.length; i++) {
            if ('/' + v.children[v.children.length - 1].children[i].linkPath === indexPath) {
              status.push(v.children[v.children.length - 1].linkPath, v.children[v.children.length - 1].children[i].linkPath);
            }
          }
        } else {
          if ('/' + v.linkPath === indexPath) {
            status.push(v.linkPath);
          }
        }
      });
      return status;
    }
  },
  watch: {
    $route (newValue, oldValue) {
      this.openList = this.thisfindMen(this.$store.getters['getMenuList'], newValue.path);
    }
  },
  created () {
    this.openList = this.thisfindMen(this.$store.getters['getMenuList'], this.$route.path);
  },
  mounted () {
    // this.$refs.sidebarelmenu.$children[0].$children[0].$el.style.paddingLeft = 0;
    // console.log((this.$refs.sidebarelmenu.$children[0].$children[0].$el.style.paddingLeft = 0));
  }
};
</script>

<style  lang="scss">
@import '@assets/css/public-style.scss';
.sidebar {
    width: rem(220);
    display: flex;
    flex-direction: column;
    background: #171f32;
    border-radius: 0px rem(30) rem(30) 0px;
    z-index: 2;
    .logo {
        width: 100%;
        height: rem(110);
        color: #ffffff;
        padding: rem(35) rem(10) 0 rem(20);
        border-bottom: 1px solid #2a335c;
        margin-bottom: rem(25);
        img {
            width: rem(90);
            height: rem(24);
            display: inline-block;
            vertical-align: middle;
            margin-right: rem(6);
        }
        .title {
            font-size: rem(16);
            font-weight: 500;
            display: inline-block;
            vertical-align: middle;
            background: rgba(255, 255, 255, 0.1);
            border-radius: rem(4);
            border: 1px solid rgba(255, 255, 255, 0.4);
            padding: 0px rem(7);
        }
        .point {
            width: rem(4);
            height: rem(4);
            display: inline-block;
            // margin-right: 5px;
            vertical-align: middle;
            text-align: center;
        }
        .text {
            width: rem(40);
            margin-left: rem(-14);
        }
    }
    .menu-wrap {
        overflow: auto;
        flex: 1;
        scrollbar-width: 0;
    }
    .menu-footer.dark {
        bottom: 0;
        left: 0;
        width: rem(220);
        height: rem(30);

        div {
            width: 100%;
            height: 100%;
            border-radius: 0px 0 rem(30) 0px;
            background-color: #171f32;
            border: none;
        }
        &.dark {
            background-color: #070f22 !important;
            z-index: 1;
        }

        &.light {
            background-color: #f4f7f9 !important;
            z-index: 1;
        }
    }
    .footer {
        position: absolute;
        bottom: rem(30);
        left: rem(20);
        z-index: 11;
        width: rem(30);
        height: rem(30);
        img {
            display: block;
            width: rem(24);
            height: rem(24);
            cursor: pointer;
        }
    }
}
.el-menu {
    border: none;
}

.sidebar-el-menu .el-submenu.is-opened > .el-submenu__title {
    //设置一级菜单点开后的状态
    color: #fff !important;
    background: rgb(44, 53, 74);
    border-radius: 0;
}
.sidebar-el-menu > .el-submenu.is-opened > .el-menu--inline > .el-submenu.is-opened > .el-submenu__title {
    color: #fff !important;
}
.sidebar-el-menu > div > .el-submenu.is-opened.is-active > .el-submenu__title {
    background: #2c354a !important;
    border-radius: rem(32) 0px 0px rem(32);
    color: rgb(39, 135, 241) !important;
    // border-right: 2px solid #2787f1;
    .el-submenu__icon-arrow::before {
        // color: rgb(39, 135, 241);
        color: #0eaeff;
    }
}
.sidebar-el-menu > div > .el-submenu > .el-menu.el-menu--inline {
    width: 100% !important;
}
// el-submenu
.sidebar-el-menu > div > .el-submenu > .el-menu.el-menu--inline > div > .el-submenu > .el-menu.el-menu--inline {
    width: 100% !important;
}
.el-menu-item.is-active {
    // color: rgb(39, 135, 241);
    color: #0eaeff;
}
.el-submenu.is-active > div > span {
    // color: rgb(39, 135, 241);
    color: #0eaeff !important;
}

.sidebar .logo.shrink {
    display: flex;
    font-size: rem(16);
    justify-content: center;
    // color: $mainTextColor;
    border-bottom: 2px solid #2a335c;
    margin-bottom: rem(20);
    align-items: flex-start;
    .text {
        width: rem(48);
        height: rem(48);
        background: rgba(255, 255, 255, 0.1);
        border-radius: rem(4);
        border: 1px solid rgba(255, 255, 255, 0.4);
        text-align: center;
    }
}

// .sidebar .logo.shrink {
//     display: flex;
//     justify-content: center;
//     color: #2787f1;
//     border-bottom: 2px solid #2a335c;
//     margin-bottom: rem(20);
//     align-items: flex-start;
//     .text {
//         width: rem(48);
//         height: rem(48);
//         background: rgba(255, 255, 255, 0.1);
//         border-radius: rem(4);
//         border: 1px solid rgba(255, 255, 255, 0.4);
//         text-align: center;
//     }
// }

.el-menu--collapse > .is-active {
    color: #2787f1;

    background: #2c354a;
    border-radius: rem(32) 0px 0px rem(32);
}

.el-menu--collapse > .is-active > .el-submenu__title {
    background: transparent !important;
}
.el-submenu > .el-submenu__title:hover {
    //设置一级菜单的鼠标经过时候的样式
    background: rgb(44, 53, 74) !important;
    border-radius: rem(32) 0px 0px rem(32) !important;
}
.el-menu-item:hover {
    border-radius: rem(32) 0px 0px rem(32);
}

.el-menu-item.is-active {
    background-color: #2c354a !important;
}
.el-menu > div > .el-submenu > .el-menu--inline > div > .el-menu-item {
    background: none !important;
}
</style>
