<template lang="html">
  <div id="charts">
    <div id="BusinessHall" :style="{width:'100%',height:'100%'}"></div>
  </div>
</template>

<script>
  import * as Util from '../../Util'
  import * as Des from '../../stores/DrillECharts'
  import co from 'co'
  import {HttpResetClass} from 'vue-client'

  export default {
    name: 'BusinessHall',
    props: {
      startdate: {
        type: String,
        default: Util.toStandardDateString()
      },
      enddate: {
        type: String,
        default: Util.toStandardDateString()
      },
      f_orgstr: {
        type: String,
        default: ''
      },
    },
    data() {
      title: '站点管理'
      return {
        texttile: '',
        xc: '',
        sqlobtaindata: [],
      }
    },
    methods: {
      searchdata() {
        var sqlcondition = {
          items: 's.*',
          tablename: '(SELECT \'笔数\' type, a.name name, a.bi value from (select  f_outlets name,COUNT(id) bi' +
          ' from t_sellinggas where f_state=\'有效\' and f_outlets is not null and ' +
          ' f_operate_date>=\'' + this.startdate + '\' and  f_operate_date<=\'' + this.enddate + '\'' +
          'and f_orgstr like \'%' + this.f_orgstr + '%\' group by f_outlets) a union' +
          ' SELECT \'气量\' type, b.name, b.gas_value value from (select  f_outlets name,SUM(f_pregas) gas_value' +
          ' from t_sellinggas where f_state=\'有效\' and f_outlets is not null and f_operate_date>=\'' + this.startdate + '\' ' +
          ' and  f_operate_date<=\'' + this.enddate + '\' and f_orgstr like \'%' + this.f_orgstr + '%\' group by f_outlets)b union SELECT \'金额\' type, c.name, c.money_value value\n' +
          'from (select  f_outlets name, SUM(f_preamount) money_value from t_sellinggas where f_state=\'有效\' ' +
          'and f_outlets is not null and  f_operate_date>=\'' + this.startdate + '\' and  f_operate_date<=\'' + this.enddate + '\' and f_orgstr like \'%' + this.f_orgstr + '%\' group by f_outlets)c)s',
          condition: '1=1'
        }
        let getData = Des.getData(this, sqlcondition)
        co(getData)
      }
    },
    ready() {
      this.searchdata()
    },
    watch: {
      'startdate'(val) {
        this.searchdata()
      },
      'enddate'(val) {
        this.searchdata()
      },
      'f_orgstr'(val) {
        console.log(this.f_orgstr, '测试')
        this.searchdata()
      },
      'sqlobtaindata': {
        deep: true,
        handler(val) {
          if (this.sqlobtaindata.length < 1) {
            let data = [{name: "", value: [{name: '', value: ""}]}]
            Des.setBar(this, 'BusinessHall', data, '营业厅气量金额直方图', '', '')
            return
          }
          let result = Des.DataIntegration(this.sqlobtaindata)
          Des.setBar(this, 'BusinessHall', result, '营业厅气量金额直方图', '营业厅', '气量金额笔数')
        }
      },
    }
  }
</script>

