<template>
  <div id="bottomRight">
    <div class="bg-color-black">
      <div class="d-flex pt-2">
        <div class="title">
           <span>
             <SvgIcon class="text-icon" icon-class="skill"></SvgIcon>
           </span>
          <span class="fs-xl text mx-2">资产数据</span>
        </div>
        <div class="d-flex">
          <div class="decoration2">
            <dv-decoration-2 :reverse="true" style="position:absolute;width:5px;height:6rem;" />
          </div>
        </div>
      </div>
      <div>
        <Chart :cdata="cdata" />
      </div>
    </div>
  </div>
</template>

<script>
import SvgIcon from "@/components/SvgIcon"
import Chart from "@/components/Charts"
export default {
  components: {
    SvgIcon,
    Chart
  },
  data () {
    return {
      drawTiming: null,
      cdata: {
        year: null,
        weekCategory: [],
        radarData: [],
        radarDataAvg: [],
        maxData: 12000,
        weekMaxData: [],
        weekLineData: []
      }
    }
  },
  mounted () {
    this.drawTimingFn();
  },
  beforeDestroy () {
    clearInterval(this.drawTiming);
  },
  methods: {
    drawTimingFn () {
      this.setData();
      this.drawTiming = setInterval(() => {
        this.setData();
      }, 6000);
    },
    setData () {
      let myAsset,assets;
      if (this.assetsList instanceof Array) {
        assets = this.assetsList.filter(i => !!(i.jiaotong || i.jiaoyu || i.shangquan || i.shushidu))
        myAsset = assets[Math.floor(Math.random() * assets.length)];
      }
      // if (this.leaseList instanceof Array) {
      //   console.log(this.leaseList)
      //   myLease = this.leaseList[Math.floor(Math.random() * this.leaseList.length)];
      //   console.log(myLease)
      // }
      // 清空轮询数据
      this.cdata.asset = myAsset??{};
      this.cdata.lease = myAsset ? myAsset["id_leases_land_id_relation"] : [];
      this.cdata.radarData = myAsset ? [myAsset.jiaotong, myAsset.jiaoyu, myAsset.shangquan, myAsset.shushidu] : [];
      this.cdata.radarDataAvg = assets ?
        [
          assets.reduce((a,b) => (a + Number(b.jiaotong??0)),0)/assets.length,
          assets.reduce((a,b) => (a + Number(b.jiaoyu??0)),0)/assets.length,
          assets.reduce((a,b) => (a + Number(b.shangquan??0)),0)/assets.length,
          assets.reduce((a,b) => (a + Number(b.shushidu??0)),0)/assets.length
        ] :
        [0, 0, 0, 0];
    }
  },
  computed: {
    assetsList () {
      return this.$store.state.bigdata.assets[1]
    },
    leaseList () {
      return this.$store.state.bigdata.leases
    }
  }
};
</script>

<style scoped lang="scss">
#bottomRight {
  padding: 20px 10px;
}
.title {
  display: flex;
  color: #fff;
  padding: 0 20px;
  align-items: center;
  .text {
    padding: 0 8px;
  }
}
.text-icon {
  width: 24px;
  height: 24px;
  color: #1da4a1;
}
</style>
