<template>
  <div class="boxxontent">
    <div class="title">
      <div><span>设备电量分析</span></div>
    </div>
    <div class="progress">
      <div class="sunmDevice">
        <Chart :cdata="cdata" />
      </div>
      <div class="datalist" v-if="showDom">
        <div class="datali" @click="jumpDevicePage(0,20)">
          <span>电量（0-20%）</span><span><NumberGrow :value="cdata.seriesData[0].value"></NumberGrow>个</span>
        </div>
        <div class="datali" @click="jumpDevicePage(20,40)">
          <span>电量（20%-40%）</span><span><NumberGrow :value="cdata.seriesData[1].value"></NumberGrow>个</span>
        </div>
        <div class="datali" @click="jumpDevicePage(40,60)">
          <span>电量（40%-60%）</span><span><NumberGrow :value="cdata.seriesData[2].value"></NumberGrow>个</span>
        </div>
        <div class="datali" @click="jumpDevicePage(60,80)">
          <span>电量（60%-80%）</span><span><NumberGrow :value="cdata.seriesData[3].value"></NumberGrow>个</span>
        </div>
        <div class="datali" @click="jumpDevicePage(80,100)">
          <span>电量（80%-100%）</span><span><NumberGrow :value="cdata.seriesData[4].value"></NumberGrow>个</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import Chart from './chart.vue'
  import moment from "moment"
  import {httpGetno} from "../../../../api/index.js"
  import NumberGrow from "../../NumberGrow.vue"
  export default {
    data() {
      return {
        showDom:true,
        timer:null,
        seriesData: {
          abnormalTotal: 0,
          batteryLevel1: 0,
          batteryLevel2: 0,
          batteryLevel3: 0,
          batteryLevel4: 0,
          batteryLevel5: 0,
          closeTotal: 0,
          offlineTotal: 0,
          onlineTotal: 0,
          openTotal: 0,
          projects: 0,
          total: 0
        },
        cdata: {
          datate: [0, 0, 0, 0, 0, 0, 0],
          seriesData: [{
              value: 0,
              name: '电量（0-20%）'
            },
            {
              value: 0,
              name: '电量（20%-40%）'
            },
            {
              value: 0,
              name: '电量（40%-60%）'
            },
            {
              value: 0,
              name: '电量（60%-80%）'
            },
            {
              value: 0,
              name: '电量（80%-100%）'
            }
          ],
        },
      };
    },
    components: {
      Chart,NumberGrow
    },
    created() {
      var seriesData = JSON.parse(localStorage.getItem('statisticsDate')).seriesData
      var cdata = this.cdata
      cdata.seriesData[0].value = seriesData.batteryLevel1//(parseInt(seriesData.batteryLevel1) / parseInt(seriesData.total) * 100).toFixed(2);
      cdata.seriesData[1].value = seriesData.batteryLevel2//(parseInt(seriesData.batteryLevel2) / parseInt(seriesData.total) * 100).toFixed(2);
      cdata.seriesData[2].value = seriesData.batteryLevel3//(parseInt(seriesData.batteryLevel3) / parseInt(seriesData.total) * 100).toFixed(2);
      cdata.seriesData[3].value = seriesData.batteryLevel4//(parseInt(seriesData.batteryLevel4) / parseInt(seriesData.total) * 100).toFixed(2);
      cdata.seriesData[4].value = seriesData.batteryLevel5//(parseInt(seriesData.batteryLevel5) / parseInt(seriesData.total) * 100).toFixed(2);
      this.cdata = cdata
      this.seriesData = seriesData
    },
    mounted() {
      var that=this
      this.timer=setInterval(function(){
        that.showDom=false
        that.setShow()
      },10000)
    },
    methods: {
      setShow(){
        this.$nextTick(()=>{
          this.showDom=true
        })
      },
      jumpDevicePage(startBattery,endBattery){
          this.$router.replace({
            path: '/allDevice',
            name:"allDevice",
            params: {
              startBattery:startBattery,
              endBattery:endBattery
            },
          });
      }
    },
    beforeRouteLeave(to, from, next) {
      clearInterval(this.timer)
      next()
    },
    beforeDestroy() {
      clearInterval(this.timer)
    },
  };
</script>

<style lang="scss" scoped>
  .boxxontent {
    margin: 0 20px;
    box-sizing: border-box;
  }

  .boxxontent .title {
    background: linear-gradient(to right, #042f89, transparent);
    padding: .4vw 1vw;
  }

  .boxxontent .title div {
    background: linear-gradient(to right, #007aff, #01cdf0 20%, #028ae1 80%);
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    font-size: 1vw;
    line-height: 1vw;
    font-weight: bold;
  }

  .progress {
    position: relative;
  }

  .progress>div {
    display: inline-block;
  }

  .progress .sunmDevice {
    width: 100%;
  }

  .progress .datalist {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    color: #fff;
  }

  .progress .datalist .datali {
    line-height: 1.2vw;
    font-size: .5vw;
    text-align: right;
    cursor: pointer;
  }

  .progress .datalist .datali>span:nth-child(2) {
    font-size: 1vw;
  }

  .progress .datalist .datali:nth-child(1)>span:nth-child(2) {
    color: #FF4C4C;
  }

  .progress .datalist .datali:nth-child(2)>span:nth-child(2) {
    color: #FF6383;
  }

  .progress .datalist .datali:nth-child(3)>span:nth-child(2) {
    color: #FF9933;
  }

  .progress .datalist .datali:nth-child(4)>span:nth-child(2) {
    color: #FFC635;
  }

  .progress .datalist .datali:nth-child(5)>span:nth-child(2) {
    color: #31DC72;
  }
</style>
