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

<script>
  import * as Util from '../../Util'
  import * as Des from '../../stores/DrillECharts'
  import co from 'co'

  export default {
    name:'CompanyUser',
    props: {
      startdate: {
        type: String,
        default: Util.toStandardDateString()
      },
      enddate: {
        type: String,
        default: Util.toStandardDateString()
      },
      f_orgstr: {
        type: String,
        default: ''
      },
      echartsflag:Boolean,
    },
    data () {
      title: '站点管理'
      return {
        texttile: '',
        xc: '',
        sqlobtaindata:[],
      }
    },
    methods: {
      searchdata () {
        var sqlcondition={
          items: 'f_user_type type,f_filiale name,count(f_userinfo_id) value',
          tablename: 't_userinfo',
          condition: 'f_user_state=\'正常\' and f_orgstr LIKE \'%'+this.f_orgstr+'%\' and f_createfile_date>=\''+this.startdate+'\'' +
          ' and f_createfile_date<=\''+this.enddate+'\' GROUP BY f_user_type,f_filiale'
        }
        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,'cesh')
        this.searchdata()
      },
      'sqlobtaindata':{
        deep:true,
        handler(val){
          if(this.sqlobtaindata.length<1){
            let data=[{name: "", value: [{name: '', value: ""}]}]
            Des.setBar(this,'CompanyUser',data,'用户分布直方图','','')
            return
          }
          let result=Des.DataIntegration(this.sqlobtaindata)
          Des.setBar(this,'CompanyUser',result,'用户分布直方图','公司名称','用户数量')
        }
      },
    }

  }
</script>

