<template>
  <div id="greenbelt">
    <ul class="screen-list">
      <li v-for="item in greenbeltList" :key="item.id" :title="item.name" @click="selectTool(item)">
        <img :src="imgSrc(item)" class="screen-img" />
      </li>
    </ul>
  </div>
</template>

<script>
import {addBufferLayer, setWatchLineAny} from "@/units/map/AddLayer";

export default {
  name: "Greenbelt",
  data(){
    return{
      greenbeltList:[
        {
          id:'0001',
          name:'绿地统计',
          chosen:false,
        },
        {
          id:'0002',
          name:'绿地分析',
          chosen:false,
        },
      ],
    }
  },
  methods:{
    imgSrc(item){
      if(item.chosen){
        return require('../../../../../assets/imgs/mainPage/'+item.name+'-选中.png')
      }else{
        return require('../../../../../assets/imgs/mainPage/'+item.name+'-未选中.png')
      }
    },
    selectTool(item){
      setWatchLineAny('line',false);
      for(let i=0;i<this.greenbeltList.length;i++){
        if(item.name ==this.greenbeltList[i].name) {
          this.greenbeltList[i].chosen = !this.greenbeltList[i].chosen;
          if(this.greenbeltList[i].chosen){
            switch (this.greenbeltList[i].name){
              case "绿地统计":
                this.$emit('setToolDetailType','greenbeltAnalysis')
                break;
              case "绿地分析":
                this.$emit('setToolDetailType','greenbeltAnalysisDynamic')
                break;
            }
          }else{
            switch (this.greenbeltList[i].name){
              case "绿地统计":
                addBufferLayer(true);
                this.$emit('setToolDetailType','')
                break;
              case "绿地分析":
                addBufferLayer(true);
                this.$emit('setToolDetailType','')
                break;
            }
          }
        }
        else{
          this.greenbeltList[i].chosen = false
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
#greenbelt{
  position: absolute;
  right:70px;
  top:200px;
  z-index: 1;
  text-align: center;
  background: rgba(0, 31, 112, 0.6);
  border-radius: 4px;
  border: 1px solid #00a1ff;
  color: #fff;
  .screen-list{
    padding: 10px 0px 10px 0px;
    margin: 0;
  }
  .screen-list li{
    list-style: none;
    cursor: pointer;
    padding: 2px 0px 2px 0px;
  }
  .screen-img{
    width: 35px;
    height: 35px;
  }
}
</style>
