<style scoped>

</style>
<template>
  <div>
    <span class="title-1">分公司年度购进量</span>
    <div class="text-1">
      <div id="textchildsellgas"></div>
    </div>
    <img class="img-bottom" src="../../../../static/NewManageHome/1.gif" />
  </div>
</template>

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


  export default {
    name: "TextChildsellgas",
    props: {
      showdate: {
        type: Boolean,
        default: false
      },
      listenheight: String,
    },
    data() {
      return {
        date: [2018, 2017, 2016],
        xc: '',
        warn: '',
        suspicious: '',
        resdata: '',
        monitordata: [],
        monitordata1: [],
        monitorscale: [],
        grade: ['汉投', '城然', '安康', '商洛'],
      }
    },
    methods: {
      setBar() {
        this.xc = this.$echarts.init(document.getElementById('textchildsellgas'))
        var scale=this.$parent.$parent.scale*1.2
        var data = {
          grade: this.grade,
          visits: [1000,1080,1380,1200],
          totalCost: [1380,1380, 1380, 1380],
          cost: this.monitorscale,
        }
        var rich = {
          blue: {
            fontSize:18*scale,
            color: '#15dce2'
          },
          white: {
            color: '#fff'
          }
        }
        this.xc.setOption({

          grid: {
            left: '15%',
            right: '15%',
            top: '8%',
            bottom: '0'
          },
          xAxis: {
            show: false,
          },
          yAxis: {
            type: 'category',
            axisLabel: {
              margin: 10 * scale,
              show: true,
              color: '#95bad7',
              fontSize: 12 * scale
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            data: data.grade
          },
          series: [{
            type: 'bar',
            barGap: '-100%',
            label: {
              normal: {
                show: true,
                position: 'right',
                fontSize: 18*scale,
                formatter:
                  function (param) {
                    return '{blue|' + data.visits[param.dataIndex] + ' 万}';
                  },
                rich: rich,
              }
            },
            barWidth: '30%',
            itemStyle: {
              normal: {
                // borderColor: 'rgba(1,207,242,0.05)',
                borderWidth: 2,
                barBorderRadius: 15*scale,
                color: '#003d4c'
              }
            },
            z: 1,
            data:  data.totalCost,
            // data: da
          }, {
            type: 'bar',
            barGap: '-99%',
            barWidth: '30%',
            itemStyle: {
              normal: {
                barBorderRadius: 16 * scale,
                color: {
                  type: 'linear',
                  x: 0,
                  x1: 1,
                  colorStops: [{
                    offset: 0,
                    color: '#6fd9d0'
                  }, {
                    offset: 1,
                    color: '#6fd9d0'
                  }]
                }
              },
            },
            label:{
              formatter:function (param) {
                console.log(param,'cdd')
              }
            },
            max: 1,
            labelLine: {
              show: true,
            },
            z: 2,
            data:  data.visits,
          }]
        })
      },
      searchdata() {
        let warndata = DataSql.getData(this,'warningcount',{}, 'resdata')
        co(warndata)
        let sqldata = DataSql.getData(this, 'monitor',{}, 'monitordata')
        co(sqldata)
      },
      scale() {
        var l = this.monitordata1[1]
        for (var i = 1; i < 5; i++) {
          l = l + this.monitordata1[i + 1]
          if (l < this.monitordata1[i + 1]) {
            l = this.monitordata1[i + 1]
          }
        }
        l = l * 1.3
        for (var i = 1; i < 6; i++) {
          if (this.monitordata1[i] == 0 || l == 0) {
            this.monitorscale[i] = 0
            continue
          }
          this.monitorscale[i] = this.monitordata1[i] / l
        }
        this.monitorscale[0] = 0
      },
    },
    watch: {
      'resdata': {
        deep: true,
        handler(val) {
          this.warn = this.resdata[0].warn
          this.suspicious = this.resdata[0].suspicious
          this.$parent.loaddata++
        }
      },
      'monitordata': {
        deep: true,
        handler(val) {
          let s = []
          for (var i = 1; i < 6; i++) {
            s[i] = this.monitordata[0][this.grade[i]]
          }
          this.monitordata1 = s
          // this.scale()
          this.setBar()
          this.$parent.loaddata++
        }
      },
    },
    ready() {
      this.setBar()
      // this.searchdata()
    }
  }
</script>

<style scoped>

</style>
