<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
            <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
              <div class="row">
                <res-select-group :show-component="$parent.$parent.resshow" :initres="$parent.$parent.initres"
                                  :cascade=true @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
                <div class="col-sm-2 form-group" >
                  <label for="startDate" class="font_normal_body" title="开始日期">开始时间</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              >
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group" >
                  <label for="endDate" class="font_normal_body" title="结束日期">结束时间</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                  >
                  </datepicker>
                </div>

                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <button class="button_clear  button_spacing" @click="$parent.$parent.clear()">清空</button>

                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield" :header="$parent.$parent.other"
                                sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="YCMonthSummary" template-name='居民用户各项数据统计表（月报）'
                                :choose-col="true">
                  </export-excel>
                  <div style="float: right" class="button_spacing"
                       :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                       @click="$parent.$parent.hidden()"></div>

                </div>
              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
              </div>
            </div>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" style="height: 95%" v-ref:grid>
            <template partial='head'>
              <tr>
                <th colspan="4" style="text-align: center;"><nobr></nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>开通数</nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>通气数</nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>未通气数</nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>热水器</nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>壁挂炉</nobr></th>
                <th colspan="4" style="text-align: center;"><nobr>门面房</nobr></th>
                <th colspan="3" style="text-align: center;"><nobr>三项强制措施</nobr></th>
                <th colspan="1" style="text-align: center;"><nobr>欠费户数</nobr></th>
                <th colspan="2" style="text-align: center;"><nobr></nobr></th>
              </tr>
              <tr>
                <th style="text-align: center;">
                  <nobr>序号</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>片区</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>小区名称</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>小区开通时间</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>卡表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>金卡网联表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>新天物联网表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>自闭阀已装</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>不锈钢波纹软管已装</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>带熄火保护灶具</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>膜式表</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>长期不用停用数量（月）</nobr>
                </th>
                <th style="text-align: center;">
                  <nobr>当月用气量</nobr>
                </th>
              </tr>
            </template>
            <template partial='body'>
              <tr style="position: relative" class="table-bordered">
                <td ><nobr>{{$index + 1}}</nobr></td>
                <td style="text-align: center;">{{ row.f_slice_area }}</td>
                <td style="text-align: center;">{{ row.f_residential_area }}</td>
                <td style="text-align: center;">{{ row.f_operate_date }}</td>
                <td style="text-align: center;">{{ row.kts_machine }}</td>
                <td style="text-align: center;">{{ row.kts_card }}</td>
                <td style="text-align: center;">{{ row.kts_jk }}</td>
                <td style="text-align: center;">{{ row.kts_xt }}</td>
                <td style="text-align: center;">{{ row.gas_machine }}</td>
                <td style="text-align: center;">{{ row.gas_card }}</td>
                <td style="text-align: center;">{{ row.gas_jk }}</td>
                <td style="text-align: center;">{{ row.gas_xt }}</td>
                <td style="text-align: center;">{{ row.ungas_machine }}</td>
                <td style="text-align: center;">{{ row.ungas_card }}</td>
                <td style="text-align: center;">{{ row.ungas_jk }}</td>
                <td style="text-align: center;">{{ row.ungas_xt }}</td>
                <td style="text-align: center;">{{ row.rsq_machine }}</td>
                <td style="text-align: center;">{{ row.rsq_card }}</td>
                <td style="text-align: center;">{{ row.rsq_jk }}</td>
                <td style="text-align: center;">{{ row.rsq_xt }}</td>
                <td style="text-align: center;">{{ row.gbl_machine }}</td>
                <td style="text-align: center;">{{ row.gbl_card }}</td>
                <td style="text-align: center;">{{ row.gbl_jk }}</td>
                <td style="text-align: center;">{{ row.gbl_xt }}</td>
                <td style="text-align: center;">{{ row.sy_machine }}</td>
                <td style="text-align: center;">{{ row.sy_card }}</td>
                <td style="text-align: center;">{{ row.sy_jk }}</td>
                <td style="text-align: center;">{{ row.sy_xt }}</td>
                <td style="text-align: center;">{{ row.force_zbf }}</td>
                <td style="text-align: center;">{{ row.force_bwg }}</td>
                <td style="text-align: center;">{{ row.force_zj }}</td>
                <td style="text-align: center;">{{ row.owenum }}</td>
                <td style="text-align: center;">{{ row.unusenum }}</td>
                <td style="text-align: center;">{{ row.f_oughtamount }}</td>

              </tr>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

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

  let readySomething = async function (self) {
    await self.$MagLoadParams.loadParam()
    self.initmeterbook()
  }
  export default {
    props: ['data'],
    title: '居民用户各项数据统计表（月报）',
    data () {
      return {
        model: new PagedList('api/af-revenue/sql/YCMonthSummary', 50, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        years:[],
        other: [],
        orgCondtionStr: '',
        resshow: ['company'],
        initres: {
          org: [this.$login.f.orgid]
        },
        meterbrands: [],
        meterbooks:[],
        gasproperties:[],
        inputtores: [{label: '全部',value: ''}],
        criteriaShow: false,
        condition: '',
        //小区
        residentialArea: []
      }
    },
    ready () {
      this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
      // this.getinputtores()
      // this.getaddress()
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      getotherfooter () {
        this.other = [];
        let otherInData = [];
        otherInData.push(`居民用户各项数据统计表（月报）`);
        this.other.push(otherInData);
      },
      async initmeterbook(){
        this.meterbooks = [{label: '全部', value: ''}, ...this.$GetSaleParam.getMeterBooks()]
      },
      async getaddress(){
        let HttpReset = new HttpResetClass()
        var data = await HttpReset.load('POST', 'api/af-revenue/sql/manage_getarealist', {
          data: {
            condition: `1=1 and s.f_orgid = '${this.$login.f.orgid}'`
          }
        }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
        let house = [{label: '全部', value: ''}]
        for (let row of data.data){
          house.push({label: row.f_residential_area, value: row.f_residential_area})
        }
        this.residentialArea = house
      },
      async getinputtores () {
        // 获取抄表员
        let rs = []
        if (this.$login.f.f_gasman.length > 0) {
          for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
            let temp = {
              label: this.$login.f.f_gasman[i].name,
              value: this.$login.f.f_gasman[i].name
            }
            rs.push(temp)
          }
        }
        this.inputtores = [{label: '全部', value: ''}, ...rs]
      },
      cancel () {
        this.show = false
      },
      userTypeChange () {
        this.gasproperties = []
        if (this.$refs.paged.$refs.cri.model !== null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties = []
          this.gasproperties = this.$appdata.getParam('用气性质')
        } else {
          this.gasproperties = [{label: '全部', value: ''}]
        }
      },
      initParams () {
        // 初始化气表品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          brandArr.push(temp)
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
        //初始化气表价格
        this.prices = this.$MagGetSaleParam.getPrices()
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        let f_orgstr = this.orgCondtionStr
        args.condition = `${args.condition} ` + f_orgstr
        this.condition = args.condition
        this.model.search(args.condition, args.model)
      },
      clear () {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      show () {
        this.criteriaShow = true
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      async getRes (condition, obj) {
        this.orgCondtionStr = condition
        this.orgname = obj.orgnames[0]
      },
    },
    events: {},
    watch: {},
    computed: {
      getfield () {
        return {
           'f_slice_area': '片区', 'f_residential_area': '小区名称', 'f_operate_date': '小区开通时间',
           'kts_machine': '膜表开通数', 'kts_card': '卡表开通数', 'kts_xt': '金卡开通数', 'kts_jk': '新天开通数',
           'gas_machine': '膜表通气数', 'gas_card': '卡表通气数', 'gas_jk': '金卡通气数', 'gas_xt': '新天通气数',
           'ungas_machine': '膜表未通气数', 'ungas_card': '卡表未通气数', 'ungas_jk': '金卡未通气数', 'ungas_xt': '新天未通气数',
           'rsq_machine': '膜表热水器', 'rsq_card': '卡表热水器', 'rsq_jk': '金卡热水器', 'rsq_xt': '新天热水器',
           'gbl_machine': '膜表壁挂炉', 'gbl_card': '卡表壁挂炉', 'gbl_jk': '金卡壁挂炉', 'gbl_xt': '新天壁挂炉',
           'sy_machine': '膜表门面房', 'sy_card': '卡表门面房', 'sy_jk': '金卡门面房', 'sy_xt': '新天门面房',
           'force_zbf': '自闭阀已装', 'force_bwg': '不锈钢波纹软管已装', 'force_zj': '带熄火保护灶具', 'owenum': '欠费户数',
           'unusenum': '长期不用停用数量', 'f_oughtamount': '当月用气量'
        }
      },
      getCondition () {
        return {
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate: this.$refs.paged.$refs.cri.model.endDate,
          condition: this.condition
        }
      },
      usertypes () {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      meterStyle () {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('燃气表型号')]
      },



    }
  }
</script>

