<!-- 左侧工具栏 -->
<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)"
        >
          <img
            width="20px"
            height="20px"
            :src="chiceStatus==index ? item.activeIcon : item.icon"
            alt
          />
          <span>{{item.name}}</span>
        </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>
</template>
<script>
const leftData = [
  {
    id: "tongyong",
    name: "通用",
    icon: require("./../../assets/images/leftImgs/tongyong.png"),
    activeIcon: require("./../../assets/images/leftImgs/tongyongactive.png"),
  },
  {
    id: "equipment",
    name: "设备",
    icon: require("./../../assets/images/leftImgs/equipment.png"),
    activeIcon: require("./../../assets/images/leftImgs/equipmentactive.png"),
  },
  {
    id: "equipList",
    name: "设备组",
    icon: require("./../../assets/images/leftImgs/equipList.png"),
    activeIcon: require("./../../assets/images/leftImgs/equipListActive.png"),
  },
  {
    id: "guanxian",
    name: "管线",
    icon: require("./../../assets/images/leftImgs/guanxian.png"),
    activeIcon: require("./../../assets/images/leftImgs/guanxianactive.png"),
  },
  {
    id: "space",
    name: "空间",
    icon: require("./../../assets/images/leftImgs/space.png"),
    activeIcon: require("./../../assets/images/leftImgs/spaceactive.png"),
  },
  {
    id: "same",
    name: "同类",
    icon: require("./../../assets/images/leftImgs/same.png"),
    activeIcon: require("./../../assets/images/leftImgs/sameactive.png"),
  },
];
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("");
    },
  },
};
</script>
<style lang="less" scoped>
ul,
li {
  margin: 0;
  padding: 0;
  list-style-type: none;
}
.left-tool-bar {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  height: calc(~"100% - 2px");
  .btn-list {
    height: 100%;
    ul {
      width: 54px;
      height: 100%;
      border-top: 1px solid #eee;
      border-right: 1px solid #eee;
      li {
        width: 100%;
        height: 58px;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        cursor: pointer;
        span {
          color: #8d9399;
          font-size: 12px;
        }
      }
      li:hover {
        background: #e4e5e7;
      }
      .btn-active {
        background: #e1f2ff !important;
        span {
          color: #0091ff;
        }
      }
    }
  }
}
.el-drawer__wrapper {
  left: 64px;
  top: 50px;
  // background: rgba(255, 255, 255, 1);
  // box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 242px;
}
</style>