<!--
 * @Description: 工具栏
 * @Author: 王晓颖
 * @Date: 2022-05-16 18:41:50
 -->
<template>
  <div v-if="show">
    <!--工具箱-->
    <div v-if="showBaseMap || showLayer || showTool" class="box-container">
      <div v-show="showBaseMap" class="box-btn" @click="clickBox('baseMap')">
        <i class="el-icon-map-location" /> 底图
      </div>
      <div v-show="showBaseMap && showLayer" class="vertical-seperate" />
      <div v-show="showLayer" class="box-btn" @click="clickBox('layer')">
        <i class="el-icon-copy-document" /> 图层
      </div>
      <div v-show="showLayer && showTool" class="vertical-seperate" />
      <div v-show="showBaseMap && !showLayer && showTool" class="vertical-seperate" />
      <!--工具箱弹窗-->
      <el-popover v-show="showTool" v-model="menuShow" placement="bottom-end" width="80" trigger="hover">
        <div class="menu-list">
          <div v-for="menu of toolMenu" :key="menu.menu" class="menu-item" @click="clickMenu(menu)">
            <i :class="'el-icon-'+menu.icon" />
            {{ menu.name }}
          </div>
        </div>
        <div slot="reference" class="box-btn" @click="clickBox('tool')">
          <i class="el-icon-suitcase-1" /> 工具箱
        </div>
      </el-popover>
    </div>
    <!--底图选择-->
    <transition enter-active-class="animate__animated animate__slideInRight" leave-active-class="animate__animated animate__slideOutRight" :duration="500" mode="out-in">
      <div v-show="baseMapWindowShow" class="base-map-window">
        <div class="window-title">
          <div>底图</div>
          <i class="el-icon-close close-icon" @click="baseMapWindowShow=false" />
        </div>
        <div class="window-body">
          <div class="base-map-block" @click="changeBaseMap('gaode_vec')">
            <el-image :src="require('@/assets/overview/gaode_vec.png')" class="base-map-image" mode="fill" />
            <div class="base-map-name">
              矢量地图
            </div>
          </div>
          <div class="base-map-block" @click="changeBaseMap('gaode_sat')">
            <el-image :src="require('@/assets/overview/gaode_sat.png')" class="base-map-image" mode="fill" />
            <div class="base-map-name">
              影像地图
            </div>
          </div>
        </div>
      </div>
    </transition>
    <!--图层选择-->
    <layer-choose-window :show="layerWindowShow" :layers="layers" :checked="layerChecked" @close="layerWindowShow=false" @checked-change="checkedLayerChange" />
  </div>
</template>

<script>
import LayerChooseWindow from './popupLayerChoose'
export default {
  name: 'ToolBox',
  components: { LayerChooseWindow },
  props: {
    show: {
      type: Boolean,
      default: false
    }, // 组件是否显示
    showBaseMap: {
      type: Boolean,
      default: true
    }, // 是否显示底图选项
    showLayer: {
      type: Boolean,
      default: true
    }, // 是否显示图层管理
    showTool: {
      type: Boolean,
      default: true
    }, // 是否显示工具箱
    mapType: {
      type: String,
      default: 'gaode_vec'
    }, // 当前底图类型
    layers: {
      type: Array,
      default: () => []
    }, // 图层列表
    layerChecked: {
      type: Array,
      default: () => []
    }, // 选中的图层
    toolMenu: {
      type: Array,
      default: () => []
    } // 工具栏菜单，格式为{menu:'dataFilter', icon'search', name:'数据筛选'}
  },
  data() {
    return {
      baseMapWindowShow: false, // 底图选择窗口显示
      layerWindowShow: false, // 图层选择窗口显示
      toolWindowShow: false, // 工具菜单窗口显示
      menuShow: false // 工具菜单显示
    }
  },
  methods: {
    // 点击工具栏菜单
    clickBox(type) {
      this.layerWindowShow = false
      this.baseMapWindowShow = false
      this.closeMenuPop()
      this[type + 'WindowShow'] = !this[type + 'WindowShow']
      this.$emit('click' + type)
    },
    // 切换底图
    changeBaseMap(maptype) {
      this.$emit('change-base-map', maptype)
    },
    // 更改选中图层
    checkedLayerChange(checkedLayer) {
      this.$emit('layer-change', checkedLayer)
    },
    // 点击工具箱中菜单项
    clickMenu(menu) {
      this.menuShow = false
      // 清除其他的显示
      this.baseMapWindowShow = false
      this.layerWindowShow = false
      this.$emit('click-menu', menu)
    },
    // 触发工具箱相关弹窗关闭
    closeMenuPop() {
      this.$emit('close-menu-pop')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.box-container{
  position: absolute;
  right: 10px;
  top:10px;
  background-color: #FFFFFF;
  padding: 8px;
  border-radius: 5px;
  box-shadow: 1px 1px 3px #9c9c9c;
  font-size: 14px;
  display: flex;
  align-items: stretch;
  color: #3b3b3b;
  .box-btn{
    padding: 0px 10px;
    &:hover{
      color: #36a3f7;
      cursor: pointer;
    }
  }
  .vertical-seperate{
    background: -webkit-linear-gradient(#ffffff, #9c9c9c, #ffffff);
    width: 1px;
  }
}
.base-map-window{
  position: absolute;
  right: 10px;
  top: 50px;
  width: 200px;
  background-color: rgba(255,255,255,0.9);
  .window-body{
    display: flex;
    flex-wrap: wrap;
    padding: 0px 10px;
  }
  .base-map-block{
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 5px;
    .base-map-image{
      width: 60px;
      height: 60px;
      border-radius: 5px;
    }
    .base-map-name{
      font-size: 14px;
      line-height: 2;
    }
    &:hover{
      color: #36a3f7;
      cursor: pointer;
      .base-map-image{
        border: 1px solid #36a3f7;
      }
    }
  }
}
.window-title{
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 10px;
  .close-icon:hover{
    cursor: pointer;
    color: #36a3f7;
  }
}
.menu-list{
  padding: 0px;
  .menu-item{
    width: 100%;
    padding: 5px 10px;
    i{
      margin-right: 5px;
    }
    &:hover{
      cursor: pointer;
      background-color: #8cc5ff;
      color: #FFF;
    }
  }
}
</style>
