<template>
  <div id="smartDatav">
    <dv-full-screen-container class="bg">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body" style="width: 100%;height: 100%;">
        <headBtn></headBtn>
        <div class="d-flex jc-center">
          <dv-decoration-10 style="width:33.3%;height:.0625rem;" />
          <div class="d-flex jc-center">
            <dv-decoration-8 :color="['#568aea', '#000000']" style="width:2.5rem;height:.625rem;" />
            <div class="title">
              <span class="title-text">学府中央</span>
              <dv-decoration-6
                class="title-bototm"
                :reverse="true"
                :color="['#50e3c2', '#67a1e5']"
                style="width:3.125rem;height:.1rem;"
              />
            </div>
            <dv-decoration-8
              :reverse="true"
              :color="['#568aea', '#000000']"
              style="width:2.5rem;height:.625rem;"
            />
          </div>
          <dv-decoration-10 style="width:33.3%;height:.0625rem; transform: rotateY(180deg);" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex" style="width: 40%">
            <div
              class="react-right ml-4"
              style="width: 6.25rem; text-align: left;background-color: #0f1325;"
            >
              <!-- <span class="react-before"></span>
              <span class="text">数据概况</span> -->
            </div>
            <div class="react-right ml-3" style="background-color: #0f1325;" >
              <!-- <span class="text colorBlue">数据分析11</span> -->
            </div>
          </div>
          <div style="width: 40%" class="d-flex">
            <div class="react-left mr-3" style="background-color: #0f1325;">
              <!-- <span class="text fw-b">小区数据</span> -->
            </div>
            <div
              class="react-left mr-4"
              style="width: 6.25rem; background-color: #0f1325; text-align: right;"
            >
              <span class="react-after"></span>
              <span class="text">{{dateYear}} {{dateWeek}} {{dateDay}}</span>
            </div>
          </div>
        </div>
        <div class="d-flex" style="width: 100%;">
          <div style="width: 40%;">
            <dv-border-box-7 :color="['rgba(0,0,0,0)','#07fcfd']" backgroundColor="rgba(29,89,159,.1)">
              <left1></left1>
              <left2></left2>
              <left3></left3>
            </dv-border-box-7>
          </div>
          <div style="width: 60%;">
            <mapCmp mapStyle="amap://styles/darkblue" mapIndex="2" zoom="18" :agencies="agencies" ></mapCmp>
            <!-- <dv-border-box-7 :color="['rgba(0,0,0,0)','#07fcfd']" backgroundColor="rgba(29,89,159,.1)">
              <div style="padding: 0 .5rem;box-sizing: border-box;width: 100%;height: 12rem;">
                <video id="VideoID" src="./assets/map_bt1.mp4" autoplay loop muted style="width: 70%;height: 100%;position: absolute;bottom: -16%;height: 80%;left: 50%;transform: translateX(-50%);"></video>
                <mapCmp :data="mapData" :orgInfo="orgInfo" @onRequest="onRequest"></mapCmp>
                <mapDeviceMenu :smartDeviceData="smartDeviceData.data" @reqDeviceCount="reqDeviceCount"></mapDeviceMenu>
              </div>
            </dv-border-box-7> -->
          </div>
          <div style="width: 40%;">
            <dv-border-box-7 :color="['rgba(0,0,0,0)','#07fcfd']" backgroundColor="rgba(29,89,159,.1)">
              <right1></right1>
              <right2></right2>
            </dv-border-box-7>
          </div>
        </div>
      </div>
    </dv-full-screen-container>
  </div>
</template>

<script>
import { formatTime } from './utils/index.js'
import headBtn from "./components/headBtn.vue"
import left1 from "./components/operateCmp/left-1.vue"
import left2 from "./components/operateCmp/left-2.vue"
import left3 from "./components/operateCmp/left-3.vue"
import right1 from "./components/operateCmp/right-1.vue"
import right2 from "./components/operateCmp/right-2.vue"
// import mapCmp from './components/geoMap.vue'
import mapCmp from './components/map.vue'
import mapDeviceMenu from "./components/mapDeviceMenu.vue";
import {getCommunityList,getMultiCount,getDeviceCount} from "../../api/grid/index"
  import {
    mapGetters,
    mapState
  } from "vuex";
export default {
  data () {
    return {
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
      mapData:[],
      adCode:'',
      deviceType:'',
      smartDeviceData:{
        data:[],
      },
      deviceList:[],
      communityData:null,
      orgInfo:'',
      agencies:{longitude:'106.127358',latitude:'38.497988'}
    };
  },
  components: {
    headBtn,
    left1,
    left2,
    left3,
    right1,
    right2,
    mapCmp,
    mapDeviceMenu,
  },
  computed: {
    ...mapGetters([
      "orgInfo"
    ])
  },
  mounted () {
    this.orgInfo = this.$store.getters.orgInfo
    this.timeFn();
    this.onRequest()
  },
  methods: {
    onRequest(adCode){
      if(adCode){
        this.adCode = adCode
      }else{
        this.adCode = this.orgInfo.orgPosition
      }
      let collect  = [];
      var _this = this;
      collect.push(this.getCommunityDataList(this.adCode))
      collect.push(this.reqDeviceCount(this.deviceType,this.adCode))
        axios.all(collect)
            .then(
              axios.spread(() => {
                _this.mapData.length = 0
                _this.mapData.push(_this.deviceList)
                _this.mapData.push(_this.communityData)
              })
            )
            .catch(err => {

            });
    },
    reqDeviceCount(type,params){
      var _this = this;
      this.deviceType = type;
      return getDeviceCount(type,_this.adCode).then((res)=>{
        let data = res.data.data;
         _this.smartDeviceData.data.length = 0;
       if(data.singleTypeSmartDeviceVOList.length>0){
         data.singleTypeSmartDeviceVOList.map((item)=>{
           let obj = {}
           obj["name"] = item.deviceTypeName
           obj['value'] = item.deviceCount
           obj['deviceType'] = item.deviceType
           _this.smartDeviceData.data.push(obj)
           _this.$set(_this.smartDeviceData)
         })
       }
       _this.deviceList.length = 0;
       if(data.smartDeviceList.length>0){
         _this.deviceList = data.smartDeviceList;
       }
      })
    },
    getCommunityDataList(params){
      var _this = this;
      return getCommunityList(params).then((res)=>{
        _this.loading = false;
        _this.communityData = res.data.data;
      }).catch((err)=>{
        console.log(err)
      })
    },
    jump(v){

    },
    timeFn () {
      setInterval(() => {
        this.dateDay = formatTime(new Date(), 'HH: mm: ss');
        this.dateYear = formatTime(new Date(), 'yyyy-MM-dd');
        this.dateWeek = this.weekday[new Date().getDay()];
      }, 1000)
    },

  }
};
</script>

<style lang="scss">
@import './assets/scss/index.scss';
</style>
