<!-- 左侧工具栏 -->
<template>
  <div class="left-tool-bar">
    <div class="btn-list">
      <ul>
        <li
          v-for="(item, index) in leftData"
          :key="index"
          :class="{ 'btn-active': chiceStatus == index }"
          @click="openTool(index)"
        >
          <span :class="['icon', 'iconfont', 'fontstyle', item.icon]"></span>
          <span>{{ item.name }}</span>
          <div class="btborder"></div>
        </li>
      </ul>
    </div>
    <el-drawer
      size="220px"
      :with-header="false"
      :destroy-on-close="true"
      :visible.sync="drawer"
      :direction="direction"
      :modal="false"
      :modal-append-to-body="false"
      :show-close="true"
      :before-close="handleClose"
      :wrapperClosable="false"
    >
      <legendList :chiceStatus="chiceStatus"></legendList>
    </el-drawer>
    <div class="close-lengend" v-show="drawer" @click="closeDraw">
      <i class="el-icon-arrow-left"></i>
    </div>
  </div>
</template>
<script>
const leftData = [
  {
    id: "tongyong",
    name: "通用",
    icon: "icon-tongyong",
  },
  {
    id: "guanxian",
    name: "管线",
    icon: "icon-guanxian",
  },
  {
    id: "equipment",
    name: "设备",
    icon: "icon-shebei",
  },
  {
    id: "equipList",
    name: "设备组",
    icon: "icon-shebeizu",
  },
  {
    id: "space",
    name: "空间",
    icon: "icon-kongjian",
  },
  {
    id: "same",
    name: "楼层",
    icon: "icon-louceng",
  },
];
import legendList from "./leftToolBar/legendList.vue";
import { mapMutations } from "vuex";
export default {
  components: { legendList },
  data() {
    return {
      drawer: false,
      chiceStatus: -1, //选中按钮状态
      direction: "ltr",
      leftData,
    };
  },
  methods: {
    ...mapMutations(["SETCHOICELEHEND"]),
    handleClose() {
      this.drawer = false;
    },
    openTool(val) {
      if (val != this.chiceStatus) {
        this.chiceStatus = val;
        if (this.drawer) {
          this.drawer = false;
          4;
          setTimeout(() => {
            this.drawer = true;
          }, 300);
        } else {
          this.drawer = true;
        }
      } else {
        this.drawer = !this.drawer;
        this.chiceStatus = -1;
      }
    },
    choiceStatus() {
      this.chiceStatus = 0;
      this.drawer = false;
      this.SETCHOICELEHEND("");
    },
    // 关闭测弹窗
    closeDraw(){
      this.drawer = !this.drawer
       this.chiceStatus = -1
    }
  },
};
</script>
<style lang="less" scoped>
ul,
li {
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.left-tool-bar {
  height: calc(~"100% - 2px");
  position: relative;
  .btn-list {
    height: 100%;
    z-index: 99;
    position: relative;
    ul {
      width: 54px;
      height: 100%;
      border-top: 1px solid #eee;
      border-right: 1px solid #eee;
      li {
        width: 100%;
        height: 58px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        cursor: pointer;
        border-right: 2px solid rgba(0, 145, 255, 0);
        .btborder {
          width: 30px;
          height: 1px;
          background: #eee;
        }
        span {
          color: #8d9399;
          font-size: 12px;
        }
        .fontstyle {
          font-size: 18px;
        }
      }
      li:hover {
        background: #f5f6f7;
      }
      .btn-active {
        background: #e1f2ff !important;
        border-right: 2px solid #0091ff;
        span {
          color: #0091ff;
        }
      }
    }
  }
  .close-lengend {
    width: 20px;
    height: 40px;
    position: absolute;
    right: -240px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 999;
    border-radius: 0px 5px 5px 0;
    cursor: pointer;
    font-size: 28px;
    color: #e4e5e7;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #e4e5e7;
    background: #ffffff;
    &:hover {
      color: #0091ff;
      border: 1px solid #0091ff;
    }
  }
}
.el-drawer__wrapper {
  left: 54px;
  top: 84px;
  // box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.1);
  width: 221px;
  border-right: 1px solid #eee;
}
</style>