<template>
  <div class="ycl">
    <div class="ycl__title">本月计划完成情况</div>
    <div class="water-level-chart-details">
      累计完成<span>{{dun}}</span>吨
    </div>
    <div class="chart-container">
      <dv-water-level-pond v-if="show" :config="config" />
    </div>
  </div>
</template>

<script>
import {getJhwcqk} from "@/api/kban";

export default {
  name:'MainYueChanLiang',
  data () {
    return {
      show:false,
      dun:0,
      config: {
        data: [0],
        shape: 'round',
        waveHeight: 25,
        waveNum: 2
      },
      delay:null,
    }
  },
  mounted() {
    // this.$socket.open()
    // this.wsSubscribe()
  },
  created(){
    this.getData();
    this.delay=setInterval(this.getData,30000)
  },
  sockets:{},
  methods:{
    getData(){
      getJhwcqk().then(res=>{
        console.log(res.data)
        this.show=false
        let total=0
        for (const item of res.data) {
          if (item.zt==='62'){
            this.dun=item.t.toFixed(2)
          }
          total+=item.t||0
        }
        const point=(this.dun/total*100).toFixed(2)
        console.log(point)
        this.config.data[0]=point
        this.show=true
      })
    },
    clear(){
      console.log("本月计划完成情况停止加载数据")
      clearInterval(this.delay)
    }
  }
}
</script>

<style scoped>
.ycl{
  width: 400px;
  height: 378px;
  background: url('../../../assets/kban/yclbg.png') no-repeat;
  background-size: 100% 100%;
  text-align: center;

  border-top: 2px solid rgba(1, 153, 209, .5);
  display: flex;
  flex-direction: column;

  .water-level-chart-title {
    font-weight: bold;
    height: 50px;
    display: flex;
    align-items: center;
    font-size: 20px;
    justify-content: center;
  }

  .water-level-chart-details {
    height: 15%;
    display: flex;
    justify-content: center;
    font-size: 17px;
    align-items: flex-end;

    span {
      font-size: 35px;
      font-weight: bold;
      color: #58a1ff;
      margin: 0 5px;
      margin-bottom: -5px;
    }
  }

  .chart-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .dv-water-pond-level {
    max-width: 90%;
    width: 240px;
    height: 240px;
    border: 10px solid #19c3eb;
    border-radius: 50%;

    ellipse {
      stroke: transparent !important;
    }

    text {
      font-size: 40px;
    }
  }

  .ycl__title{
    width: 231px;
    height: 41px;
    background: url('../../../assets/kban/cltitle.png') no-repeat;
    background-size: 100% 100%;
    font-weight: bold;
    font-size: 20px;
    padding: 12px 26px;
    margin-left: 85px;
  }
}
</style>

