<template>
  <div>
    <div class="label">安检</div>
    <div class="f2">
      <div id="unfinished" class="he1"></div>
      <div id="untreated" class="he1"></div>
    </div>
    <div class="f1">
      <table>
        <tr>
          <td class="td1"><img src="../../../../static/ManageHomePic/图层11.png"></td>
          <td>安检总户数<br/><span class="s1">{{totalstring}}</span></td>
        </tr>
        <tr>
          <td class="td1"><img src="../../../../static/ManageHomePic/图层1343.png"></td>
          <td>正常户数<br/><span class="s2">{{normaluser}}</span></td>
        </tr>
        <tr>
          <td class="td1"><img src="../../../../static/ManageHomePic/椭圆8拷贝6.png"></td>
          <td>隐患户数<br/><span class="s3">{{hiddenuser}}</span></td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
  import * as DataSql from '../../../stores/DataSql'
  import co from 'co'

  export default {
    name: "PlanStatistics",
    data() {
      return {
        resdata: [],
        resdata1: [],
        totalstring: '',
        normaluser: '',
        hiddenuser: '',
        safedata: [{value: 0, name: '已完成'}, {value: 0, name: '未完成'}],
        safedatastring: [{value: "", name: '已完成'}, {value: "", name: '未完成'}],
        safeerrordata: [],
      }
    },
    methods: {
      setBar(id, iddata) {
        var self = this
        this.xc = this.$echarts.init(document.getElementById(id))
        var scale = 0.8
        var color = ["#e7c83c", "#2f3f2b"]
        var center = [66, 82]
        var startAngle=90
        if (id == 'untreated') {
          color = ["#69d8d2", "#013e48"]
          center = [66, 82]
          startAngle=0
        }
        this.xc.setOption({
          color: color,
          series: [
            {
              name: 'demo',
              type: 'pie',
              center: ['50%', '40%'],
              radius: ['25%', '40%'],
              minAngle: 15,//最小角度
              startAngle: startAngle, //起始角度
              avoidLabelOverlap: false,
              hoverAnimation: false,
              label: {
                normal: {
                  formatter: function (params, ticket, callback) {
                    if (id == 'unfinished') {
                      for (var i = 0; i < self.safedatastring.length; i++) {
                        if (self.safedatastring[i].name == params.name) {
                          return '{a|' + params.name + '}{a|' + self.safedatastring[i].value + '}\n';
                        }
                      }
                    }
                    return '{b|' + params.name + '}{b|' + params.value + '}\n';
                  },
                  borderWidth: 20 * scale,
                  borderRadius: 4 * scale,
                  padding: [0, -88 * scale],
                  rich: {
                    a: {
                      color: '#f3c832',
                      fontSize: 12 * scale,
                    },
                    b: {
                      fontSize: 12 * scale,
                      color: '#6fd9d0'
                    }
                  }
                }
              },
              labelLine: {
                normal: {
                  length: 10 * scale,
                  length2: 90 * scale,
                  lineStyle: {
                    color: color[0]
                  }
                }
              },
              data: iddata
            }
          ]
        })
      },
    },
    watch: {
      // 安检数据返回
      'resdata': {
        deep: true,
        handler(val) {
          if (typeof this.resdata[0].totalsafe !== "undefined") {
            this.safedata[0].value = this.resdata[0].complete
            this.safedata[1].value = this.resdata[0].undone
            DataSql.dataunitarray(this, 'safedata', 'safedatastring')
            this.setBar('unfinished', this.safedata)
            this.totalstring = DataSql.dataunit(this.resdata[0].totalsafe)
            if(this.safeerrordata.length>0){
              var self=this
              this.safeerrordata.forEach(function (s) {
                if(s.name=='隐患数'){
                  self.hiddenuser=s.value
                }
              })
              var usernum=this.resdata[0].totalsafe
              this.normaluser = DataSql.dataunit(usernum)
            }
            this.$parent.loaddata++
          }
        },
      },
      // 隐患数据返回
      'resdata1': {
        deep: true,
        handler(val) {
            this.safeerrordata=this.resdata1
          console.log(this.safeerrordata,'测试隐患数据')
            this.setBar('untreated', this.safeerrordata)
          if(this.resdata.length>0){
              var self=this
              this.resdata1.forEach(function (s) {
                if(s.name=='隐患数'){
                  self.hiddenuser=s.value
                }
              })
               var usernum=this.resdata[0].totalsafe
            this.normaluser = DataSql.dataunit(usernum)
          }
          this.$parent.loaddata++
        },
      },
    },
    ready() {

      let getdata = DataSql.getData(this,'noplancheck',{}, 'resdata')
      co(getdata)
      let getdata1 = DataSql.getData(this,'hiddennum',{}, 'resdata1')
      co(getdata1)

    }
  }
</script>

<style scoped>
  .label {
    margin-left: 6%;
    font-size: 0.85em;
    float: left;
    color: #fff;
    height: 8%;
    width: 100%;
    text-align: left;
  }

  table {
    width: 100%;
    height: 100%;
  }

  td {
    height: 30%;
    color: #ffffff;
    font-size: 0.85em;
  }

  .td1 {
    width: 40%;

  }

  .f1 {
    padding: 0% 0% 0% 5%;
    height: 90%;
    width: 40%;
    float: left;
  }

  .f2 {
    height: 90%;
    width: 60%;
    float: right;
  }

  .s1 {
    color: #f3c832;
    font-size: 1.35em;
  }

  .s2 {
    color: #5d89e4;
    font-size: 1.35em;
  }

  .s3 {
    color: #05c3c7;
    font-size: 1.35em;
  }

  img {
    width: 80%;
  }

  .he1 {
    height: 50%;
  }
</style>
