<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <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">
                <div class="col-sm-2 form-group">
                  <label for="startDate" class="font_normal_body">开始日期</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                  >
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label for="endDate" class="font_normal_body">结束日期</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :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"
                                sqlurl="api/af-revenue/logic/openapi/exportfile"
                                sql-name="keyUserGasRanking"
                                template-name='重点用户用气排行查询'
                                :choose-col="true"></export-excel>
                  <print-data :sum-field="$parent.$parent.getfield" :model="$parent.model" :field="$parent.$parent.getfield"
                              :defaultfield="$parent.$parent.defaultfield"
                              titletable="重点用户用气排行查询"
                              ></print-data>
                  <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 class="col-sm-2 form-group">
                  <label class="font_normal_body">客户编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                         condition="f_userinfo_code = '{}' " placeholder="客户编号">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">客户姓名</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                         condition="f_user_name like '%{}%'" placeholder="客户姓名">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">表号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_meternumber"
                         condition="f_meternumber = '{}' " placeholder="表号">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">用气性质</label>
                  <v-select :value.sync="model.f_gasproperties" multiple
                            v-model="model.f_gasproperties"
                            :options='$parent.$parent.gasproperties' placeholder='请选择'
                            condition="f_gasproperties in {}"
                            close-on-select></v-select>
                </div>
              </div>
            </div>
          </criteria>
          <data-grid  :model="model" partial='list' class="list_area table_sy" v-ref:grid >
            <template partial='head'>
              <tr>
                <th v-for="(key,value ) in $parent.$parent.$parent.config.pageFilds" ><nobr>{{value}}</nobr></th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;" v-for="(key,value ) in $parent.$parent.$parent.config.pageFilds"><nobr>{{row[key]}}</nobr></td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList, HttpResetClass} from 'vue-client'
  import defaultPrint from '../../config/DefaultPrint'
  import plugins from "../../../../plugins/GetLoginInfoService";

  let readySomething = async function (self) {
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'
    await self.$MagLoadParams.loadParam()

  }

  export default {
    title: '重点用户用气排行查询',
    data() {
      let model = new PagedList('api/af-revenue/sql/keyUserGasRanking', 20, {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate'
      })
      return {
        //默认打印列
        defaultfield: [],
        config: {
          pageFilds:{
            'f_userinfo_code': '用户编号', 'f_user_name': '用户名', 'f_meternumber': '表号',  'f_gasproperties': '用气性质','f_pregas' : '用气量', 'f_bv':'所在用气性质占比'
          },
          defaultPrint: ['f_userinfo_code', 'f_user_name', 'f_meternumber','f_gasproperties','f_pregas', 'f_bv']
        },
        model: model,
        criteriaShow: false,
        gasproperties:[{label: '全部',value: ''}, ...this.$appdata.getParam('用气性质')]
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      selfSearch(args) {
        if(!this.$refs.paged.$refs.cri.model.startDate || !this.$refs.paged.$refs.cri.model.endDate){
          return this.$showMessage("时间区间的开始和结束时间不能为空！");
        }
        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] = []
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      }
    },
    watch: {
    },
    computed: {

      getCondition() {
        return {
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate: this.$refs.paged.$refs.cri.model.endDate,
          condition: this.$refs.paged.$refs.cri.condition
        }
      },
      getfield() {
        return this.config.pageFilds
      }
    }

  }
</script>
