<template>
  <div id="pageLeft" :class="{leftClose:!leftIsOpen}">
    <div class="leftContainer" v-if="leftIsOpen">
      <div class="topContainer">
        <div class="logoDiv">
          <img :src="logoUrl" class="logoImg" />
        </div>
        <div class="middDiv">
          <i class="el-icon-fa-bars fa fa-bars" @click="toggleLeft"></i>
        </div>
      </div>
      <div class="menuDiv">
        <el-menu
          text-color="#fff"
          active-text-color="#ffd04b"
          background-color="#364150"
          router
        >
          <el-menu-item-group v-for="menu in menus" :key="menu.id">
            <template slot="title">
              <span v-text="menu.name"></span>
            </template>
            <leftMenu
              :menu="subMenu"
              v-for="subMenu in menu.children"
              :key="subMenu.id"
              :index="subMenu.id"
              :leftIsOpen="leftIsOpen"
            ></leftMenu>
          </el-menu-item-group>
        </el-menu>
      </div>
    </div>
    <div class="leftContainer" v-if="!leftIsOpen">
      <div class="topContainer">
        <div class="middDiv middDivClose">
          <i class="el-icon-fa-bars fa fa-bars el-icon-fa-barsClose" @click="toggleLeft"></i>
        </div>
      </div>
      <div class="menuDiv">
        <el-menu
          text-color="#fff"
          active-text-color="#ffd04b"
          background-color="#364150"
          router
        >
          <el-menu-item-group v-for="menu in menus" :key="menu.id">
            <leftMenu
              :menu="subMenu"
              v-for="subMenu in menu.children"
              :key="subMenu.id"
              :index="subMenu.id"
              :leftIsOpen="leftIsOpen"
            ></leftMenu>
          </el-menu-item-group>
        </el-menu>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
import leftMenu from "./leftMenu";
export default {
  props: [],
  data() {
    return {
      leftIsOpen: true,
      logoUrl: require("@/assets/images/logo.png"),
    };
  },
  computed: {
    ...mapState(["menus"]),
  },
  methods: {
    toggleLeft: function () {
      this.leftIsOpen = !this.leftIsOpen;
    },
  },
  created() {},

  mounted() {},
  components: {
    leftMenu,
  },
};
</script>

<style scoped>
#pageLeft {
  width: 235px;
  height: 100%;
}

.leftClose{
  width:64px !important;
}

.leftContainer {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topContainer {
  background: #2b3643;
  height: 50px;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.menuDiv {
  flex: 1;
  background: #364150;
  overflow: auto;
}

.logoImg {
  height: 18px;
  margin-left: 20px;
}

.el-icon-fa-bars {
  font-family: FontAwesome !important;
  font-size: inherit;
  font-style: normal;
  font-weight: 400;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  vertical-align: baseline;
  display: inline-block;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #ffffff;
  margin-left: 88px;
  cursor: pointer;
}

.el-icon-fa-barsClose{
  margin-left: 0;
}

.logoDiv {
  flex: 1;
}

.middDiv {
  flex: 1;
}

.middDivClose{
  text-align: center;
}

.el-menu-item-group__title span {
  font-size: 14px !important;
  color: #68707b;
  font-weight: bold;
}
</style>

