<!--
 * @Description: 供应专题
 * @Author: 王晓颖
 * @Date: 2021-04-14
 -->
<template>
  <layout-map>
    <!--统计结果显示-->
    <div v-show="boardData.name" class="label-container">
      <div class="label-div">
        <div class="label">
          {{ boardData.name }}实时供给
        </div>
        <div class="value">
          {{ boardData.value }}<span class="unit"><span v-show="boardData.type=='area'">万</span>m³</span>
        </div>
      </div>
      <div>
        <div class="label-div-small-parent">
          <div class="label-div-small">
            <div class="label">
              LNG
            </div>
            <div class="value">
              {{ boardData.lng }}<span class="unit"><span v-show="boardData.type=='area'">万</span>m³</span>
            </div>
          </div>
          <div class="label-div-small">
            <div class="label">
              PNG
            </div>
            <div class="value">
              {{ boardData.png }}<span class="unit"><span v-show="boardData.type=='area'">万</span>m³</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!--地图-->
    <Map :url="configUrl" @onload="onMapload" >
      <supply-layer-cone ref="supply" :show="supplyShow" @click="clickSupply"/>
      <vip-layer ref="vip" :show="vipShow" popup-type="other" show-value="supply" @click="clickVip"/>
    </Map>
    <div class="map-btn-group">
      <select-button :select="supplyShow" name="供应" icon="icon-supply" @click="supplyShow=!supplyShow"/>
      <select-button :select="vipShow" name="重点用户" icon="icon-user" @click="vipShow=!vipShow"/>
    </div>

  </layout-map>
</template>

<script>
import 'mars3d-echarts'
import Map from '@/components/Map/MarsMap.vue'
import SelectButton from '@/components/SelectTool/components/selectButton'
import LayoutMap from '@/layout/layoutMap'
import SupplyLayerCone from '@/components/Map/components/supplyLayerCone'
import VipLayer from '@/components/Map/components/vipLayer'
export default {
  name: 'SupplyTopic',
  components: {
    VipLayer,
    SupplyLayerCone,
    LayoutMap,
    SelectButton,
    Map
  },
  filters: {
    boardNameFilter(val) {
      if (val === '全部' || val === '') {
        return '全省重点用户'
      } else {
        return val + '区域重点用户'
      }
    }
  },

  data() {
    return {
      map: null, // 地图
      configUrl: 'static/config/config.json',
      alpha: 100, // 透明度
      underground: null, // ？
      pointColorArr: ['#f33349', '#f79a2c', '#95e40c', '#95e40c', '#1ffee6'],
      vipShow: false, // 显示位置
      supplyShow: true, // 显示供应
      boardData: {
        type: '', // area or vip
        name: '',
        value: '',
        lng: '',
        png: ''
      }, // 统计版展示数据
      citiesPositions: {
        '太原市': { 'x': 112.549248, 'y': 37.857014 },
        '大同市': { 'x': 113.295258, 'y': 40.090309 },
        '阳泉市': { 'x': 113.583282, 'y': 37.861187 },
        '晋中市': { 'x': 113.290072, 'y': 37.388188 },
        '长治市': { 'x': 113.113556, 'y': 36.191113 },
        '晋城市': { 'x': 112.851273, 'y': 35.497555 },
        '临汾市': { 'x': 111.517975, 'y': 36.084148 },
        '运城市': { 'x': 111.00396, 'y': 35.022778 },
        '朔州市': { 'x': 112.433388, 'y': 39.331261 },
        '忻州市': { 'x': 112.733536, 'y': 38.41769 },
        '吕梁市': { 'x': 111.134338, 'y': 37.524364 }
      },
      cities: [],
      vipList: [], // 重点用户点位
      vipLayer: null, // 重点用户分布图层
      supplyLayer: null, // 供应光锥图层
      graphicLayer: null, // 管理站标签图层
      timer: null, // 轮训定时器
      clock: 86400 // 间隔时间
    }
  },
  methods: {
    // 地图构造完成回调
    onMapload(map) {
      // 以下为演示代码
      this.map = map
      // 背景透明
      this.map._viewer.scene.backgroundColor = new this.Cesium.Color(0.0, 0.0, 0.0, 0.0)
      this.map._viewer.scene.globe.baseColor.alpha = 0
      this.refreshData()
    },
    clickSupply(event) {
      const item = event.graphic.attr
      this.boardData.type = 'area'
      this.boardData.name = item.name
      this.boardData.value = item.supply.toFixed(2)
      this.boardData.lng = item.lngSupply.toFixed(2)
      this.boardData.png = item.pngSupply.toFixed(2)
    },
    clickVip(event) {
      const item = event.graphic.attr
      this.boardData.type = 'vip'
      this.boardData.name = item.name
      this.boardData.value = item.supply
      this.boardData.lng = item.lngSupply
      this.boardData.png = item.pngSupply
    },
    // 显示供应
    showSupply(show) {
      this.supplyShow = !this.supplyShow
      if ((!this.supplyShow) && this.boardData.type === 'area') {
        this.clearBoardData()
      }
    },
    // 显示重点用户分布和供应
    showVip(show) {
      this.vipShow = !this.vipShow
      if ((!this.vipShow) && this.boardData.type === 'area') {
        this.clearBoardData()
      }
    },
    clearBoardData() {
      this.boardData = {
        type: '', // area or vip
        name: '',
        value: '',
        lng: '',
        png: ''
      }
    },
    // 打开轮询,定时刷新数据
    refreshData() {
      console.log(this.clock * 1000)
      this.timer = setInterval(() => {
        console.log('refreshData')
        if (this.supplyShow) { // 如果供需图层不为空，刷新工薪数据
          this.$refs.supply.initLayer()
        }
        if (this.vipShow) {
          this.$refs.vip.initLayer()
        }
      }, this.clock * 1000)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .label-container {
    position: absolute;
    top: 140px;
    left: 31rem;
    z-index: 100;
    .label-div {
      color: white;
      padding: 1.5rem 2.2rem 1rem 2.2rem;
      background-image: url("../../assets/button_images/board-box1.png");
      background-size: 100% 100%;
      margin-bottom: 20px;
      .label {
        margin-bottom: 0.8rem;
        font-size: 1rem;
      }
      .value {
        font-family: DS-DigitalBold;
        font-size: 2rem;

      }
      .unit{
        font-family: "Microsoft YaHei";
        font-size:1rem;
      }
    }
    .label-div-small-parent{
      display: flex;
      justify-content: start;
      .label-div-small {
        /*flex:1;*/
        color: white;
        padding: 1rem 2rem 1rem 2rem;
        background-image: url("../../assets/button_images/board-box1.png");
        background-size: 100% 100%;
        margin-bottom: 20px;
        .label {
          margin-bottom: 0.2rem;
          font-size: 1rem;
        }
        .value {
          font-family: DS-DigitalBold;
          font-size: 2rem;
          display: inline-block;
        }
        .unit{
          font-family: "Microsoft YaHei";
          font-size:1rem;
        }
      }
    }
  }
  .map-btn-group{
    position: absolute;
    bottom:3rem;
    left:50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
  }
</style>

<style rel="stylesheet/scss" lang="scss">
  /*整个容器*/
  .mapcontainer {
    position: relative;
    height: 100%;
    width: 100%;
    background-color: transparent;
    /*background-color: #051151;*/
  }

</style>
