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

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

let getData = function * (self) {
  let load = new HttpResetClass()
  load.load('POST', 'rs/sql/userfilesvalues',
  {data: {startDate: self.startdate, endDate: self.enddate, f_orgid: self.orgid}},
  {resolveMsg: null, rejectMsg: null})
  .then((res) => {
    self.texttile = '用户类型'
    // let arrparams = []
    console.log('获取数据。。', res.data)
    let org = []
    //let name = []
    let minyongvalue=[]
    let feiminyongvalue=[]
    for (var i = 0; i < res.data.length; i++) {
        if (!org.includes(res.data[i].org)) {
          org.push(res.data[i].org)
        }
        if (res.data[i].name === '民用') {
          minyongvalue[org.indexOf(res.data[i].org)] = res.data[i].number
        }else{
          feiminyongvalue[org.indexOf(res.data[i].org)]= res.data[i].number
        }
    }
    self.set(org,minyongvalue,feiminyongvalue)
  })
}
export default {
  props: {
    startdate: {
      type: String,
      default: Util.toStandardDateString()
    },
    enddate: {
      type: String,
      default: Util.toStandardDateString()
    },
    orgid: {
      type: String
    }
},
 data () {
   title: '银行管理'
   return {
     texttile: '',
     xc: '',

     minyongvalue: [],
     feiminyongvalue: []
   }
 },
 methods: {
   set (org,minyongvalue,feiminyongvalue) {
     this.xc = echarts.init(document.getElementById('bm'))
     this.xc.setOption({
       title : {
         text: '新增用户散列图',
         subtext: '数据查询来源',
         x: 'left'
       },
       tooltip : {
         trigger: 'axis'
       },
       legend: {
         x: 'left',
         y: 'bottom',
         data: ['民用','非民用']
       },
       toolbox: {
         show : true,
         feature : {
           dataView : {show: true, readOnly: false},
           magicType : {show: true, type: ['line', 'bar']},
           restore : {show: true},
           saveAsImage : {show: true}
         }
       },
       calculable : true,
       xAxis : [
         {
           type : 'category',
           data : org
         }
      ],
      yAxis : [
        {
          type : 'value'
        }
      ],
      series : [
        {
          name:'民用',
          type:'bar',
          data:minyongvalue,
          markLine : {
            data : [
              {type : 'average', name: '平均值'}
            ]
          }
        },
        {
          name:'非民用',
          type:'bar',
          data:feiminyongvalue,
          markLine : {
          data : [
              {type : 'average', name : '平均值'}
            ]
          }
        }
      ]
     })
   },
   searchdata () {
     let getGen =getData(this)
     co(getGen)
   }
 },
 ready () {
   this.searchdata()
 },
 watch: {
   'startdate' (val) {
     this.searchdata()
   },
   'enddate' (val) {
     this.searchdata()
   },
   'orgid' (val) {
     this.searchdata()
   }
 }

}
</script>
