<template>
  <div class="cq">
    <div class="cq__title">出勤情况</div>
    <div class="water-level-chart-details">
      总人数<span>{{totalPerson}}</span>人
      ,出勤率<span>100%</span>
    </div>
    <div class="chart-container">
      <dv-active-ring-chart v-if="show" :config="config" />
    </div>
  </div>
</template>

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

export default {
  name:'Cq',
  data () {
    return {
      show:false,
      totalPerson:0,
      config: {
        radius: '60%',
        activeRadius: '63%',
        data: [],
        digitalFlopStyle: {
          fontSize: 20
        }
      },
      delay:null,
    }
  },
  mounted() {
    // this.$socket.open()
    // this.wsSubscribe()
  },
  created(){
    this.getData();
    this.delay=setInterval(this.getData,30000)
  },
  sockets:{},
  methods:{
    getData(){
      getKqData().then(res=>{
        this.show=false
        const data=[]
        this.totalPerson=0
        const keySize=Object.keys(res.data).length
        Object.keys(res.data).forEach(key=>{
          if (key==='total'){
            this.totalPerson=res.data[key]
            if (keySize===1){
              const item=res.data[key]
              data.push({name:'总人数',value:item})
            }
            return
          }
          if (key==='rows'){
            const item=res.data[key]
            const 白班人数=item.filter(item=>item.zt==='01').length
            const 二班人数=item.filter(item=>item.zt==='02').length
            data.push({name:'白班',value:白班人数})
            data.push({name:'二班',value:二班人数})
            return
          }
          const item=res.data[key]
          data.push({name:key,value:item})
        })
        this.config.data=data
        this.show=true
      })
    },
    clear(){
      clearInterval(this.delay)
    }
  }
}
</script>

<style scoped>
.cq{
  width: 369px;
  height: 294px;
  background: url('../../../assets/kban/cqbg.png') no-repeat;
  background-size: 100% 100%;
  margin-left: 62px;
  margin-top: 14px;
  text-align: center;

  .cq__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: 71px;
  }

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

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

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

  .dv-active-ring-chart {
    width: 300px;
    height: 300px;
    margin-top: -40px;

    ellipse {
      stroke: transparent !important;
    }

    text {
      font-size: 40px;
    }
  }
}
</style>