<template>
  <div :class="['leftMenu',{collapsed:leftMenuCollapsed}]">
    <div class="logo" @click="goHome">
      <!--      <img :class="['logo-img',{'small-img':leftMenuCollapsed}]" src="../../../assets/logo.png" alt="">-->
      <span v-if="!leftMenuCollapsed" class="title">业委会管理系统</span>
    </div>
    <el-menu
        :unique-opened="true"
        @select="handlerSelect"
        mode="vertical"
        :collapse="leftMenuCollapsed">
      <template v-for="(item,index) in menuList">
        <el-menu-item :index="item.name" v-if="item.children.length == 0">
          <template slot="title">
            <i :class="item.icon" style="width:1em;height: 1.2em;color: #333333"></i>
            <span style="font-size: 1em;">{{item.title}}</span>
          </template>
        </el-menu-item>

        <el-submenu :index="item.name" style="text-align: left;" v-if="item.children.length != 0" class="submenu">
          <template slot="title">
            <i :class="item.icon" style="width:1.2em;height: 1.2em;color: #333333"></i>
            <span style="font-size: 1em;">{{ item.title }}</span>
          </template>
          <el-menu-item :index="tar.name" v-for="(tar,inde) in item.children" :key="inde">
            <i :class="tar.icon" style="width:1em;height: 1.2em;color: #333333"></i>
            {{ tar.title }}
          </el-menu-item>
        </el-submenu>
      </template>


    </el-menu>
  </div>

</template>

<script>
import {mapGetters} from 'vuex'
import {getDeepObj} from "@/util";
let getMenus = (list)=>{
  list.forEach(x=>{
    changeData(x)
  })
  function changeData(obj){
    obj.title = obj.meta.title
    obj.name = obj.path
    obj.icon = obj.meta.icon
    if(obj.children){
      obj.children.forEach(x=>{
        changeData(x)
      })
    }
  }
  return list
}
export default {
  name: "leftMenu",
  data() {
    return {
      menuList: [
        {
          name:'voteActivity',
          icon:"el-icon-message",
          title:'投票活动',
          children:[],
        },
        {
          name:'notice',
          icon:"el-icon-message-solid",
          title:'公告通知',
          children:[],
        },
        {
          name:'verify',
          icon:"el-icon-office-building",
          title:'房产审核',
          children:[],
        },
        {
          name:'suggestions',
          icon:"el-icon-s-comment",
          title:'意见反馈',
          children:[],
        },


        // {
        //     icon:"",
        //     title:'基础操作',
        //     children:[
        //
        //     ]
        // },

      ],
    };
  },

  computed: {
    ...mapGetters(['leftMenuCollapsed']),
    roleId() {
      return localStorage.getItem('id');
    }
  },
  watch: {},
  mounted() {

  },
  methods: {

    goHome() {
      this.$router.push({name: 'home'})
    },
    handlerSelect(index) {
      if (index) {
        this.defaultName = index;

        this.$router_(getDeepObj(this.menuList, 'name', index),)
      } else {
        return
      }


    }
  }
}
</script>

<style scoped lang="less">
::-webkit-scrollbar {
  display: none; /*ChromeSafari*/
}

.leftMenu {
  /*border:1px solid red;*/
  width: 160px;
  height: 100%;
  overflow-y: auto;
  //background-color: rgb(48, 65, 86);
  background-color: white;
  transition: all 0.3s;
  z-index: 10;
  flex: 0 0 auto;
  border-right: 1px solid #e6e6e6;

  .logo {
    height: 60px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    border-bottom: 1px solid #e8e8e8;

    .logo-img {
      width: 40px;
      height: 40px;
      border-radius: 100%;
    }

    .small-img {
      width: 30px;
      height: 30px;
    }

    .title {
      font-size: 16px;
      font-weight: 700;
      display: inline-block;
    }
  }
}

.collapsed {
  width: 80px;
}


i {
  font-size: 18px !important;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.leftMenu {
  height: 100%;
  overflow-y: auto;

}
.el-menu {
  border-right: 0px;
}

</style>
