<!--信息中心-->
<template>
  <div class="visual-con">
    <!--头部-->
    <vheader></vheader>
    <!--主体-->
    <div class="visual-body">
      <!-- 左侧 -->
      <div class="leftbar w-10" :class="indentleft" ref="left">
        <div class="forthis">
          <dv-border-box-13 backgroundColor="rgba(19, 13, 5, 0.9)" :color="['#d5811d', '#ebd033']" style="padding-bottom: 1rem;">
            <img src="../assets/images/integrated/light.png" style="width: 100%; margin-top: .4rem;"/>
            <div class="i-list-con h-78">
              <div class="d-l-con-icon">
                <div class="icon-con" :class="{on:iconCurrentIndex==item.resourceTable}"
                     v-for="(item,index) in resourcesList"
                     v-on:click="indentleftSetMarkers(item.key)">
                  <div class="iconfont icon icon-normal" :class="item.icon"></div>
                  <div class="icon-text">
                    <h6 v-if=" item.count.length > 10">{{ item.count.substring(0,10) }}<br>{{item.count.substring(10)}}</h6>
                    <h6 v-else>{{ item.count}}</h6>
                    <h5>{{ item.name }}</h5>
                  </div>
                </div>
              </div>
            </div>
          </dv-border-box-13>
        </div>
      </div>
      <!-- 地图 -->
      <supermap ref="supermap" style="width: 100%;height: 100vh;" :mapDiv="'forestMap'" class="indexSupermapClass"
                :mapSite="{doubleClickZoom:false}" :codes="['9fa5']" :isSideBySide="false" @showPointDetails="showPointDetails"></supermap>
      <!--      <button @click="showEventInfo1" style="position: absolute; right: 50%;top: 45%;z-index: 1000;">弹层事件演示用按钮-->
      <!--      </button>-->
      <!-- 右侧 -->
      <div class="rightbar" :class="indentright" ref="right">
        <div class="forthis">
          <dv-border-box-13 backgroundColor="rgba(19, 13, 5, 0.9)" :color="['#d5811d', '#ebd033']" style="padding-bottom: 1rem;">
            <img src="../assets/images/integrated/light.png" style="width: 100%; margin-top: .4rem;"/>
            <div class="this-title">
              <span>数据分布</span>
              <dv-decoration-3 style="width:150px;height:15px;margin-right: 1rem;" :color="['#935713', '#ebd033']"/>
            </div>
            <div class="i-list-con h-73">
              <div class="overflow-y" style="height: 39vh">
                <div class="d-l-con" :class="{on:listCurrentIndex==item.deptId}"
                     v-for="(item,index) in deptGroupList"
                     v-on:click="indentleftByDeptIdSetMarkers(item.deptId)">
                  <div class="d-l-l-text">
                    <i class="i-small"></i>
                    <h4>{{ item.deptName }}</h4>
                  </div>
                  <div class="d-l-l-count">{{ item.eventCount }}</div>
                </div>
              </div>
              <div class="overflow-y" style="height: 34vh;">
                <div id="data-chart" style="width: 100%;height:34vh;"></div>
              </div>
            </div>
          </dv-border-box-13>
        </div>
      </div>
      <vBottomMenu ref="bottomMenu"></vBottomMenu>
      <!--<el-tooltip :content="indentText" placement="top" :disabled="indentdisabled">-->
        <!--<div class="mascot" ref="mascot" :class="indentStyle" @click="indent"><img-->
          <!--src="@/assets/images/mascot.png"/>-->
        <!--</div>-->
      <!--</el-tooltip>-->

    </div>
    <pointDetails ref="pointDetails"></pointDetails>
    <eventLocation ref="eventLocation"></eventLocation>
    <TVWall ref="TVWall"></TVWall>
  </div>
</template>

<script>
import {
  getResource,
  getFindAllType,
  getFindAllZhanList
} from '@/api/datacenter'

import supermap from '@/components/supermap' //超图
import vheader from '@/components/v-header.vue' //一体化共用头部
import vBottomMenu from '@/components/vBottomMenu.vue' //一体化公共底部菜单
import eventLocation from '@/components/eventLocation.vue' //事件定位弹窗
import TVWall from '@/components/TVWall.vue' //电视墙弹窗

import pointDetails from './pointDetails.vue' //点位详情页面

// import echarts from 'echarts'
let echarts = require('echarts')
export default {
  components: {
    supermap,
    vheader,
    vBottomMenu,
    eventLocation,
    TVWall,
    pointDetails
  },
  created() {
    /** ----------------------------------底部按钮公用组件开始------------------------------------- */
    window.showDialog = this.showDialog
    window.choseLayerSwitching = this.choseLayerSwitching
    window.choseLayerSwitchingList = this.choseLayerSwitchingList
    /** ----------------------------------底部按钮公用组件结束------------------------------------- */
  },
  mounted() {
    this.getResource();
    this.bottomMenuList() //获取底部公共组件消息和任务
  },
  data() {
    return {
      iconCurrentIndex: '',
      listCurrentIndex: '',
      markersList: [],
      iframeBoo: true,
      open: false,
      iframeVue: null,
      activeName: 'info',
      radio: '1',
      //类型
      resourceTable: '',
      //左侧资源
      resourcesList: [],
      // resourcesMap: {},
      //右侧资源
      deptGroupList: [],
      supermapDianList: [],//点击左侧数据表获取到的点位数据
      source: [],
      //左右缩进
      indentStyle: '',
      indentleft: '',
      indentright: '',
      indentText: '收起左右栏',
      indentdisabled: false,
    }
  },

  methods: {
    /** ----------------------------------底部按钮公用组件开始------------------------------------- */
    bottomMenuList() {
      this.$refs.bottomMenu.selectTaskList()//获取任务列表
      this.$refs.bottomMenu.selectMessageList()//获取消息列表
    },
    showDialog(click) {
      if (click == 'eventLocation') {
        this.$refs.eventLocation.showEventLocation()
        this.$refs.supermap.isEditableLayers = false
        this.$refs.bottomMenu.showChild = false
        this.$refs.bottomMenu.showBanChild = false
        this.$refs.bottomMenu.showChangChild = false
      } else if (click == 'editableLayers') {
        this.$refs.bottomMenu.showChild = false
        this.$refs.bottomMenu.showBanChild = false
        this.$refs.bottomMenu.showChangChild = false
        if (!this.$refs.supermap.isEditableLayers) {
          this.$refs.supermap.isEditableLayers = true
        } else {
          this.$refs.supermap.isEditableLayers = false
        }
      } else if (click == 'layerSwitching') {
        this.$refs.supermap.isEditableLayers = false
        this.$refs.bottomMenu.showBanChild = false
        this.$refs.bottomMenu.showChangChild = false
        if (!this.$refs.bottomMenu.showChild) {
          this.$refs.bottomMenu.showChild = true
        } else {
          this.$refs.bottomMenu.showChild = false
        }
      } else if (click == 'TVWall') {
        this.$refs.TVWall.showTVWall()
        this.$refs.supermap.isEditableLayers = false
        this.$refs.bottomMenu.showChild = false
        this.$refs.bottomMenu.showBanChild = false
        this.$refs.bottomMenu.showChangChild = false
      } else if (click == 'forestban') {
        this.$refs.supermap.isEditableLayers = false
        this.$refs.bottomMenu.showChild = false
        this.$refs.bottomMenu.showChangChild = false
        if (!this.$refs.bottomMenu.showBanChild) {
          this.$refs.bottomMenu.showBanChild = true
        } else {
          this.$refs.bottomMenu.showBanChild = false
        }
      } else if (click == 'forestchang') {
        this.$refs.supermap.isEditableLayers = false
        this.$refs.bottomMenu.showBanChild = false
        this.$refs.bottomMenu.showChild = false
        if (!this.$refs.bottomMenu.showChangChild) {
          this.$refs.bottomMenu.showChangChild = true
        } else {
          this.$refs.bottomMenu.showChangChild = false
        }
      }

    },
    //选择图层
    choseLayerSwitching(url, isClear) {
      this.$refs.supermap.layerSwitching(url, isClear)
    },
    //选择图层(传递数组)
    choseLayerSwitchingList(urlList) {
      this.$refs.supermap.layerSwitchingList(urlList)
    },
    /** ----------------------------------底部按钮公用组件结束------------------------------------- */
    //数据分布chart
    dataChat() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('data-chart'))
      // 绘制图表
      const dfColor = ['#92E1FF', '#0097FB', '#30ECA6', '#FFC227', '#FF4848']
      myChart.setOption({
        dataset: {
          source: this.source
        },
        tooltip: {
          trigger: 'item'

        },
        grid: {
          top: '5%',
          left: '2%',
          // right: "4%",
          bottom: '-5%',
          width: '75%',
          containLabel: true
        },
        xAxis: {
          show: false,
          type: 'value'
        },
        yAxis: {
          type: 'category', // 不设置类目轴，抽离的dataset数据展示不出来
          inverse: true,
          axisLabel: {
            show: true,
            textStyle: {
              color: '#5deaff',
              fontSize: '12'
            }
          },
          splitLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          }
        },

        series: [{

          type: 'bar',
          animationCurve: 'easeOutBack',
          barWidth: 5,
          label: {
            show: true,
            position: 'right',
            offset: [0, 0],
            color: '#88dfd5',
            // fontSize: "12",
            style: {
              fill: '#fff'
            }
          },
          backgroundBar: {
            show: true,
            style: {
              fill: 'rgba(97,152,255,0.20)'
            }
          },
          barStyle: {
            stroke: 'rgba(41,244,236,1)'
          },
          gradient: {
            color: ['rgba(41,244,236,1)', 'rgba(41,244,236,0)']
          },
          itemStyle: {
            label: {
              show: true
            },
            labelLine: {
              show: false
            },
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 0,
              color: 'rgba(41,244,236,0)'
            },
              {
                offset: 1,
                color: 'rgba(41,244,236,.5)'
              }
            ]),
            borderColor: '#a2f9f7',
            shadowBlur: 16,
            shadowColor: '#a2f9f7'
          }
        }]
      })

    },

    //吉祥物收起左右框
    indent() {
      let list = document.getElementsByClassName('el-tooltip__popper')
      list[list.length - 1].style.display = 'none'
      if (this.indentStyle == '') {
        this.indentStyle = 'indent-style'
        this.indentleft = 'indent-left'
        this.indentright = 'indent-right'
        this.indentText = '展开左右栏'
      } else if (this.indentText == '展开左右栏') {
        this.indentStyle = ''
        this.indentleft = ''
        this.indentright = ''
        this.indentText = '收起左右栏'
      }
    },

    // 弹层方法
    // 弹层方法
    showEventInfo1() {
      this.eventInfoVisible1 = true
    },
    showEventInfo2() {
      this.eventInfoVisible2 = true
    },

    showPointDetails(pointParam){
      //事件信息弹出
      this.$refs.pointDetails.showPointDetails(pointParam);
    },

    getResource() {
      let that = this
      //获取左侧菜单列表
      getResource().then(res => {
        const resourcesMap = res.data;
        // const resourcesMap = [];
        // let data = res.data;
        // console.log("data=",data)
        // for(let key in data){
        //   if(key == 'getNumByVarieties' ||
        //     key == 'getLivestockNumByVarieties' ||
        //     key == 'enterpriseStat' ||
        //     key == 'getInformation' ||
        //     key == 'getSupervise' ||
        //     key == 'grainFourSeasons'
        //   ){
        //     resourcesMap.push({key: data[key]});
        //   }
        // }
        for(let key in resourcesMap){
          const map = {};
          map.count=resourcesMap[key];
          if(key == 'buzhu'){map.name="补助次数";}
          if(key == 'gengdi'){map.name="耕地面积";map.count=resourcesMap[key]+"㎡";}
          if(key == 'hezuoshe'){map.name="合作社数量";}//有经纬度
          if(key == 'huafei'){map.name="化肥库存";map.count=resourcesMap[key]+"吨";}
          if(key == 'nongji'){map.name="农机站数量";}//有经纬度
          if(key == 'nongju'){map.name="农具库存";map.count=resourcesMap[key]+"个";}
          if(key == 'xubao'){map.name="畜保站数量";}//有经纬度
          if(key == 'yangzhi'){map.name="养殖及粪污处理点";}//有经纬度
          if(key == 'zhibao'){map.name="植保数量";}//有经纬度
          if(key == 'zhongzhi'){map.name="种植产量";map.count=resourcesMap[key]+"吨";}
          if(key == 'zhongzi'){map.name="种子库存";map.count=resourcesMap[key]+"吨";}

          // 备案畜禽规模养殖场统计	/agricultureBigData/getNumByVarieties
          // 种畜禽养殖场统计	/agricultureBigData/getLivestockNumByVarieties
          // 企业分布统计	/agricultureBigData/enterpriseStat
          // 农药信息统计	/agricultureBigData/getInformation
          // 农资监管统计	/agricultureBigData/getSupervise
          // 粮食四季变化	/agricultureBigData/grainFourSeasons
          if(key == 'getNumByVarieties'){map.name="备案养殖场";map.count=resourcesMap[key]+"";}
          if(key == 'getLivestockNumByVarieties'){map.name="种畜禽养殖场";map.count=resourcesMap[key]+"";}
          if(key == 'enterpriseStat'){map.name="企业数量";map.count=resourcesMap[key]+"";}
          if(key == 'getInformation'){map.name="农药数量";map.count=resourcesMap[key]+"L";}
          if(key == 'getSupervise'){map.name="农资监管数量";map.count=resourcesMap[key]+"";}
          if(key == 'grainFourSeasons'){map.name="粮食数量";map.count=resourcesMap[key]+"吨";}
          map.icon='sj-icon-'+key;
          map.key=key;
          if(key == 'getNumByVarieties' ||
            key == 'getLivestockNumByVarieties' ||
            key == 'enterpriseStat' ||
            key == 'getInformation' ||
            key == 'getSupervise' ||
            key == 'grainFourSeasons'
          ){
            // that.resourcesList.push(map);
          }
          that.resourcesList.push(map);
        }
      })
    },
    indentleftSetMarkers(type) {
      let that = this
      that.resourceTable=type;
      getFindAllType(type).then(res => {
        that.deptGroupList = res.data.dept;
        that.supermapDianList = res.data.list;
        that.source = [];
        that.markersList = [];
        //点击左侧右侧数据展示及横向柱状图
        if (res.data != null && res.data.dept.length > 0) {
          for (let i = 0; i < res.data.dept.length; i++) {
            let aa = [res.data.dept[i].deptName, res.data.dept[i].eventCount];
            that.source.push(aa);
          }
        }
        this.dataChat();
        if (res.data != null && res.data.list.length > 0) {
          if(type=='hezuoshe'||type=='nongji'||type=='zhibao'||type=='xubao'||type=='yangzhi'){
            for (let i = 0; i < res.data.list.length; i++) {
              let markersMap = {
                lng: res.data.list[i].longitude,
                lat: res.data.list[i].latitude,
                icon: 'marker',
                bindPopupHtml: '' +
                  '<div class="map-tip">' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>经纬度：' + res.data.list[i].longitude + ',' + res.data.list[i].latitude + '</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>地址：' + res.data.list[i].address + '</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>名称：' + res.data.list[i].name +'</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '</div>',
                click: 'showPointDetails',
                parameter: {id:res.data.list[i].id,type:type},
                keepBindPopup: false,
                isAggregation: false
              }
              that.markersList.push(markersMap)
            }
          }else{
            that.markersList = [];
          }
        }
        that.$refs.supermap.clearM(false);
        that.$refs.supermap.setMarkers(that.markersList);
      });
    },
    indentleftByDeptIdSetMarkers(deptId) {
      this.listCurrentIndex = deptId
      let that = this;
      let type = that.resourceTable;
      that.markersList = [];
      //点击右侧地图落点
      if(type=='hezuoshe'||type=='nongji'||type=='zhibao'||type=='xubao'||type=='yangzhi'){
        getFindAllZhanList(type,deptId).then(res => {
          if (res.data != null && res.data.length > 0) {
            for (let i = 0; i < res.data.length; i++) {
              let markersMap = {
                lng: res.data[i].longitude,
                lat: res.data[i].latitude,
                icon: 'marker',
                bindPopupHtml: '' +
                  '<div class="map-tip">' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>经纬度：' + res.data[i].longitude + ',' + res.data[i].latitude + '</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>地址：' + res.data[i].address + '</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '   <span>' +
                  '     <div class="d-l-con">' +
                  '       <div class="d-l-l-text">' +
                  '         <h4>名称：' + res.data[i].name +'</h4>' +
                  '       </div>' +
                  '     </div>' +
                  '   </span>' +
                  '</div>',
                click: 'showPointDetails',
                parameter: {id:res.data[i].id,type:type},
                keepBindPopup: false,
                isAggregation: false
              }
              that.markersList.push(markersMap)
            }
          }else{
            that.markersList = [];
          }
          that.$refs.supermap.clearM(false)
          that.$refs.supermap.setMarkers(that.markersList)
        })
      }
      that.$refs.supermap.clearM(false)
    }

  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import '@/assets/styles/base.scss';
</style>
