<template>
  <div class="flex-row">
    <div @keyup.enter="search" class="basic-main">
      <criteria-paged :model="model" v-ref:paged @sort="sort">
        <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <modal :show.sync="$parent.$parent.upshow" width="500px" title="文件导入" v-ref:modal large backdrop="false">
              <article slot="modal-body" class="modal-body">
                <file-upload class="my-file-uploader " name="UploadFile" class="btn btn-success"
                             style="border-radius: 2px;"
                             action="rs/file/uploadFile" tagname="导入抄表数据" v-ref:file :headers="headers"
                             multiple></file-upload>
              </article>
              <footer slot="modal-footer" class="modal-footer">
              </footer>
            </modal>
            <div class="row">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">开始日期</label>
                <datepicker style="width:60%" id="startDate" placeholder="开始日期"
                            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 class="font_normal_body">结束日期</label>
                <!--<label for="endDate" class="control-label">结束日期</label>-->
                <datepicker style="width:60%" id="endDate" placeholder="结束日期"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            :format="'yyyy-MM-dd'"
                            :show-reset-button="true">
                </datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用户编号</label>
                <input style="width:60%" type="text" class="form-control col-sm-6" v-model="model.f_userinfo_code"
                       condition="f_userinfo_code='{}'" placeholder='用户编号'
                >
              </div>

              <div class="col-sm-2 form-group">
                <label class="font_normal_body" style="color:red">抄表日期</label>
                <!--<label for="endDate" class="control-label">结束日期</label>-->
                <datepicker style="width:60%" id="handDate" placeholder="抄表录入日期"
                            v-model="$parent.$parent.handDate"
                            :value.sync="$parent.$parent.handDate"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            :show-reset-button="true">
                </datepicker>
              </div>
              <!--<div class="form-group">-->
              <!--<input style="width:60%" type="text" class="form-control" v-model="model.f_user_id"-->
              <!--condition="f_user_id='{}'" placeholder='表编号'-->
              <!--:size="model.f_user_id ? model.f_user_id.length : 3">-->
              <!--</div>-->

              <div class="span" style="float:right;">
                <button class="button_search button_spacing" @click="search()">查询</button>
                <button  class="button_search" style="width: 90px" @click="$parent.$parent.downloadFiles()">模板下载</button>
                <button class="button_search button_spacing" @click="$parent.$parent.clickupshow()">抄表导入</button>
                <!--<button class="button_clear  button_spacing" @click="$parent.$parent.searchPrint()">抄表模板导出</button>-->
                <!--<button class="btn btn-success  width-100" @click="$parent.$parent.batchAudit()">批量审核</button>
                -->
                <export-excel
                  :data="{startDate: $parent.$parent.startDate, endDate: $parent.$parent.endDate, condition: $parent.$parent.model.condition,orderitem: $parent.$parent.orderitem?$parent.$parent.orderitem :'f_userinfo_code'}"
                  :field="$parent.$parent.getfield"
                  sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="getCardPlan"
                  template-name='卡表抄表导出'
                  :choose-col="true">
                </export-excel>
                <div
                  :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;小区域</label>
                <v-select :value.sync="model.f_small_area" v-model="model.f_small_area"
                          :options='$parent.$parent.smallareas' placeholder='小区域'
                          close-on-select :search='true'
                          condition="f_small_area = '{}'"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用户姓名</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_user_name" placeholder='用户姓名'
                       condition="f_user_name = '{}'">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用户地址</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_address"
                       condition="f_address like '%{}%'" placeholder='用户地址'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">小&emsp;&emsp;区</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_residential_area"
                       condition="f_residential_area like '%{}%'" placeholder='小区'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">楼&emsp;&emsp;栋</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_building"
                       condition="f_building like '%{}%'" placeholder='楼栋'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">单&emsp;&emsp;元</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_unit"
                       condition="f_unit like '%{}%'" placeholder='单元'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">楼&emsp;&emsp;层</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_floor"
                       condition="f_floor like '%{}%'" placeholder='楼层'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;门牌号</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_room"
                       condition="f_room like '%{}%'" placeholder='门牌号'
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">表&emsp;&emsp;号</label>
                <input style="width:60%" type="text" class="form-control" v-model="model.f_meternumber"
                       condition="f_meternumber like '%{}%'" placeholder='表号'
                >
              </div>
              <!--</div>-->
              <!--<div class="row">-->
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;抄表员</label>
                <v-select :value.sync="model.f_inputtor" v-model='model.f_inputtor'
                          :options='$parent.$parent.inputtore' placeholder='抄表员'
                          close-on-select multiple="true"
                ></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用户类型</label>
                <v-select :value.sync="model.f_user_type" v-model="model.f_user_type"
                          :options='$parent.$parent.usertypes' placeholder='用户类型'
                          close-on-select :search='true'
                          condition="f_user_type = '{}'"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用气性质</label>
                <v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                          :options='$parent.$parent.gasproperties' placeholder='用气性质'
                          close-on-select :search='true'
                          condition="f_gasproperties = '{}'"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用户等级</label>
                <v-select :value.sync="model.f_user_level" v-model="model.f_user_level"
                          :options='$parent.$parent.userlevels' placeholder='用户等级'
                          style="width:60%"
                          close-on-select
                          condition="f_user_level = '{}'"></v-select>
              </div>
              <!-- <div class="col-sm-2 form-group">
                   <label  class="col-sm-4 font_normal_body">气价名称</label>
                   <v-select :value.sync="model.f_price_name"
                             v-model="model.f_price_name"
                             :options='$parent.$parent.pricenames' placeholder='气价名称'
                             condition="f_price_name= '{}'" class="col-sm-8"
                             close-on-select></v-select>
               </div>-->
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">抄表状态</label>
                <v-select :value.sync="model.f_meter_state" v-model="model.f_meter_state"
                          :options='$parent.$parent.meterstates' placeholder='抄表状态'
                          close-on-select f_gasbrand_id
                          condition="f_meter_state {}"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表品牌</label>
                <v-select :value.sync="model.gasbrand" v-model="model.gasbrand"
                          :options='$parent.$parent.meterbrands' placeholder='气表品牌' close-on-select
                          v-model='$parent.$parent.gasbrand'
                          condition="f_meter_brand = '{}'"
                ></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">使用类型</label>
                <v-select :value.sync="model.f_usetype"
                          v-model="model.f_usetype"
                          :options='$parent.$parent.usetype'
                          placeholder='使用类型'
                          style="width:60%"
                          close-on-select
                          condition="f_usetype = '{}'">
                </v-select>
              </div>
              <res-select-group :show-component="['company','department','operator']" :initres="$parent.$parent.initres"
                                @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
              <hl-downdata class="col-sm-1 form-group" :info="model"></hl-downdata>
            </div>

          </div>
        </criteria>
        <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid id="CardHand">
          <template partial='head'>
            <tr>
              <th>
                <nobr>序号</nobr>
              </th>
              <!--                        <th>户编号</th>-->
              <!--                        <th>基本信息</th>-->
              <th>
                <nobr>
                  <data-order field="f_userinfo_code" name="户编号"
                              :order.sync="$parent.$parent.$parent.orderFields.f_userinfo_code"></data-order>
                </nobr>
              </th>
              <th>
                <nobr>
                  <data-order field="f_address" name="基本信息"
                              :order.sync="$parent.$parent.$parent.orderFields.f_address"></data-order>
                </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>
                  <data-order field="f_hand_date" name="下发日期"
                              :order.sync="$parent.$parent.$parent.orderFields.f_hand_date"></data-order>
                </nobr>
              </th>
              <th>
                <nobr>
                  <data-order field="f_last_input_date" name="上次抄表录入日期"
                              :order.sync="$parent.$parent.$parent.orderFields.f_last_input_date"></data-order>
                </nobr>
              </th>
              <th>
                <nobr>
                  <data-order field="f_input_date" name="抄表录入日期"
                              :order.sync="$parent.$parent.$parent.orderFields.f_input_date"></data-order>
                </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>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center;">{{ $index + 1 }}</td>
            <td style="text-align: center;">{{ row.f_userinfo_code }}</td>
            <td style="text-align: center;">
              {{ row.f_user_name }}&nbsp;&nbsp;{{ row.f_gasproperties }}&nbsp;&nbsp;{{
                row.f_user_phone
              }}&nbsp;&nbsp;{{ row.f_address }}
            </td>
            <td>{{ row.f_user_level }}</td>
            <td style="text-align: center;">{{ row.f_residential_area }}</td>
            <td style="text-align: center;">{{ row.f_meternumber }}</td>
            <td style="text-align: center;">{{ row.f_user_phone }}</td>
            <td style="text-align: center;">{{ row.f_inputtor }}</td>
            <td style="text-align: center;">{{ row.total_fee }}</td>
            <td style="text-align: center;">{{ row.total_gas }}</td>
            <td>{{row.f_hand_date}}</td>
            <td>{{row.f_last_input_date}}</td>
            <td style="text-align: center;">
              <div class="form-group" style="margin-bottom:0px;display: contents;" :class="{
                       'has-success has-feedback': !row.error,
                       'has-error has-feedback': row.error}"
                   v-if="row.f_meter_state === '未抄表'">
                <datepicker id="f_hand_date" placeholder="抄表录入日期"
                            v-model="row.f_input_date"
                            :value.sync="row.f_input_date"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            :show-reset-button="true">
                </datepicker>
              </div>
              <div v-else>
                {{ row.f_input_date }}
              </div>
            </td>
            <td style="text-align: center;">{{ row.f_last_tablebase }}</td>
            <td style="text-align: center;">
              <div class="form-group" style="margin-bottom:0px;" :class="{
						'has-success has-feedback': row.f_tablebase ? ((row.f_last_tablebase-0) <= (row.f_tablebase -0)) : false,
						'has-error has-feedback': row.f_tablebase ? ((row.f_last_tablebase-0) > (row.f_tablebase -0) ) : false}"
                   v-if="row.f_meter_state === '未抄表' ">
                <input type="text" class="form-control" v-model="row.f_tablebase"
                       @blur="$parent.$parent.$parent.enter(row)"
                       v-next-el="{id: $index+1}" :id="$index" style="width: 100px;padding: 6px;"
                       :disabled="row.state === '开始'"
                       @focus="$parent.$parent.$parent.clearError(row)">
              </div>
              <div v-else>
                <span v-if="row.f_tablebase">{{ row.f_tablebase }}</span>
              </div>
              <span v-if="row.error" style="color: red;">{{ row.error }}</span>
            </td>
            <td>
              <div class="form-group" style="margin-bottom:0px;display: contents;" :class="{
                       'has-success has-feedback': !row.error,
                       'has-error has-feedback': row.error}"
                   v-if="row.f_meter_state === '未抄表' && row.states !== 0">
                <v-select :value.sync="row.f_result_state" v-model="row.f_result_state"
                          :options='$parent.$parent.$parent.resultstate' placeholder='抄表结果'
                          width="100%"
                          :value-single="true"
                          close-on-select
                          condition="f_adjustable_name = '{}'"></v-select>
                <!-- <span id="inputError2Status" class="sr-only">(error)</span> -->
              </div>
              <div v-else>
                {{ row.f_result_state }}
              </div>
            </td>
            <td style="text-align:center">
              <img-self :src="row.f_handplan_image" v-if="row.f_handplan_image" :width="100" :height="100"></img-self>
              <img-self :src="`rs/image/file/${row.f_notified_path}`" v-if="row.f_notified_path" :width="100" :height="100"></img-self>
            </td>
            <td style="text-align:center">
              <img-self :src="row.f_sign_path" v-if="row.f_sign_path.indexOf('http:') > -1" :width="100" :height="100"></img-self>
              <img-self :src="`rs/image/file/${row.f_sign_path}`" v-else :width="100" :height="100"></img-self>
            </td>

            <td style="text-align: center;">{{ row.f_actualtablebase }}</td>
            <td style="text-align: center;">
              <div class="form-group" style="margin-bottom:0px;"
                   v-if="row.f_meter_state === '未抄表' ">
                <input type="text" class="form-control" v-model="row.f_shengyu_gas"
                       v-next-el="{id: $index+1}" :id="$index" style="width: 100px;padding: 6px;"
                       :disabled="row.state === '开始'"
                >
              </div>
              <div v-else>
                <span >{{ row.f_shengyu_gas }}</span>
              </div>
            </td>
            <td style="text-align: center;">{{ row.f_meter_state }}</td>
            <td style="text-align: center;">{{ row.f_usetype }}</td>
            <td style="text-align: center;">

              <!--                        <button type="button" name="button" class="btn btn-link"-->
              <!--                                @click.stop="$parent.$parent.$parent.modify(row)"-->
              <!--                                v-if="row.f_meter_state === '已抄表' && !$parent.$parent.$parent.jurisdiction.includes('审核权限')">修正</button>-->

              <!--   <button type="button" name="button" class="btn btn-link"
                         @click.stop="$parent.$parent.$parent.pass(row)"
                         v-if="$parent.$parent.$parent.jurisdiction.includes('审核权限') && row.f_meter_state === '待审核'">通过</button>

                 <button type="button" name="button" class="btn btn-link"
                         @click.stop="$parent.$parent.$parent.nopass(row)"
                         v-if="row.f_meter_state === '待审核' && $parent.$parent.$parent.jurisdiction.includes('审核权限')">不通过</button>-->
              <button type="button" name="button" class="button_search button_spacing width-60" title="权限名称:(卡表抄表冲正)"
                      @click.stop="$parent.$parent.$parent.cardhandCenter(row)"
                      v-if="row.f_meter_state === '已抄表'">冲正
              </button>
            </td>
            <td><span title="{{row.f_card_reason}}"
                      v-if="row.f_card_reason">{{ row.f_card_reason.substring(0, 5) }} ...</span>
            </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 style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
            抄表用量:&emsp;{{ sumsmodel.f_actualtablebase }}
          </td>
        </tr>
      </table>
      <modal :show.sync="cardCental" v-ref:modal backdrop="false">
        <header slot="modal-header" class="modal-header">
          <h4 class="modal-title">卡表抄表冲正</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <div class="form-group">
            <label class="label-control">撤销原因</label>
            <textarea class="form-control" v-model="cardreason" rows="3" placeholder="请填写撤销原因"></textarea>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button v-show="cardCental" type="button" class="btn btn-default" @click='close'>取消</button>
          <button v-show="cardCental" type="button" class="btn btn-success" @click='cancel(this.cardCentalData)'>确认
          </button>
        </footer>
      </modal>
    </div>
  </div>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
import Vue from 'vue'
import AppData from '../../../stores/AppData'
import * as Util from '../../../Util'
import co from 'co'

let loadParamGem = async function (self) {
  await self.$LoadParams.loadParam(self.f_filialeid)
  self.loadMeterBooks()
}
let modifyGen = function* (self, row, url) {
  console.log('抄表修正，。。。', row, url)
  self.cardCental = false
  self.cardCentalData = ''
  row.f_user_id = row.f_user_id + ''
  // 删除待审核的抄表记录
  let state = yield self.$resetpost(url, {data: row}, {warnMsg: null, rejectMsg: null, resolveMsg: null})
  if (state.data === '异常') {
    Vue.showAlert('该笔抄表有差额记录，请先冲正！！！', 'warning', 4000)
    return
  } else if (state.data === '正常') {
    Vue.showAlert('冲正成功，稍等片刻，正在重新查询！', 'success', 4000)
  }
  self.cardreason = ''
  // 重新查询界面
  self.search()
}

export default {
  title: '卡表抄表',
  data () {
    return {
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: []
      },
      timer: null,
      // 请求对象(批量导入,查询进度使用)
      HttpReset: new HttpResetClass(),
      resultstate: this.$appdata.getParam('卡表抄表表状态'),
      criteriaShow: false,
      orderitem: 'f_userinfo_code',
      model: new PagedList('rs/sql/getCardPlan', 50, {orderitem: this.orderitem ? '"' + this.orderitem + ' "' : `'f_userinfo_code'`}, {f_actualtablebase: 0}),
      // model: new PagedList('rs/sql/cardHands', 50),
      startDate: Util.toStartAndEndDateString()[0],
      endDate: Util.toStartAndEndDateString()[1],
      handDate: null,
      batch_audit: false,
      cardCental: false,
      // 合计数据
      sumsmodel: {},
      orderFields: {
        f_userinfo_id: 'no'
      },
      f_filialeid: this.$login.f.orgid,
      cardreason: '',
      cardCentalData: '',
      getfield: {
        'id': '抄表单编号',
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户姓名',
        'f_meternumber': '表号',
        'f_gasproperties': '用气性质',
        'f_user_phone': '客户电话',
        'f_address': '客户地址',
        'f_inputtor': '抄表员',
        'total_fee': '总购金额',
        'total_gas': '累购气量',
        'f_hand_date': '下发日期',
        'f_last_input_date': '上次抄表录入日期',
        'f_input_date': '抄表录入日期',
        'f_last_tablebase': '上期底数',
        'f_tablebase': '本期底数',
        'f_shengyu_gas': '剩余气量',
        'f_actualtablebase': '实际用量',
        'f_img_path': '附件查看',
        'f_sign_img': '签章图片',
        'f_meter_state': '状态',
        'f_usetype': '使用类型'
      },
      meterbrands: [{label: '全部', value: ''}],
      upshow: false,
      orgCondtionStr: ''
    }
  },
  beforeDestroy () {
    // 销毁定时器
    if (this.timer) clearInterval(this.timer)
  },
  ready () {
    this.$refs.paged.$refs.criteria.model.startDate = Util.toStartAndEndDateString()[0]
    this.$refs.paged.$refs.criteria.model.endDate = Util.toStartAndEndDateString()[1]
    loadParamGem(this)
  },
  methods: {
    downloadFiles () {
      let downurl = 'rs/downloadfile/file?filename=卡表批量抄表导入模板'
      this.$downFile(downurl,'卡表批量抄表导入模板.xlsx')
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    loadMeterBooks () {
      let meterbrand = this.$GetSaleParam.getGasbrand()
      for (let row of meterbrand) {
        console.log(row)
        this.meterbrands.push({label: row.label, value: row.label})
      }
    },
    search () {
      this.$refs.paged.$refs.criteria.search()
    },
    clickupshow () {
      console.log('in upload', this.upshow, !this.upshow)
      this.upshow = !this.upshow
    },
    searchPrint () {
      console.log('mode', this.model)
      let cons = this.model.params
      console.log('查询条件', cons)
      let data = {
        'body': {
          'data': {
            'condition': ''
          },
          'field': [],
          'templateName': '',
          'sqlName': ''
        },
        'condition': cons,
        'sqlname': 'cardHands'
      }
      this.$resetpost('rs/logic/allExportExcel', {data: data}, {resolveMsg: null, rejectMsg: '上传失败'}).then((res) => {
        if (res.data === 'no user') {
          this.$showAlert(`无匹配用户，无法导出对应excel`, 'warning', 2000)
        } else {
          var link = document.createElement('a')
          res.data.forEach((item) => {
            console.log('导出路径', item.filename)
            let path = item.filename
            // 本地
            // let pathName = "http://" + location.host + "/excel" + path.split('excel')[1]
            // 服务器
            let pathName = 'http://' + location.host + '/webapps' + path.split('webapps')[1]
            link.href = pathName
            console.log('=============================', path.split('excel/')[1])
            link.download = path.split('excel/')[1]
            link.dispatchEvent(new MouseEvent('click'))
          })
        }
      })
    },
    changeType () {
      if (this.$refs.paged.$refs.criteria.model.f_meter_classify && this.$refs.paged.$refs.criteria.model.f_meter_classify.length > 0) {
        this.$dispatch('type', this.$refs.paged.$refs.criteria.model.f_meter_classify[0])
      }
    },
    getRes (obj) {
      this.orgCondtionStr = obj
    },
    selfSearch (args) {
      this.sumsmodel = this.$refs.paged.$refs.grid.model.sums

      this.startDate = this.$refs.paged.$refs.criteria.model.startDate
      this.endDate = this.$refs.paged.$refs.criteria.model.endDate
      console.log('卡表抄表查询参数，。，。', args, this.model)
      this.model.params.startDate = this.$refs.paged.$refs.criteria.model.startDate
      this.model.params.endDate = this.$refs.paged.$refs.criteria.model.endDate

      // 抄表员查询条件
      this.inputtouPerson = this.$refs.paged.$refs.criteria.model.f_inputtor
      if (this.inputtouPerson.length !== 0) {
        let str = JSON.stringify(this.inputtouPerson)
        str = str.replace(/"/g, `'`)
        str = str.replace(/\[/g, ``)
        str = str.replace(/\]/g, ``)
        console.log('=====抄表员model22222222222绑定====', str)
        // 查询多个抄表员时条件
        args.condition += ` and f_inputtor in  ( ${str} )`
      }

      if (!this.orgCondtionStr) {
        args.condition = `${args.condition} and f_orgid = '${this.$login.f.orgid}'`
      } else {
        args.condition = `${args.condition}` + this.orgCondtionStr
      }
      if (args.model.f_meter_state.length > 0) {
        console.log('选择待审核状态了', args.model)
        this.batch_audit = args.model.f_meter_state[0] !== '已抄表' && args.model.f_meter_state[0] !== '未抄表'
      }
      this.model.search(args.condition, this.model)
    },
    reflash () {
      this.$refs.paged.$refs.criteria.search()
    },
    enter (row) {
      if (!row.f_tablebase || ((row.f_tablebase - 0) - (row.f_last_tablebase - 0)).toFixed(3) < 0) {
        return
      }
      if (row.f_tablebase.toString().split(".").length>1 && row.f_tablebase.toString().split(".")[1].length>3) {
        Vue.set(row, 'error', '底数最多只能输入小数点后3位')
        return
      }
      // || ((row.f_tablebase - 0) - (row.f_last_tablebase - 0)).toFixed(3) < 0
      if (row.f_tablebase) {
        // 如果本期底数大于上期底数生成超用收费
        // if ((row.f_tablebase - 0) > (row.f_meter_base - 0)) {
        //   row.charge_type = '超用收费'
        //   row.f_real_amount = (row.f_tablebase - 0) - (row.f_last_tablebase - 0)
        // } else if ((row.f_tablebase - 0) < (row.f_meter_base - 0)) {
        //   // 如果本地底数小于上期底数生成补差收费
        //   row.charge_type = '补差收费'
        //   row.f_real_amount = (row.f_tablebase - 0) - (row.f_last_tablebase - 0)
        // } else if ((row.f_tablebase - 0) == (row.f_last_tablebase - 0)) {
        //   row.charge_type = '正常收费'
        //   row.f_real_amount = 0
        // }
        row.f_operator = this.$login.f.name
        row.f_filiale = this.$login.f.f_fengongsi
        row.f_outlets = this.$login.f.f_parentname
        row.f_meter_state = '已抄表'
        if (this.handDate) {
          row.f_input_date = this.handDate
        }
        row.f_input_date = row.f_input_date ? row.f_input_date : Util.toStandardTimeString()
        row.f_last_input_date = row.f_last_input_date ? row.f_last_input_date : row.f_input_date
        row.f_operate_date = Util.toStandardTimeString()
        row.f_filialeids = this.$login.f.orgid
        row.f_orgid = this.$login.f.orgid
        row.f_orgname = this.$login.f.orgs
        row.f_depid = this.$login.f.depids
        row.f_depname = this.$login.f.deps
        row.f_operatorid = this.$login.f.id
        row.f_user_id = row.f_user_id + ''
        row.f_total_gas = row.total_gas
        row.f_total_fee = row.total_fee
        // 余气量=累购-(本期指数-表初始指数)
        console.log('录入完毕。。', row)
        this.$resetpost('rs/logic/cardCommonEnter', row, {resolveMsg: null, rejectMsg: '录入数据出错!!!'}).then((res) => {
          console.log('返回数据', res)
          row.id = res.data.id
          console.log('录入完数据的row值,,', row)
        }).catch((error) => {
          row.state = '失败'
          Vue.set(row, 'error', JSON.stringify(error))
        })
      } else {

      }
    },
    batchAudit () {
      // 批量审核
      console.log('录入完毕。。', this.model.condition)
      this.$resetpost('rs/logic/batchCardHandAudit', {
        data: {
          condition: this.model.condition,
          startDate: this.$refs.paged.$refs.criteria.model.startDate,
          endDate: this.$refs.paged.$refs.criteria.model.endDate
        }
      }, {resolveMsg: null, rejectMsg: '批量审核出错！！！'}, 0).then((res) => {
        if (res.data.f_state === '异常') {
          this.$showAlert(`本次审核有${res.data.handRepeatLength}户重复抄表，请处理后再进行审核操作!重复用户编号：${res.data.userRepeat}`, 'warning', 10000)
        } else {
          console.log('审核通过', res.data)
          this.$showAlert(`批量审核成功!!! 审核抄表数: ${res.data.total}, 成功条数: ${res.data.success}`, 'success', 4000)
          this.search()
        }
      })
    },
    modify (row) {
      // 录入错误进行修正
      co(modifyGen(this, row, 'rs/logic/cardhandnopass'))
    },
    pass (row) {
      co(modifyGen(this, row, 'rs/logic/cardhandpass'))
    },
    nopass (row) {
      co(modifyGen(this, row, 'rs/logic/cardhandnopass'))
    },
    cardhandCenter (row) {
      // let load = new HttpResetClass()
      // load.load('POST', 'rs/logic/Correct', {data: row}, {warnMsg: null, resolveMsg: null})
      // 抄表加入权限
      if (!this.$login.r.find(value => value == '卡表抄表冲正')) {
        this.$showMessage('当前登录用户没有冲正权限, 请联系管理员!')
        return
      }
      this.cardCental = true
      this.cardCentalData = row
    },
    cancel (row) {
      row.operatorInfo = {
        f_filiale: this.$login.f.f_fengongsi,
        f_outlets: this.$login.f.f_parentname,
        f_operator: this.$login.f.name,
        cardreason: this.cardreason
      }
      row.f_last_hand_date = row.f_last_input_date
      co(modifyGen(this, row, 'rs/logic/cardhandCancel'))
    },
    close () {
      this.cardCental = false
      this.cardCentalData = ''
      this.cardreason = ''
    },
    clearError (row) {
      if (row.f_tablebase === 0) {
        row.f_tablebase = ''
      }
      Vue.set(row, 'error', null)
    },
    // 删除这条计划
    delectHand (row) {
      this.$showMessage('删除后不可恢复，确认删除吗？', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          this.$resetpost('rs/logic/deleteCardPlan', {data: row}).then(() => {
            let condition = this.model.condition
            this.selfSearch({condition: condition})
          })
        }
      })
    },
    sort (field, rule) {
      // 将所有排序方式设为不排序，实现相互排斥
      for (let key in this.orderFields) {
        if (key === field) {
          this.orderFields[key] = rule
        } else {
          this.orderFields[key] = 'no'
        }
      }
      // 如果新规则不排序，还原为默认排序
      if (rule === 'no') {
        this.model.paramSource.orderitem = `'${this.orderitem}'`
      } else {
        this.model.paramSource.orderitem = `'${field} ${rule}'`
      }

      this.search()
    }
  },
  computed: {
    inputtore () {
      // 获取抄表员
      console.log('获取抄表员', this.$login.f)
      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.inputtores2 = rs
      return [...rs]
    },
    meterstates () {
      return [{label: '全部', value: ''}, {label: '未抄表', value: "= '未抄表'"}, {
        label: '已抄表',
        value: "= '已抄表'"
      }, {label: '冲正', value: "='冲正'"}]
    },
    specialuser () {
      return [{label: '全部', value: ''}, {label: '正常用户', value: "= '正常用户'"}, {label: '采暖户', value: "= '采暖户'"}]
    },
    usertypes () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
    },
    usetype () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('使用类型')]
    },
    userlevels () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户等级')]
    },
    smallareas () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('小区域')]
    },
    ventilationstate () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('通气手续')]
    },
    gasproperties () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
    },
    pricenames () {
      let arr = []
      AppData.getOnlyPrice().forEach((item) => {
        let temp = {}
        temp.label = item.label
        temp.value = item.value.f_price_name
        arr.push(temp)
      })
      return [{label: '全部', value: ''}, ...arr]
    },
    whetherpaies () {
      return [
        {label: '全部', value: ''},
        {label: '已缴费', value: '是'},
        {label: '未缴费', value: '否'}
      ]
    },
    // 界面细节权限
    jurisdiction () {
      return this.$login.r ? this.$login.r : []
    },
    brand () {
      return [{
        label: '全部',
        value: {f_meter_brand: '', gasmodel: [{label: '全部', value: {f_meter_style: ''}}]}
      }, ...AppData.getGasbrand()]
    }
  },
  events: {
    onFileUpload: function (file, res) {
      console.log('进入了抄表上传')
      let uuid = this.$login.guid()
      let data1 = {
        filepath: res.f_downloadpath,
        f_operator: this.$login.f.name,
        f_operatorid: this.$login.f.id,
        f_orgid: this.$login.f.orgid,
        f_orgname: this.$login.f.orgs,
        f_depid: this.$login.f.depids,
        f_depname: this.$login.f.deps,
        uuid: uuid
      }
      console.log('传入数据', data1)
      try {
        this.$resetpost('rs/handPlanAudit/cardBatchCommonEnter', data1, {resolveMsg: null, rejectMsg: null}, 1000)
      } catch (e) {
      }
      this.$showMessage(`正在批量处理中, 请耐心等待...`, [])
      // 启动定时器定时查询处理结果
      this.timer = setInterval(async () => {
        let res = await this.HttpReset.load('POST', 'rs/logic/getBatchOperaPro', {data: {uuid: uuid}}, {
          resolveMsg: null,
          rejectMsg: null
        })
        console.log('查询进度返回: ', res)
        if (res.data.msg || res.data.error) {
          clearInterval(this.timer)
          this.$closeMessage()
          if (res.data.error) {
            this.$showAlert(`${res.data.error}`, 'danger')
            return
          }
          await this.$showMessage(`处理总条数: ${res.data.n}, 成功${res.data.success}条, 失败${res.data.fail}条`)
          this.upshow = false
          this.search()
        }
      }, 5000)
    }
  }
}
</script>
<style lang="less">
#CardHand {
  thead {
    position: relative;
    z-index: 2;
  }
}
</style>
