<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <div class="flex" v-if="!show">
    <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 @keyup.enter="search()">
          <div class="row">
            <div class="col-sm-2">
              <label class="font_normal_body">&emsp;&emsp;公司</label>
              <right-tree @re-res="$parent.$parent.getorg"
                          :initresid='$parent.$parent.org'></right-tree>
            </div>
            <div class="col-sm-2 ">
              <label for="f_gasproperties"class="font_normal_body">用气性质</label>
              <v-select id="f_gasproperties"
                        style="width:60%"
                        v-model="model.f_gasproperties"
                        placeholder='用气性质'
                        :value.sync="model.f_gasproperties"
                        :options='$parent.$parent.gasproperties'
                        condition="f_gasproperties = '{}'"
                        close-on-select >
              </v-select>
            </div>
            <div class="col-sm-2" >
              <label  for="f_user_state" class="font_normal_body">客户状态</label>
              <v-select :value.sync="model.f_user_state"
                        v-model="model.f_user_state"
                        :options='$parent.$parent.userstate' placeholder='请选择'
                        condition="f_user_state = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 flex-row" style="white-space: nowrap">
              <label class="font_normal_body" v-if="$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.meter_classify.includes('物联网表')" >未购天数</label>
              <label class="font_normal_body" v-else>未抄天数</label>
              <div class="row">
                <input type="text" style="width:30%" class="input_search" v-model="model.diffdaymin"
                       condition="diffday >= {} " placeholder="">
                <label   class="font_normal_body">  ≤ x ≤ </label>
                <input type="text" style="width:30%" class="input_search" v-model="model.diffdaymax"
                       condition="diffday <= {} " placeholder="">
              </div>

            </div>

            <div class="span" style="float:right;">
              <button class="btn button_search" @click="search()">查询</button>
              <button class="btn button_clear" @click="$parent.$parent.clear()">清空</button>
              <button class="btn button_clear" @click="$parent.$parent.batchQuota()">批量限购</button>
              <export-excel :data="$parent.$parent.getCondition"
                            :field="$parent.$parent.getfield"
                            :footer="$parent.$parent.footer"
                            :header="$parent.$parent.other"
                            sqlurl="api/af-revenue/logic/openapi/exportfile"
                            :sql-name="$parent.$parent.sqlName"
                            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"
                          print-name="稽查查询打印"
                          :sumsmodel="$parent.$parent.sumsmodel" ></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 ">
              <label class="font_normal_body">起始时间</label>
              <datepicker id="startDate" placeholder="起始时间"
                          v-model="model.startDate"
                          style="width:60%"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 ">
              <label class="font_normal_body">截止时间</label>
              <datepicker id="endDate" placeholder="截止时间"
                          v-model="model.endDate"
                          style="width:60%"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 ">
              <label for="f_meter_classify"class="font_normal_body" title="参数名称：气表类型">气表类型</label>
              <v-select id="f_meter_classify"
                        v-model="$parent.$parent.meter_classify"
                        placeholder='气表类型'
                        style="width:70%"
                        :value.sync="$parent.$parent.meter_classify"
                        :options='$parent.$parent.f_meter_classify'
                        :value-single="true"
                        close-on-select >
              </v-select>
            </div>
            <div class="col-sm-2 ">
              <label for="f_table_state" class="font_normal_body">&emsp;表状态</label>
              <v-select id="f_table_state"
                        style="width:60%"
                        v-model="model.f_table_state"
                        placeholder='表状态'
                        :value.sync="model.f_table_state"
                        :options='$parent.$parent.tablestate'
                        condition="f_table_state = '{}'"
                        close-on-select >
              </v-select>
            </div>
            <div class="col-sm-2" >
              <label class="font_normal_body" v-if="$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.meter_classify.includes('物联网表')">购气次数</label>
              <label class="font_normal_body" v-else>抄表次数</label>
                <input type="text" style="width:25%" class="input_search" v-model="model.cishumin"
                       condition="cishu >= {} " placeholder="">
                <label   class="font_normal_body">  ≤ x ≤ </label>
                <input type="text" style="width:25%" class="input_search" v-model="model.cishumax"
                       condition="cishu <= {} " placeholder="">
            </div>
            <div class="col-sm-2">
              <label class="font_normal_body" v-if="$parent.$parent.meter_classify.includes('卡表')">&nbsp;&nbsp;购气量</label>
              <label class="font_normal_body" v-if="$parent.$parent.meter_classify === '机表'">&nbsp;&nbsp;用气量</label>
              <label class="font_normal_body" v-if="$parent.$parent.meter_classify === '物联网表'">购气金额</label>
                <input type="text" style="width:25%" class="input_search" v-model="model.pregasmin"
                       condition="pregas >= {} " placeholder="">
                <label   class="font_normal_body">  ≤ x ≤ </label>
                <input type="text" style="width:25%" class="input_search" v-model="model.pregasmax"
                       condition="pregas <= {} " placeholder="">
            </div>
            <div class="col-sm-2" v-if="$parent.$parent.meter_classify.includes('卡表')">
              <label class="font_normal_body">购气金额</label>
                <input type="text" style="width:25%" class="input_search" v-model="model.collectionmin"
                       condition="collection >= {} " placeholder="">
                <label   class="font_normal_body">  ≤ x ≤ </label>
                <input type="text" style="width:25%" class="input_search" v-model="model.collectionmax"
                       condition="collection <= {} " placeholder="">
            </div>

            <div class="col-sm-2">
              <label class="font_normal_body">&emsp;&emsp;表号</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 ">
              <label class="font_normal_body">用户类型</label>
              <v-select :value.sync="model.f_user_type"
                        @change="$parent.$parent.userTypeChange()"
                        :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                        condition="f_user_type = '{}'"
                        close-on-select></v-select>
            </div>

            <div class="col-sm-2">
              <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">
              <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 like '%{}%' " placeholder="客户编号">
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" title="旧客户编号">档案编号</label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_olduserinfo_code"
                     condition="f_olduserinfo_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_address"
                     condition="f_address 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_user_phone"
                     condition="f_user_phone like '%{}%'" placeholder="客户电话">
            </div>
            <div class="col-sm-2  form-group">
              <label class="font_normal_body">是否安检</label>
              <v-select :value.sync="model.f_ischeck"
                        :options='$parent.$parent.ischecks'
                        placeholder='请选择'
                        v-model="model.f_ischeck"
                        condition="f_ischeck = '{}'"
                        close-on-select></v-select>
            </div>


          </div>

        </div>
      </criteria>
      <data-grid :model="model" partial='list' class="list_area table_sy" :optional="true"  v-ref:grid>
        <template partial='head'>
          <tr>
            <th><nobr>序号</nobr></th>
            <th><nobr>客户编号</nobr></th>
            <th><nobr>客户电话</nobr></th>
            <th><nobr>档案编号</nobr></th>
            <th><nobr>表号</nobr></th>
            <th><nobr>客户名称</nobr></th>
            <th><nobr>客户状态</nobr></th>
            <th><nobr>客户地址</nobr></th>
            <th><nobr>建档日期</nobr></th>
            <th><nobr>客户类型</nobr></th>
            <th><nobr>用气性质</nobr></th>
            <th><nobr>表具状态</nobr></th>
            <th><nobr>气表品牌</nobr></th>
            <th><nobr>气价名称</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.$parent.meter_classify.includes('物联网表')"><nobr>区间内最后购气日期</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify === '机表'"><nobr>区间内最后抄表日期</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.$parent.meter_classify.includes('物联网表')"><nobr>区间内购气次数</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify === '机表'"><nobr>区间内抄表次数</nobr></th>

            <th v-show="$parent.$parent.$parent.meter_classify.includes('卡表')"><nobr>区间内购气量</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.$parent.meter_classify.includes('物联网表')"><nobr>区间内购气金额</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify === '机表'"><nobr>区间内用气量</nobr></th>

            <th v-show="$parent.$parent.$parent.meter_classify.includes('卡表') || $parent.$parent.$parent.meter_classify.includes('物联网表')"><nobr>区间内未购气天数</nobr></th>
            <th v-show="$parent.$parent.$parent.meter_classify === '机表'"><nobr>区间内未抄表天数</nobr></th>
            <th><nobr>组织机构</nobr></th>
            <th><nobr>安检次数</nobr></th>
            <th><nobr>最后安检时间</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;"><nobr>{{$index+1}}</nobr></td>
          <td style="text-align: center;"><nobr>
            <span @click="$parent.$parent.$parent.showmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
          </nobr> </td>
          <td style="text-align: center;"><nobr>{{row.f_user_phone}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_olduserinfo_code}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_meternumber}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_user_name}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_user_state}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_address}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_createfile_date}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_user_type}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_gasproperties}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_table_state}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_meter_brand}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_price_name}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.delivery_date}}</nobr></td>

          <td style="text-align: center;"><nobr>{{row.cishu}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.pregas}}</nobr></td>
          <td style="text-align: center;" v-show="$parent.$parent.$parent.meter_classify.includes('卡表')"><nobr>{{row.collection}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.diffday}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_orgname}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_checknum}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_last_check_date}}</nobr></td>
        </template>
      </data-grid>
    </criteria-paged>
        <table class="table-hover">
          <tr style="position: relative" class="table-bordered">
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">汇总信息</td>
            <td v-if="meter_classify.includes('卡表')" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">购气量合计:&emsp;&emsp;{{sumsmodel.pregas}}</td>
            <td v-if="meter_classify === '机表'" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">抄表气量合计:&emsp;&emsp;{{sumsmodel.pregas}}</td>
            <td v-if="meter_classify === '物联网表'" style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">购气金额合计:&emsp;&emsp;{{sumsmodel.pregas}}</td>
          </tr>
        </table>
  </div>
      <div class="flex" v-if="show">
        <user-info-detail-manage-new :f_userinfo_id="rowdata.f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage-new>
      </div>
    </div>
    <modal :show.sync="batchQuotaModalShow" v-ref:secureQuotaModalShow
           backdrop="false" class="secureQuotaModalShow" @modal-close="batchQuotaModalClose">
      <header slot="modal-header" class="modal-header" style="text-align: center">
      </header>
      <article slot="modal-body" class="modal-body">
        <validator name='v'>
          <form class="form-horizontal  select-overspread">
            <div class="row">
              <div class="col-sm-6 form-input-group" :class="[$v.third.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">第三方缴费</label>
                <input type="text" v-show="false" v-model="$refs.third.selectedItems"
                       v-validate:third='{required: true }'>
                <v-select
                  :value.sync="quotaData.f_third_pay"
                  v-model="quotaData.f_third_pay"
                  :options='thirdPays'
                  :value-single="true"
                  close-on-select v-ref:third></v-select>
              </div>
              <div class="col-sm-6 form-input-group" :class="[$v.style.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">限制类型</label>
                <input type="text" v-show="false" v-model="$refs.style.selectedItems"
                       v-validate:style='{required: true }'>
                <v-select
                  :value.sync="quotaData.f_limit_style"
                  v-model="quotaData.f_limit_style"
                  :options='limitstyle'
                  :value-single="true"
                  close-on-select v-ref:style></v-select>
              </div>
            </div>
            <div class="row" style="margin-top:10px;" >
              <div class="col-sm-6 form-input-group" :class="[$v.timetypes.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">周期类型</label>
                <input type="text" v-show="false" v-model="$refs.timetypes.selectedItems"
                       v-validate:timetypes='{required: true }'>
                <v-select
                  :value.sync="quotaData.f_time_type"
                  v-model="quotaData.f_time_type"
                  :options='timeTypes'
                  :value-single="true"
                  close-on-select v-ref:timetypes></v-select>
              </div>
              <div class="col-sm-6 form-input-group" :class="[$v.f_time_value.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">周期时长</label>
                <input type="text" v-model="quotaData.f_time_value"
                       placeholder="周期时长"
                       style="vertical-align:middle"
                       v-validate:f_time_value='{required: true }'>
              </div>
            </div>

            <div class="row" style="margin-top:10px;" v-if="quotaData.f_limit_style !=='按总量'">
              <div class="col-sm-6 form-input-group" :class="[$v.f_limit_times.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">限制次数</label>
                <input type="text" style="width: 70%;display: inline-block" v-model="quotaData.f_limit_times" placeholder="限制次数" v-validate:f_limit_times='{required: true }'>
              </div>
              <div class="col-sm-6 form-input-group" v-if="quotaData.f_limit_type ==='气量'" :class="[$v.f_limit_value.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">单次限购</label>
                <input type="text" v-model="quotaData.f_limit_value" placeholder="单次限购" v-validate:f_limit_value='{required: true }'>
              </div>
              <div class="col-sm-6 form-input-group" v-if="quotaData.f_limit_type ==='金额'" :class="[$v.f_limit_amount.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">单次限购</label>
                <input type="text" v-model="quotaData.f_limit_amount" placeholder="单次限购" v-validate:f_limit_amount='{required: true }'>
              </div>
            </div>
            <div class="row" style="margin-top:10px;" v-if="quotaData.f_limit_style ==='按总量'">
              <div class="col-sm-6 form-input-group" v-if="quotaData.f_limit_type ==='气量'"  :class="[$v.f_limit_value.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">总限购量</label>
                <input type="text" v-model="quotaData.f_limit_value" placeholder="单次限购" v-validate:f_limit_value='{required: true }'>
              </div>
              <div class="col-sm-6 form-input-group" v-if="quotaData.f_limit_type ==='金额'" :class="[$v.f_limit_amount.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">总限购量</label>
                <input type="text" v-model="quotaData.f_limit_amount" placeholder="单次限购" v-validate:f_limit_amount='{required: true }'>
              </div>
            </div>
            <div class="row" style="margin-top:10px;">
              <div class="col-sm-6 form-input-group" :class="[$v.limittype.required ? 'has-error' : '']">
                <label class="font_normal_body col-sm-3">支付限制</label>
                <input type="text" v-show="false" v-model="$refs.limittype.selectedItems"
                       v-validate:limittype='{required: true }'>
                <v-select
                  :value.sync="quotaData.f_limit_type"
                  v-model="quotaData.f_limit_type"
                  :options='limitTypes'
                  :value-single="true"
                  close-on-select v-ref:limittype></v-select>
              </div>
              <div class="col-sm-6 form-input-group">
                <label class="font_normal_body col-sm-3">执行时间</label>
                <datepicker placeholder="执行时间"
                            v-model="quotaData.f_start_date"
                            :value.sync="quotaData.f_start_date"
                            :format="'yyyy-MM-dd'">
                </datepicker>
              </div>
              <div class="row auto">
                <div class="col-sm-12 form-group form-input-group" :class="[$v.f_operate_reason.required ? 'has-error' : '']">
                  <label class="control-label">限购原因</label>
                  <div class="col-sm-4">
                    <textarea class="form-control col-sm-4"
                              v-model="quotaData.f_operate_reason"
                              v-validate:f_operate_reason='{required: true }'
                              placeholder="限购原因">
                    </textarea>
                  </div>
                </div>
              </div>
            </div>
          </form>
        </validator>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <div class="modal-footer">
          <button type="button" class="btn btn-default" :disabled="!$v.valid"
                  @click='batchQuotaConfirm'>确定
          </button>
          <button type="button" class="btn btn-default" @click='batchQuotaModalClose'>取消</button>
        </div>
      </footer>
    </modal>
  </div>
</template>
<script>
  /**
   *用户档案查询列表以及添加操作组件
   */
  import { PagedList } from 'vue-client'
  import Vue from 'vue'
  import plugin from 'system-clients/src/plugins/GetLoginInfoService'

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStartAndEndDateString()[0]
    self.$refs.paged.$refs.cri.model.endDate =  self.$login.toStandardDateString()

    // await self.$refs.paged.$refs.cri.search()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }
  export default {
    title: '用户稽查',
    data () {
      return {
        other:[],
        footer:[],
        org:[this.$login.f.orgid],
        criteriaShow: false,
        meter_classify:'气量卡表',
        filialeNameStr: null,
        filialeCodeStr: `and f_orgid = '${this.$login.f.orgid}'`,
        userid: this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() == $organization$))`,
        getfield:{"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号","f_user_name":"客户名称",
          "f_user_state":"客户状态","f_user_phone":"客户电话","f_address":"地址","f_createfile_date":"建档日期","f_user_type":"用户类型",
          "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
          "delivery_date":"区间内最后购气日期","cishu":"区间内购气次数","pregas":"区间内购气量","collection":"区间内购气金额",
          "diffday":"区间内未购气天数","f_checknum":"安检次数","f_last_check_date":"最后安检日期"},
        model: new PagedList('api/af-revenue/sql/inspectList', 50,{startDate:'this.model.startDate',endDate:'this.model.endDate'},{pregas: 0}),
        rows: null,
        //orgid:'',
        show:false,
        sqlName:'inspectList',
        rowdata:{},
        sumsmodel: {},
        config: {
          defaultPrint: ['f_userinfo_code','f_user_id']
        },
        thirdPays: [{label: '支持', value: '1'},{label: '不支持', value: '0'}],
        timeTypes: [{label: '按月', value: '按月'},{label: '按日', value: '按日'}],
        limitTypes: [{label: '气量', value: '气量'},{label: '金额', value: '金额'}],
        limitstyle: [{label: '按次数', value: '按次数'},{label: '按总量', value: '按总量'}],
        batchRowList: [],
        quotaData: {
          f_third_pay: '0',
          f_time_type: '按月',
          f_limit_times: '',
          f_time_value: '',
          f_limit_type: '气量',
          f_limit_style:'',
          f_limit_value: 0,
          f_limit_amount: 0,
          f_start_date: this.$login.toStandardDateString(),
          f_operate_reason: '',
          f_limit_source: '营收批量限购'
        },
        ischecks: [{label: '全部', value: ''},{label: '已安检', value: '已安检'},{label: '未安检', value: '未安检'}],
        batchQuotaModalShow: false,
        defaultfield: [],
      }
    },
    watch:{
      meter_classify(val){
        if (val.includes('卡表')) {
          this.model.url = this.url = 'api/af-revenue/sql/inspectList'
          this.sqlName = 'inspectList'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_user_phone":"客户电话","f_address":"地址",
            "f_createfile_date":"建档日期","f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"区间内最后购气日期","cishu":"区间内购气次数","pregas":"区间内购气量","collection":"区间内购气金额",
            "diffday":"区间内未购气天数","f_checknum":"安检次数","f_last_check_date":"最后安检日期"}
        }else if (val === '机表') {
          this.model.url = this.url = 'api/af-revenue/sql/handinspectList'
          this.sqlName = 'handinspectList'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_user_phone":"客户电话","f_address":"地址",
            "f_createfile_date":"建档日期","f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"区间内最后抄表日期","cishu":"区间内抄表次数","pregas":"区间内抄表气量",
            "diffday":"区间内未抄表天数","f_checknum":"安检次数","f_last_check_date":"最后安检日期"}
        } else if (val === '物联网表') {
          this.model.url = this.url = 'api/af-revenue/sql/getWebMeterList'
          this.sqlName = 'getWebMeterList'
          this.getfield = {"f_userinfo_code":"客户编号","f_olduserinfo_code":"档案编号","f_meternumber":"表号",
            "f_user_name":"客户名称","f_user_state":"客户状态","f_user_phone":"客户电话","f_address":"地址",
            "f_createfile_date":"建档日期", "f_user_type":"用户类型",
            "f_gasproperties":"用气性质","f_table_state":"表具状态","f_meter_brand":"气表品牌","f_price_name":"气价名称",
            "delivery_date":"区间内最后购气日期","cishu":"区间内购气次数","pregas":"区间内购气金额",
            "diffday":"区间内未购气天数","f_checknum":"安检次数","f_last_check_date":"最后安检日期"}
        }
        this.clear()
        this.model.rows = []
        for(let key in this.model.sums){
          this.model.sums[key] = 0
        }

      },
      sumsmodel:{
        handler: function(val) {
          this.getotherfooter();
        },
        deep: true
      }
    },
    ready () {

      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })

      // 添加回车键监听
      document.addEventListener('keyup', this.handleKeyUp)
    },
    methods: {
      // 添加处理回车键的方法
      handleKeyUp(e) {
        if (e.key === 'Enter') {
          this.search()
        }
      },
      batchQuotaConfirm () {
        let selectRow =  this.$refs.paged.$refs.grid.getRowData()
        let selectRowLen = selectRow.length
        let msg = {
          resolveMsg: `您已成功限购${selectRowLen}位用户！`,
          rejectMsg: '批量作废限购失败！'
        }
        this.batchRowList = []
        selectRow.forEach(row => {
          this.batchRowList.push({"f_userinfo_id": row.f_userinfo_id, "f_priceid": row.f_priceid})
        })
        this.$showMessage(`您确定要将您你选中的${selectRowLen}位用户进行批量限购吗?`, ['confirm', 'cancel']).then(async (res) => {
          if (res === 'confirm') {
            console.log('所选中的用户:=======' + JSON.stringify(this.batchRowList))
            let data = {
              limitUserList: this.batchRowList,
              f_operate_people: this.$login.f.name,
              f_operate_peopleid: this.$login.f.id,
              model: this.quotaData,
              f_operate_type: '0'
            }
            await this.$resetpost('api/af-revenue/logic/sale_operateQuotaRecord', {data: data}, msg)
            this.batchQuotaModalClose()
            this.search()
          }
        })
      },
      batchQuotaModalClose () {
        this.quotaData = {
          f_third_pay: '0',
          f_time_type: '按月',
          f_limit_times: '',
          f_time_value: '',
          f_limit_type: '气量',
          f_limit_style:'',
          f_limit_value: 0,
          f_limit_amount: 0,
          f_start_date: this.$login.toStandardDateString(),
          f_operate_reason: '',
          f_limit_source: '营收批量限购'
        }
        this.batchQuotaModalShow = false
      },
      batchQuota(){
        if (!this.$login.r.find(value => value == '稽查批量限购')) {
          this.$showAlert('您没有权限操作此功能！！！', 'warning', 2000)
          return
        }
        if(this.$refs.paged.$refs.grid.getRowData().length === 0){
          this.$showAlert('请至少选择一项！', 'warning', 2000)
          return
        }
        this.batchQuotaModalShow = true
      },
        getotherfooter(){
          // this.$refs.paged.$refs.cri.$refs.exports.otherData=[];
          // this.$refs.paged.$refs.cri.$refs.exports.footerData=[];
          this.other=[];
          this.footer=[];
          let exportdata = this.getCondition;
          let otherInData=[];
          otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`);
          let footerData=[],exportfield=this.getfield;
          footerData.push("合计");
          let self = this;
          for(var field in self.sumsmodel){
            footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`);
          }
          this.footer.push(footerData);
          this.other.push(otherInData);
        },
      getorg (obj) {
        if(obj.resids.length>0){
          this.filialeCodeStr =" and f_orgid in " + plugin.convertToIn(obj.resids)
        }
        else{
          this.filialeCodeStr= " and f_orgid = " + this.$login.f.orgid
        }
      },
      userTypeChange () {
        this.gasproperties=[]
        if(this.$refs.paged.$refs.cri.model !==null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
      },

      cancel() {
        this.show = false
      },
      showmsg(obj){
        this.rowdata=obj
        this.show=true
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        if (!this.meter_classify) {
          this.$showMessage('请选择气表类型。。。')
          return
        }
        this.model.params.meter_classify = this.meter_classify
        args.condition = args.condition+ ` ${this.filialeCodeStr}`
        this.model.search(args.condition, args.model)
      },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      clear(){
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          if(key != 'startDate' && key != 'endDate')
            this.$refs.paged.$refs.cri.model[key] = []
        })
        this.$refs.paged.$refs.cri.model.startDate =  this.$login.toStartAndEndDateString()[0]
        this.$refs.paged.$refs.cri.model.endDate =  this.$login.toStandardDateString()
      }
    },
    computed: {
      gasproperties() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      usertypes() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      userstate() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('客户状态')]
      },
      tablestate () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')]
      },
      f_meter_classify(){
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
        // return [{label: '机表', value: '机表'},{label: '卡表', value: '卡表'},{label: '物联网表', value: '物联网表'}]
        // return [{label: '卡表', value: '卡表'}]
      },

      getCondition () {
        let result = {
          condition: '',
          diffDay:' 1=1 ',
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate: this.$refs.paged.$refs.cri.model.endDate
        }
        result.condition = this.$refs.paged.$refs.cri.condition + this.filialeCodeStr

        return result
      }
    },
    beforeDestroy() {
      // 组件销毁前移除事件监听
      document.removeEventListener('keyup', this.handleKeyUp)
    }
  }
</script>
<style media="screen">
  .divtext {
    min-width: 50px;
    max-width: 200px;
    border: 1px solid green;
    display: inline-block;
  }
</style>

