<template>
  <div>
    <div class="label">巡线</div>
    <div id="LineInspection"></div>
  </div>
</template>

<script>
  import co from 'co'
  import {HttpResetClass} from 'vue-client'

  let getData = function* (self) {
    let load = new HttpResetClass()
    load.load("POST", 'rs/sql/singleTableParam',
      {data: self.sqlcondition},
      {resolveMsg: null, rejectMsg: null})
      .then((res) => {
      })
  }

  export default {
    name: "LineInspection",
    data() {
      return {
        xc: '',
        usernum: [
          {value: 2000, name: '已完成'},
          {value: 1215, name: '未完成'},
        ],
        totaluser: '',
      }
    },
    methods: {
      setBar() {
        this.xc = this.$echarts.init(document.getElementById('LineInspection'))
        var scale = 0.8;
        let echartData = this.usernum
        var rich = {
          yellow: {
            color: "#ffc72b",
            fontSize: 10 * scale,
            padding: [5, 4],
            align: 'center'
          },
          total: {
            color: "#ffc72b",
            fontSize: 10 * scale,
            align: 'center'
          },
          white: {
            color: "#fff",
            align: 'center',
            fontSize: 12 * scale,
            padding: [4, 0]
          },
          blue: {
            color: '#e1e52a',
            fontSize: 12 * scale,
            align: 'center',
            padding: [6, 0]
          },
          hr: {
            borderColor: '#64d8d4',
            width: '100%',
            borderWidth: 0.5,
            height: 0
          },
        }
        var total = 0; //用户总和
        echartData.forEach(function (value) {
          total += value.value;
        });
        this.xc.setOption({
          title: [{
            left:'35%',
            text:'总巡线',
            textStyle:{
              color:'#fff',
              fontSize:16*scale,
            },
            bottom:'30%',
          },{
            text:total,
            left:'50%',
            textStyle:{
              color:'#e1e52a',
              fontSize:16*scale
            },
            bottom:'30%',
          }],
          legend: {
            orient: 'vertical',
            icon: 'circle',
            x:'70%',
            bottom:'2%',
            itemWidth: 20 * scale,
            itemHeight: 10 * scale,
            textStyle: {
              fontSize: 12 * scale,
              padding: [0, 0, 0, 4 * scale],
              color: '#ffffff'
            },
            data: ['已完成', '未完成']
          },
          grid: {
            left: '35%',
            right: '35%',
            top: '0',
            bottom: '0'
          },
          series: [
            {
              name: 'Line 1',
              type: 'pie',
              animation: false,
              clockWise: false,
              radius: ['15%', '16%'],
              center: ['50%', '35%'],
              itemStyle: {
                normal: {
                  label: {
                    show: false
                  },
                  labelLine: {
                    show: false
                  },
                }
              },
              hoverAnimation: false,
              tooltip: {
                show: false
              },
              data: [{
                value: 100,
                name: '02',
                itemStyle: {
                  normal: {
                    color: '#29b7ff',//未完成的圆环的颜色
                    label: {
                      show: false
                    },
                    labelLine: {
                      show: false
                    }
                  }
                }
              }]
            },
            {
              name: '总用户数',
              type: 'pie',
              radius: ['20%', '30%'],
              center: ['50%', '35%'],
              minAngle: 15,//最小角度
              startAngle: 300, //起始角度
              hoverAnimation: false,
              color: ['#6fd9d0', '#ede61f'],
              label: {
                normal: {
                  borderWidth: 1,
                  borderRadius: 4,
                  backgroundColor:'#004b5c',
                  borderColor:'#64d8d4',
                  formatter: function (params, ticket, callback) {
                    var total = 0; //用户总数量
                    var percent = 0;
                    echartData.forEach(function (value, index, array) {
                      total += value.value;
                    });
                    percent = ((params.value / total) * 100).toFixed(1);
                    return '{white|' + params.name + '}\n{hr|}\n{blue|  ' + params.value + '}{blue|   ' + percent + '%}';
                  },
                  rich: rich,
                }
              },
              labelLine: {
                normal: {
                  length: 10 ,
                  length2: 12 ,
                }
              },
              data: echartData
            },
            {
              name: 'Line 2',
              type: 'pie',
              animation: false,
              clockWise: false,
              radius: ['35%', '36%'],
              center: ['50%', '35%'],
              itemStyle: {
                normal: {
                  label: {
                    show: false
                  },
                  labelLine: {
                    show: false
                  },
                }
              },
              hoverAnimation: false,
              tooltip: {
                show: false
              },
              data: [{
                value: 100,
                name: '02',
                itemStyle: {
                  normal: {
                    color: '#29b7ff',//未完成的圆环的颜色
                    label: {
                      show: false
                    },
                    labelLine: {
                      show: false
                    }
                  }
                }
              }
              ]
            }
          ]
        }, true)
      },
      dataunit(value) {
        var index = value.toString().length
        if (index > 5) {
          var i = value.toString().substring(0, index - 4)
          var s = value.toString().substring(index - 4, index - 3)
          this.totaluser = i + '.' + s + '万'
        }
      },
    },
    watch: {
      'usernum'(val) {
        var value = this.usernum[0].value + this.usernum[1].value + this.usernum[2].value
        this.dataunit(value)
        this.setBar()
      }
    },
    ready() {
      var items = '(aa.qq-cc.ee) 民用, bb.ww 非民用, cc.ee 民用锅炉'
      var tablename = '(select count(f_userinfo_id) qq from t_userinfo where f_user_type=\'民用\') aa,\n' +
        '\n' +
        '(select count(f_user_type) ww from t_userinfo where f_user_type=\'非民用\') bb,\n' +
        '\n' +
        '(select count(b.f_userinfo_id) ee from T_USERINFO a, T_DEVICES b where a.F_USERINFO_ID=b.f_userinfo_id and F_DEVICES_TYPE=\'壁挂炉\' and a.f_user_type=\'民用\') cc'
      var condition = "1=1"
      this.sqlcondition = {items: items, tablename: tablename, condition: condition}
      this.setBar()
    }
  }
</script>

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