<template xmlns:v-el="">
  <div class="flex-row">
    <div 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-6">-->
              <!--style="border: 1px solid #a6d5ea; box-shadow: darkgrey 1px 1px 1px 2px;padding: 0.5%">-->
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">归属起始</label>
                <datepicker placeholder="开始日期"
                            style="width:60%"
                            class="datepicker"
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">归属结束</label>
                <datepicker placeholder="结束日期"
                            style="width:60%"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            :format="'yyyy-MM-dd'"
                ></datepicker>
              </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_userinfo_code"
                       condition="f_userinfo_code='{}'" placeholder='客户编号'>
              </div>

              <div class="span" style="float:right;">

                <button class="button_search button_spacing" @click="$parent.$parent.estimaterclick0()">估表抄表</button>
                <button v-if="!$parent.$parent.saveenterflag" class="button_search button_spacing" @click="$parent.$parent.startestimaterall()">开始批量抄表</button>
                <button v-if="$parent.$parent.saveenterflag" class="button_clear button_spacing" @click="$parent.$parent.endestimaterall()">取消批量抄表</button>
                <button v-if="$parent.$parent.saveenterflag" class="button_search button_spacing" @click="$parent.$parent.estimaterallclick()">批量抄表保存</button>
                <button class="button_search button_spacing" @click="$parent.$parent.search()">查询</button>
                <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
                <button class="button_search button_spacing" @click="$parent.$parent.clickupshow()">导入抄表</button>
<!--                <button class="button_search button_spacing" @click="$parent.$parent.searchPrint()">导出信息Excel</button>-->

                <button v-if="$parent.$parent.meter_state" class="button_search button_spacing" @click="$parent.$parent.batchDownHand()">计划下发</button>
                <button v-if="$parent.$parent.inputtor_change" class="button_search button_spacing" @click="$parent.$parent.batchInputtorChange()">抄表员调整</button>

                <export-excel
                  :data="$parent.$parent.getCondition"
                  :field="$parent.$parent.getfield"
                  sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="periodAlreadyIssuedOrder" 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">表&ensp;编&ensp;号</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_id"
                       condition="f_user_id='{}'" 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" placeholder='客户姓名'
                       condition="f_user_name = '{}'">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">小&ensp;&ensp;&ensp;&ensp;区</label>
<!--                <v-select :value.sync="model.f_residential_area"-->
<!--                          class="select_list select"-->
<!--                          enter-push-->
<!--                          v-model="model.f_residential_area"-->
<!--                          style="width: 60%"-->
<!--                          multiple = "true"-->
<!--                          :options='$parent.$parent.residentialArea' placeholder='选择小区'-->
<!--                          close-on-select v-el:cc>-->
<!--                </v-select>-->
                <input type="text" style="width:60%" class="input_search" 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 type="text" style="width:60%" class="input_search" v-model="model.f_building"
                       condition="f_building = '{}'" placeholder='楼栋'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">单&emsp;&emsp;元</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_unit"
                       condition="f_unit = '{}'" placeholder='单元'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">楼&emsp;&emsp;层</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_floor"
                       condition="f_floor = '{}'" placeholder='楼层'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">门&ensp;牌&ensp;号</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_room"
                       condition="f_room = '{}'" 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">抄&ensp;表&ensp;员</label>
                <v-select :value.sync="model.f_inputtor" v-model='model.f_inputtor'
                          style="width:60%"
                          multiple="true"
                          :options='$parent.$parent.inputtores' placeholder='抄表员'
                          close-on-select
                          v-el:cc></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">是否缴费</label>
                <v-select :value.sync="model.f_whether_pay" v-model='model.f_whether_pay'
                          style="width:60%"
                          :options='$parent.$parent.whetherpaies' placeholder='是否缴费'
                          close-on-select
                          condition="f_whether_pay = '{}'"></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'
                          style="width:60%"
                          :options='$parent.$parent.meterstates' placeholder='抄表状态'
                          close-on-select
                          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.f_meter_classify" v-model="model.f_meter_classify"
                          style="width:60%"
                          :options='$parent.$parent.meters' placeholder='气表类型'
                          close-on-select
                          condition="f_meter_classify = '{}'"
                          default-value="'机表'"></v-select>
              </div>
              <div class="col-sm-2 form-group" >
                <label for="belongmonth" class="font_normal_body" >所属年月</label>
                <datepicker placeholder="所属年月" style="width:60%"
                            v-model="model.belongmonth"
                            :value.sync="model.belongmonth"
                            :format="'yyyy-MM'"
                            :show-reset-button="true"
                            condition="belongmonth = '{}'"
                            :select-month="true">
                </datepicker>
              </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='客户类型'
                          style="width:60%"
                          close-on-select
                          condition="f_user_type = '{}'"></v-select>
              </div>

              <div class="col-sm-2 form-group">
                <label class="font_normal_body">抄&ensp;表&ensp;册</label>
                <v-select :value.sync="model.f_meter_book" v-model="model.f_meter_book"
                          :options='$parent.$parent.meterbooks' placeholder='抄表册'
                          style="width:60%"
                          close-on-select
                          condition="f_meter_book_num = '{}'"></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">调压箱名</label>
                <v-select :value.sync="model.f_adjustable_name" v-model="model.f_adjustable_name"
                          :options='$parent.$parent.adjustablename' placeholder='调压箱名称'
                          style="width:60%"
                          close-on-select
                          condition="f_adjustable_name = '{}'"></v-select>
              </div>
              <res-select-group :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
              <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>
              <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>


          </div>
        </criteria>
        <data-grid :model="model" partial='list'   class="list_area table_sy"  v-ref:grid >
          <template partial='head'>
            <tr>
              <th><nobr>序号</nobr></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>表编号</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><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_hand_date" name="下发日期"
                                    :order.sync="$parent.$parent.$parent.orderFields.f_hand_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>
              <th><nobr><data-order field="f_book_name" name="抄表册"
                                    :order.sync="$parent.$parent.$parent.orderFields.f_book_name"></data-order></nobr>

              </th>
              <th><nobr>操作</nobr></th>
            </tr>
          </template>
          <template partial='body'>

            <td style="text-align: center;">{{$index + 1}}</td>
            <td>{{row.f_userinfo_code}}</td>
            <td>{{row.f_user_id}}</td>
            <td>{{row.f_user_name}}&nbsp;&nbsp;{{row.f_address}}</td>
            <td>{{row.f_user_level}}</td>
            <td>{{row.belongmonth}}</td>
            <td>{{row.f_adjustable_name}}</td>
            <td>{{row.f_inputtor}}</td>
            <td>{{row.f_balance}}</td>
            <td>{{row.f_last_input_date}}</td>
            <td>{{row.f_hand_date}}</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 && $parent.$parent.$parent.jurisdiction.includes('录入日期修正')">
                <datepicker id="endDate" 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>{{row.f_meter_base}}</td>
            <td>{{row.lastoutamount}}</td>
            <td>{{row.lastmeterstate}}</td>
            <td id="hand-creat">
              <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">

                <input title="只能录入整数" type="text" class="input_search" v-model="row.f_tablebase"
                       @blur="$parent.$parent.$parent.beforenter($index, row)"
                       v-next-el="{id: $index+2}" :id="$index+1" style="width: 100px;padding: 6px;"
                       @focus="$parent.$parent.$parent.clearError(row)"
                       :disabled="row.state === '开始'">
              </div>
              <div id="handManager" v-else>
              <span
                v-if="row.states === 0">{{row.f_tablebase || row.f_tablebase === 0 ? row.f_tablebase : '本期无计划'}}</span>
                <span
                  v-if="row.states === 1">{{row.f_tablebase || row.f_tablebase === 0 ? row.f_tablebase : '尚未下发'}}</span>
              </div>
              <span v-if="row.error" style="color: #ff0000;">{{row.error}}</span>
            </td>
            <td>
              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.deleteBattchEnter(row) "
                      v-if="row.f_tablebase!='' && $parent.$parent.$parent.saveenterflag">删除
              </button>
            </td>
            <td style="text-align: center;">{{Math.round(row.avggas)}}</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='抄表结果状态'
                          style="width:120%"
                          :value-single="true"
                          close-on-select></v-select>
              </div>
              <div  v-else>
                {{row.f_result_state}}
              </div>
            </td>
            <td style="text-align: center;">{{row.f_oughtfee}}</td>
            <td style="text-align: center;">{{row.f_debt_money}}</td>
            <td style="text-align: center;">{{row.f_oughtamount = row.f_tablebase ?
              (row.f_share_gas ?
              (row.f_tablebase - 0 - (row.f_meter_base - 0)).toFixed(4) + (row.f_share_gas > 0 ? '+' : '') + row.f_share_gas.toFixed(2) : (row.f_tablebase - 0 - (row.f_meter_base - 0)).toFixed(2)) : 0}}
            </td>
            <td style="text-align: center;">{{row.f_whether_pay}}</td>
            <td>{{row.f_book_name}}</td>
            <td style="text-align: center;">
              <button type="button" name="button" class="btn btn-link"
                      v-if="row.f_audit_state != '审核中'&& row.states === 1 && row.f_meter_state === '已抄表'  && row.f_oper_state === '正常' && (row.f_whether_pay === '否' ||  row.f_accounts_state === '自动下账')"
                      @click.stop="$parent.$parent.$parent.cancelHand2(row)">冲正
              </button>
                <button type="button" name="button" class="btn btn-link"
                        v-if="row.f_audit_state === '审核中' && $parent.$parent.$parent.jurisdiction.includes('抄表冲正审核')"
                        @click.stop="$parent.$parent.$parent.cancelHand4(row)">审核通过
                </button>
              <div   v-if="row.f_audit_state === '审核中' && !$parent.$parent.$parent.jurisdiction.includes('抄表冲正审核')">
                审核中
              </div>
              <button type="button" name="button" class="btn btn-link"
                      v-if="$parent.$parent.$parent.config.customCal && row.f_meter_state === '已抄表' && row.states === 1 && row.f_oper_state === '正常' &&  row.f_whether_pay === '否'"
                      @click.stop="$parent.$parent.$parent.fileterprice(row)">自定义划价
              </button>

              <button type="button" name="button" class="btn btn-link" disabled="disabled"
                      v-if="row.f_oper_state === '换表'">已换表
              </button>

              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.delectHand(row)  && row.states === 1"
                      v-if="row.f_meter_state === '未抄表' && row.states === 1">删除
              </button>

              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.downHand(row)"
                      v-if="row.f_meter_state === '未下发'">下发计划
              </button>
              <button type="button" name="button" class="btn btn-link"
                      v-if="row.f_meter_state === '待审核' ">待审核
              </button>

              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.pass(row)"
                      v-if="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 === '待审核' ">不通过
              </button>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <split-price :showdata="splitdata" :pricesplit="priceSplit" v-if="priceSplit" ></split-price>
      <modal :show.sync="show" 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">
          <form class="form-horizontal">
            <div class="row auto">
              <div class="form-group form-input-group col-sm-6">
                <label class="label-control">下发日期</label>
                <datepicker placeholder="下发日期" :value.sync="downModel.downDate"></datepicker>
              </div>
            </div>
            <div class="row auto">
              <div class="form-group form-input-group col-sm-3">
                <div class="col-sm-2"></div>
                <input type="radio" value="downWithUserfiles" v-model="downModel.downWay" checked>
                <label>表册抄表员</label>
              </div>
              <div class="form-group form-input-group col-sm-3">
                <input type="radio" value="downWithSelf" v-model="downModel.downWay">
                <label class="label-control">自定义抄表员</label>
              </div>
            </div>
            <div class="row auto" v-if="downModel.downWay === 'downWithSelf'">
              <div class="form-group form-input-group col-sm-6">
                <label class="label-control">抄表员</label>
                <div class="col-sm-4">
                  <v-select :value.sync="downModel.downInputtor" v-model='downModel.downInputtor'
                            :options='inputtores2' placeholder='抄表员'
                            close-on-select></v-select>
                </div>
              </div>
            </div>
          </form>
        </article>

        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-default" @click='close()'>取消</button>
          <button type="button" class="btn btn-success" @click='confirm()'>确认</button>
        </footer>
      </modal>
      <modal :show.sync="downConfirm" backdrop="false">
        <header slot="modal-header" class="modal-header">
          <h4 class="modal-title">下发确认</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <div class="col-sm-2 form-group">
            {{msg}}
          </div>
        </article>

        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-success" @click='downContinue'>继续下发</button>
          <button type="button" class="btn btn-success" @click='downFilter'>下发无抄表</button>
          <button type="button" class="btn btn-default" @click='close'>取消</button>
        </footer>
      </modal>

      <modal :show.sync="downConfirm" backdrop="false">
        <header slot="modal-header" class="modal-header">
          <h4 class="modal-title">下发确认</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <div class="col-sm-2 form-group">
            {{msg}}
          </div>
        </article>

        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-success" @click='downContinue'>继续下发</button>
          <button type="button" class="btn btn-success" @click='downFilter'>下发无抄表</button>
          <button type="button" class="btn btn-default" @click='close'>取消</button>
        </footer>
      </modal>
      <modal :show.sync="inputtor_show" backdrop="false">
        <header slot="modal-header" class="modal-header">
          <h4 class="modal-title">抄表员变更</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <form class="form-horizontal">
            <div class="row auto">
              <div class="form-group form-input-group col-sm-6">
                <label>调整客户数</label>
                <input class="input_search" v-model="model.count" disabled>
              </div>
            </div>
            <div class="row auto">
              <div class="form-group form-input-group col-sm-6">
                <label class="label-control">抄表员</label>
                <div class="col-sm-4">
                  <v-select :value.sync="inputtorModel.inputtor" v-model='inputtorModel.inputtor'
                            :options='inputtores2' placeholder='抄表员'
                            close-on-select></v-select>
                </div>
              </div>
            </div>
          </form>
        </article>

        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-success" @click='inputtorConfirm'>确认</button>
          <button type="button" class="btn btn-default" @click='close'>取消</button>
        </footer>
      </modal>

      <modal :show.sync="uploadshow" v-ref:modal backdrop="false">
        <header slot="modal-header" class="modal-header">
          <button type="button" class="close" @click="close"><span>&times;</span></button>
          <h4 class="modal-title">文件上传</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <div class="col-sm-2 form-group">
            <file-upload class="my-file-uploader" name="myFile"
                         action="rs/file/upload" tagname="文件上传" :headers="headers" multiple v-ref:file></file-upload>
          </div>
        </article>

        <footer slot="modal-footer" class="modal-footer">
          <!-- <button v-show="show" type="button" class="btn btn-default" @click='close'>取消</button>
          <button v-show="show" type="button" class="btn btn-success" @click='confirm(filename)'>确认</button> -->
        </footer>
      </modal>
        <modal :show.sync="examineshow" v-ref:modal backdrop="false">
            <header slot="modal-header" class="modal-header">
                <button type="button" class="close" @click="close"><span>&times;</span></button>
                <h4 class="modal-title">冲正审核</h4>
            </header>
            <article slot="modal-body" class="modal-body">
                <div class = "row">
                    <div class="col-sm-12 form-group">
                        <label class="font_normal_body">冲正原因</label>
                        <input type="text" style="width:90%" class="input_search" :disabled="examinetype" v-model="examinerow.f_examinereason"
                               placeholder='冲正原因'>
                    </div>
                    <upload :blodid="examinerow.id" v-ref:upload  :fusetype="uploadText" isremark="true" style="width:auto" ></upload>
                </div>

            </article>

            <footer slot="modal-footer" class="modal-footer">
                 <button v-show="examineshow" type="button" class="btn btn-default" @click='close'>取消</button>
                <button v-show="!examinetype" type="button" class="btn btn-success" @click='examineconfirm()'>确认</button>
                <button type="button" v-show="examinetype" class="btn btn-success" @click='cancelHand5()'>审核通过</button>
            </footer>
        </modal>

      <modal :show.sync="showerr" backdrop="false">
        <header slot="modal-header" class="modal-header">
          <button type="button" class="close" @click="closeerr"><span>&times;</span></button>
          <h4 class="modal-title">抄表出错！</h4>
        </header>
        <article slot="modal-body" class="modal-body">
          <div class = "row">
            <p> {{err}}</p>
            <input type="text" class="form-control" @blur="paycodefocus" v-el:paycode>
          </div>

        </article>

        <footer slot="modal-footer" class="modal-footer">
          <button v-show="showerr" type="button" class="btn btn-default" @click='closeerr'>关闭</button>
        </footer>
      </modal>
    </div>
    <modal :show.sync="progressShow" v-ref:modal backdrop="true"  width="50%" style="width:auto;" >
      <header slot="modal-header" class="modal-header">
        估表抄表
      </header>
      <article slot="modal-body" class="modal-body">
        <div  style="margin: 20px" >
          <p>正在进行估表抄表，请耐心等待...</p>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-default" @click='progressclose'>关闭</button>
      </footer>
    </modal>
    <modal :show.sync="progressShow2" v-ref:modal backdrop="true"  width="50%" style="width:auto;" >
      <header slot="modal-header" class="modal-header">
        批量抄表
      </header>
      <article slot="modal-body" class="modal-body">
        <div  style="margin: 20px" >
          <p>正在进行批量抄表，请耐心等待...</p>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-default" @click='progressclose'>关闭</button>
      </footer>
    </modal>
    <work-busy :is-busy="iswork" v-show="iswork"></work-busy>
  </div>
</template>
<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import Vue from 'vue'
  import co from 'co'
  import axios from 'axios'

  let readyGen = async function (self) {
    await self.$getConfig(self, 'HandManager')
    await self.$LoadParams.loadMeterBook(self.f_filialeid)
    self.loadMeterBooks()
    self.getfield = self.config.excelHeaders
    self.reflash()
  }

  let downGen = function *(type, condition, data, self) {
    self.condition = condition
    self.msg = '确认下发计划'
    // 判断之前是否有未抄表数据
    let getUnhand = null
    if (type === 'single') {
      getUnhand = yield Vue.resetpost('rs/sql/getUnhand', {
        data: {
          startDate: self.model.params.startDate,
          condition: condition
        }
      }, {resolveMsg: null, rejectMsg: '获取未抄表数据异常!!'})
      self.msg = `下发客户编号为${data.f_userinfo_code}的抄表计划？`
      // } else if (type === 'all') {
    } else if (type === 'batch') {
      let tempCondition = condition.replace("and f_meter_state = '未下发'", '')
      getUnhand = yield Vue.resetpost('rs/sql/getUnhand', {
        data: {
          startDate: self.model.params.startDate,
          condition: tempCondition
        }
      }, {resolveMsg: null, rejectMsg: '获取未抄表数据异常!!'})
      self.msg = `确认下发当前总计:  ${data}  户计划`
    }
    for (let i = 0; i < getUnhand.data.length; i++) {
      let temp = {
        id: getUnhand.data[i].id,
        f_user_id: getUnhand.data[i].f_user_id,
        f_userfiles_id: getUnhand.data[i].f_userfiles_id,
        f_adjustable_id: getUnhand.data[i].f_adjustable_id,
        f_adjustable_name: getUnhand.data[i].f_adjustable_name
      }
      console.log('=================================================================================')
      console.log('下发计划查看调压箱和调压箱编号', temp)
      console.log('========================================================================================')
      self.unhandplan.push(temp)
    }
    if (getUnhand.data.length > 0) {
      self.msg = self.msg + `, 警告: 之前有 ${getUnhand.data.length} 条未抄表数据`
    }
    self.show = true
  }

  let beforenterGen = async function (self, index, row) {
    // 验证是不是总表
    // self.enter(index, row)
    if (row.f_totalsplit_type === '总表') {
      let hasUnHand = await self.$HandService.getSplitInfo(row.f_userfiles_id)
      if (hasUnHand) {
        self.$showAlert('该表下面有未抄或未审核的分表信息！！请先抄录或审核分表信息！', 'danger', 0)
        row.f_tablebase = null
      } else {
        self.enter(index, row)
      }
    } else {
      self.enter(index, row)
    }
  }

  let inputtotChangeGen = async function (self) {
    let param = {
      f_change_content: self.inputtorModel.inputtor[0],
      f_change_cause: self.inputtorModel.reason,
      condition: self.model.condition,
      startDate: self.model.params.startDate,
      endDate: self.model.params.endDate,
      f_operator: self.$login.f.name,
      f_change_count: self.model.count,
      f_change_type: '抄表员变更',
      // f_input_person: self.$login.f.name,
      f_operatorid: self.$login.f.id,
      f_orgid: self.$login.f.orgid,
      f_orgname: self.$login.f.orgs,
      f_depid: self.$login.f.depids,
      f_depname: self.$login.f.deps
    }
    console.log('抄表单抄表员变更', param)
    await self.$resetpost('rs/logic/changeInputtor', param, {resolveMsg: null, rejectMsg: '批量抄表员变更失败'})
    self.$showAlert(`总计变更 ${self.model.count} 户抄表员为 ${self.inputtorModel.inputtor[0]}`, 'success', 2000)
    self.inputtor_show = false
    self.initModal()
    self.reflash()
  }

  let paramsdata = function(self){
    //将本条记录中所有只放入需抄表值
    if(self.$refs.paged.$refs.grid.model.rows.length>0){
      self.$refs.paged.$refs.grid.model.rows.forEach(item=>{
        let param = {
          f_meter_classify: item.f_meter_classify,
          f_meter_brand: item.f_meter_brand,
          f_hand_id: item.id,
          f_operator: Vue.$login.f.name,
          f_tablebase: item.f_meter_base,
          f_userinfo_id: item.f_userinfo_id,
          f_userinfo_code:item.f_userinfo_code
        };
        item.f_tablebase = item.f_meter_base;
        self.metertneterarr.push(param);
      })
    }
  }

  export default {
    title: '估表抄表',
    data () {
      return {
        progressShow:false,
        progressShow2:false,
        percent:0,
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        orgCondtionStr: '',
        priceSplit: false,
        criteriaShow: false,
        model: new PagedList('rs/sql/EstimateperiodAlreadyIssuedOrder', 30, {orderitem: this.orderDefault ? '"' + this.orderDefault + ' "' : `'id'`}),
        config: {

          // 导出列要和查询列相同
          excelHeaders: {
            'f_user_id': '表编号',
            'f_inputtor': '抄表员',
            'f_balance': '上期结余',
            'f_last_input_date': '上次抄表',
            'f_hand_date': '下发时间',
            'f_input_date': '抄表日期',
            'f_userinfo_code': '客户编号',
            'f_address': '客户地址',
            'f_residential_area': '小区名称',
            'f_user_name': '客户姓名',
            'f_meter_base': '上期底数',
            'f_tablebase': '本期指数',
            'f_oughtfee': '应交金额',
            'f_oughtamount': '应交气量',
            'f_whether_pay': '是否缴费',
            'f_book_name': '抄表册',
            'f_meter_classify': '气表分类',
            'f_price_type': '气价类型',
            'f_price_name': '气价名称',
            'f_meter_type': '气表类型',
            'f_meter_style': '气表型号',
            'f_accounts_state': '下账标识',
            'f_user_phone': '客户电话',
            'f_adjustable_id': '表箱号'
          },
          examine: true,
          customCal: false
        },
        meter_state: false, // 是否显示计划下发按钮
        downModel: {
          downDate: Vue.$login.toStandardTimeString(),
          downWay: 'downWithUserfiles',
          downInputtor: []
        },
        inputtor_change: false, // 是否显示抄表员变更按钮
        inputtor_show: false, // 控制抄表员变更模板
        inputtorModel: {
          inputtor: [],
          reason: ''
        },
        plans: [], // 记录当前行是否被勾选
        all: false, // 是否全选
        show: false, // 下发日期模态框显示
        unhandplan: [], // 之前是否有未抄表记录
        downConfirm: false, // 下发若有未抄记录，确认框
        uploadshow: false,
        // 小区
        // residentialArea: [],

        msg: '',
        condition: '',
        headers: {'username': Vue.$login.f.name, 'blodid': Vue.$login.guid()},
        orderDefault: 'id',
        orderFields: {
          f_userinfo_id: 'no'
        },
        getfield: {},
        outlet: '',
        filiale: '',
        condition2: '',
        area: [],
        inputtouPerson: [],
        meters: [{label: '全部', value: ''}, {label: '机表', value: '机表'}, {label: '物联网表', value: '物联网表'}],
        resultstate: this.$appdata.getParam('抄表结果状态'),
        meterstates: this.$appdata.getParam('抄表状态') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('抄表状态')] : [],
        usertypes: this.$appdata.getParam('客户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('客户类型')] : [],
        userlevels: this.$appdata.getParam('用户等级') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户等级')] : [],
        adjustablename: this.$appdata.getParam('调压箱名称') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('调压箱名称')] : [],
        inputtores2: [], // 下发时使用自定义抄表员,
        splitdata: '',
        f_filialeid: this.$login.f.orgid,
        meterbooks: [{label: '全部', value: ''}],
        upshow: false,
        inputid: 0,
        examineshow: false,
        examinerow: null,
        showfiles: false,
        uploadText: '抄表',
        examinetype: false,
        showerr: false,
        err: '',
        searchOrderstr: '',
        iswork: false,
        metertneterarr:[],  //保存批量抄表数据
        saveenterflag:false,
        timer:'',
      }
    },
    ready () {
      // this.getaddress()
      readyGen(this)
    },
    mounted () {
      console.log(this.inputid)
      document.getElementById(this.inputid).focus()
    },
    methods: {
      deleteBattchEnter(row){
        if(this.saveenterflag){
          this.metertneterarr.forEach(item=>{
            if(item.f_hand_id == row.id){
              row.f_tablebase=0;
              this.metertneterarr.pop(item);
            }
          })
          this.$showAlert('删除成功','success',1500);
        }
      },
      progressclose(){
        this.progressShow = false;
        this.progressShow2 = false;
        if(this.timer != null){
          clearInterval(this.timer);
        }
      },
      getuuid(){
        let uuidA = '';
        var s = [];
        var hexDigits = '0123456789abcdef';
        for (var i = 0; i < 36; i++) {
          s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = '4';
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
        s[8] = s[13] = s[18] = s[23] = '-';
        uuidA = s.join('');
        this.uuida = uuidA;
      },
      async startestimaterall(){
        if(this.$refs.paged.$refs.criteria.model.f_meter_state != '未抄表'){
          this.$showAlert('请选择抄表状态为未抄表开始批量抄表!', 'warning', 2000)
        }else{
          await this.search();
          this.$showMessage("本页未抄表数据以上期底数存为待抄表数据，是否继续？",['confirm','cancel']).then(res=>{
            if(res == 'confirm'){
              paramsdata(this);
            }
          })
          this.saveenterflag = true;
        }
      },
      endestimaterall(){
        this.$showMessage("正在进行批量录入抄表，确认后录入数据将丢失是否继续?",['confirm','cancel']).then(res=>{
            if(res == 'confirm'){
              this.saveenterflag = false;
              this.metertneterarr = [];
            }
        });
      },
      //批量抄表
      estimaterallclick(){
        if(!this.saveenterflag || this.metertneterarr.length <=0){
          this.$showAlert('无任何批量抄表数据，无法进行批量抄表，请录入后进行点击此按钮','warning',2000);
          return;
        }
        this.$showMessage("是否要进行批量估表抄表保存?",['confirm','cancel']).then(res=>{
            if(res == 'confirm'){
              this.meterenterallsave();
            }
        })
      },
      meterenterallsave(){
        this.$showMessage(`将进行抄表${this.metertneterarr.length}条,是否继续?`, ['confirm', 'cancel']).then(async (res) => {
          if(res == 'confirm'){
            this.getuuid();
            let param = {
              info: this.metertneterarr,
              modeluser : {
                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: this.uuida
            }
            try{
              await this.$resetpost('rs/logic/estimateCommonEnternoSQL',{data: param},{resolveMsg: null, rejectMsg: null},1000).then((res)=>{
                if(res.data){
                }
              })
            }catch(error){}
            let getparam = {
              uuid: this.uuida
            }
            let self = this;
            this.progressShow2=true;
            this.timer = setInterval(function(){
              self.$resetpost('/rs/logic/getBatchOperaPro',{data:getparam},{resolveMsg: null, rejectMsg: null}, 0).then((res)=>{
                if(res.data ){
                  if(res.data.msg ){
                    self.progressclose();
                    self.metertneterarr=[];
                    self.saveenterflag=false;
                    self.$showMessage(res.data.msg);
                    self.search();
                  }
                }
              });
            },3000);
          }
        });

      },
      estimaterclick0(){
        if(this.saveenterflag){
          this.$showMessage("正在进行批量录入抄表，确认后将退出批量抄表并且录入数据将丢失是否继续?",['confirm','cancel']).then(res=>{
            if(res == 'confirm'){
              this.metertneterarr =[];
              this.saveenterflag=false;
              this.estimaterclick();
            }else{
              return;
            }
          })
        }
      },
      // 估表抄表
      async estimaterclick () {

        if(this.$refs.paged.$refs.criteria.model.f_meter_state != '未抄表'){
          this.$showAlert('请选择抄表状态为未抄表进行估表抄表!', 'warning', 2000)
          return
        }
        await this.search()
        if (this.searchOrderstr == '') {
          this.$showAlert('请选择点击查询后进行估表抄表!', 'warning', 2000)
          return
        }
        // 2. 查询有多少需要进行估表抄表
        if (this.model.rows.length <=0 ) {
          this.$showAlert('当前无需要估表抄表数据!', 'warning', 2000)
          return
        }
        // 是否有需要估表抄表的
        if (this.model.count < 1) {
          this.$showAlert('当前无需要估表抄表数据!', 'warning', 2000)
          return
        }
        // 进行估表抄表
        this.$showMessage(`将进行估表抄表${this.model.count}户,是否继续?`, ['confirm', 'cancel']).then(async (res) => {
          if (res == 'confirm') {
            this.percent = 0;
            this.getuuid();
              let param = {
                info: this.getCondition,
                modeluser : {
                  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: this.uuida
              }
              try{
                await this.$resetpost('rs/logic/estimateCommonEnter',{data: param},{resolveMsg: null, rejectMsg: null},1000).then((res)=>{
                  if(res.data){
                  }
                })
              }catch(error){}
              let getparam = {
                uuid: this.uuida
              }
              let self = this;
              this.progressShow=true;
              this.timer = setInterval(function(){
                self.$resetpost('/rs/logic/getBatchOperaPro',{data:getparam},{resolveMsg: null, rejectMsg: null}, 0).then((res)=>{
                  if(res.data ){
                    if(res.data.msg ){
                      self.progressclose();
                      self.$showMessage(res.data.msg);
                      self.search();
                    }
                  }
                });
              },3000);
          }
        })
      },
      paycodefocus () {
        this.$nextTick(() => {
          this.$els.paycode.focus()
        })
      },
      getRes (obj) {
        this.orgCondtionStr = obj
      },
      // async  getaddress () {
      //   console.log('开始获取小区')
      //   let HttpReset = new HttpResetClass()
      //   var data = await HttpReset.load('POST', 'rs/sql/manage_getarealist', {
      //     data: {
      //       condition: `1=1 and s.f_filialeid = '${this.$login.f.orgid}'`
      //     }
      //   }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
      //   console.log('小区', data)
      //   let house = []
      //   house.push()
      //   for (let row of data.data) {
      //     console.log('开始保存小区')
      //     house.push({label: row.f_residential_area, value: row.f_residential_area})
      //   }
      //   this.residentialArea = house
      // },
      loadMeterBooks () {
        this.meterbooks = [...this.meterbooks, ...this.$GetSaleParam.getMeterBooks()]
      },

      fileterprice (row) {
        this.splitdata = row
        this.priceSplit = true
        console.log('row==>', row)
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      clear () {
        Object.keys(this.$refs.paged.$refs.criteria.model).forEach((key) => {
          this.$refs.paged.$refs.criteria.model[key] = []
        })
        this.$refs.paged.$refs.criteria.model.f_meter_classify = ['机表']
      },

      // 判断当前页是否全选
      isChooseAll (rows) {
        if (this.plans.length == 0 && rows.length == 0) {
          return false
        }
        for (var i = 0; i < rows.length; i++) {
          let flag = false
          if (rows[i].f_meter_state == '未下发') {
            for (let plan of this.plans) {
              if (plan.id == rows[i].f_userfiles_id) {
                flag = true
                if (!plan.state) {
                  return false
                }
              }
            }
            if (!flag) {
              return false
            }
          }
        }
        return true
      },
      // 选择需要下发的计划
      chooseOne (e, row, rows) {
        console.log('row', row)
        let checked = e.target.checked
        console.log('state', e.target.checked)
        // 判断当前行是否被选中
        if (checked) {
          let onePlan = {
            id: row.f_userfiles_id,
            state: true
          }
          // 记录被选中计划的状态
          let flag = false
          for (let plan of this.plans) {
            if (plan.id == row.f_userfiles_id) {
              flag = true
              plan.state = true
            }
          }
          if (!flag) {
            this.plans.push(onePlan)
          }
        } else {
          for (let plan of this.plans) {
            if (plan.id == row.f_userfiles_id) {
              plan.state = false
            }
          }
        }
        // let param = {id:row.id,isChoose:true}

        if (this.isChooseAll(rows)) {
          this.all = true
        } else {
          this.all = false
        }
        // this.delRepetition()
      },
      uploadFiles () {
        this.showfiles = !this.showfiles
      },
      chooseAll () {
        if (this.all) {
          for (let row of this.model.rows) {
            if (row.f_meter_state == '未下发') {
              let onePlan = {
                id: row.f_userfiles_id,
                state: true
              }
              let flag = false
              for (let plan of this.plans) {
                if (plan.id == row.f_userfiles_id) {
                  flag = true
                  plan.state = true
                }
              }
              if (!flag) {
                this.plans.push(onePlan)
              }
            }
          }
        } else {
          // this.chooseInfo[index-1] = []
          // console.log("this.chooseInfo[index-1]",this.chooseInfo[index-1])
          for (let row of this.model.rows) {
            if (row.f_meter_state == '未下发') {
              for (let plan of this.plans) {
                if (plan.id == row.f_userfiles_id) {
                  plan.state = false
                }
              }
            }
          }
        }
      },
      search () {
        // 查询前清空选择项
        this.plans = []
        this.$refs.paged.$refs.criteria.search()
      },
      clickupshow () {
        this.upshow = !this.upshow
      },
      searchPrint () {
        console.log('mode', this.model)
        let cons = this.model.params
        let data = {
          'body': {
            'data': {
              'condition': ''
            },
            'field': [],
            'templateName': '',
            'sqlName': ''
          },
          'condition': cons,
          'sqlname': 'periodAlreadyIssuedOrder'
        }
        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'))
            })
          }
        })
      },
      selfSearch (args) {
        if(this.saveenterflag){
          this.$showMessage("是否重新查询，重新查询后本次未保存抄表结果将丢失，是否继续？",['confirm','cancel']).then(res=>{
            if(res != 'confirm'){
              return;
            }else{
              this.metertneterarr=[];
              this.saveenterflag = false;
              this.searchnew(args);
            }
          })
        }else{
          this.searchnew(args);
        }

      },
      searchnew(args){
        this.meter_state = args.condition.includes('未下发')
        this.inputtor_change = args.condition.includes('未抄表')

        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + ' and f_orgid = ' + this.$login.f.orgid
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }

        // 抄表员查询条件
        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, ``)
          // 查询多个抄表员时条件
          args.condition += ` and f_inputtor in  ( ${str} )`
        }

        if (args.model.f_meter_brand && args.model.f_meter_brand.length > 0) {
          if (args.model.f_meter_brand[0].f_meter_brand) {
            args.condition = `${args.condition} and f_meter_brand = '${args.model.f_meter_brand[0].f_meter_brand}'`
          }
        }
        this.model.params.startDate = this.$refs.paged.$refs.criteria.model.startDate
        this.model.params.endDate = this.$refs.paged.$refs.criteria.model.endDate
        this.condition2 = args.condition
        console.log('selfsearch..', args.condition, this.model)
        this.searchOrderstr = args.condition
        this.model.search(args.condition, this.model)
      },
      reflash () {
        this.$refs.paged.$refs.criteria.model.f_orgid = `${Vue.$login.f.orgid}`
        this.$refs.paged.$refs.criteria.model.startDate = this.$login.toStartAndEndDateString()[0]
        this.$refs.paged.$refs.criteria.model.endDate = this.$login.toStartAndEndDateString()[1]
        //this.search()
      },
      beforenter (index, row) {
        this.inputid = index + 1
        // 限制本次抄表不能低于上次
        if (row.f_tablebase) {
          if (row.f_tablebase - parseInt(row.f_tablebase) !== 0) {
            row.state = '失败'
            Vue.set(row, 'error', '底数只能输入整数')
            this.speckText('底数只能输入整数，请注意!')
          } else if (row.f_tablebase < row.f_meter_base) {
            row.state = '失败'
            Vue.set(row, 'error', '本期表底数不能低于上期表底数')
            this.speckText('本期表底数不能低于上期表底数，请注意!')
          } else {
            beforenterGen(this, index, row)
          }
        }
      },
      enter (index, row) {
        console.log('录入数据。..', row)
        if (this.$appdata.getSingleValue('抄表审核') === '启用') {
          let f_input_date = Vue.$login.toStandardDateString()
          if (row.f_input_date && row.f_input_date != '') {
            f_input_date = row.f_input_date
          }
          let handplan = {
            id: row.id,
            f_oughtamount: row.f_oughtamount,
            f_tablebase: row.f_tablebase,
            f_hand_date: row.f_hand_date,
            f_input_date: f_input_date,
            f_input_person: Vue.$login.f.name,
            f_meter_state: '待审核',
            f_meter_source: '手动录入',

            f_operator: Vue.$login.f.name,
            f_operatorid: Vue.$login.f.id,
            f_orgid: Vue.$login.f.orgid,
            f_orgname: Vue.$login.f.orgs,
            f_depid: Vue.$login.f.depids,
            f_depname: Vue.$login.f.deps

          }
          console.log('抄表负数。。0', handplan)
          this.$resetpost('rs/entity/t_handplan', handplan, {
            resolveMsg: null,
            rejectMsg: '抄表数据保存出错!!!'
          }).then((res) => {
            row.f_meter_state = '待审核'
            row.f_whether_pay = '否'
            row.f_input_date = res.data.f_input_date
            this.$parent.search()
          }).catch((error) => {
            row.state = '失败'
            Vue.set(row, 'error', JSON.stringify(error))
            this.speckText('抄表录入出错，请注意!')
          })
        } else {
          // 没有启用抄表审核功能
          row.f_input_person = this.$login.f.name
          row.f_inputtor = row.f_inputtor
          row.f_userinfo_id = row.f_userinfo_id + ''
          row.f_userfiles_id = row.f_userfiles_id + ''
          this.pass(row)
        }
      },
      pass (row) {
        let param = {
          f_meter_classify: row.f_meter_classify,
          f_meter_brand: row.f_meter_brand,
          f_hand_id: row.id,
          f_operator: Vue.$login.f.name,
          f_tablebase: row.f_tablebase,
          f_userinfo_id: row.f_userinfo_id,
          f_userinfo_code:row.f_userinfo_code
        }
        //判断是否要进行批量抄表
        if(this.saveenterflag){
          let flag =false;
          this.metertneterarr.forEach(item=>{
            if(item.f_hand_id == param.f_hand_id){
              flag=true;
              item.f_tablebase = param.f_tablebase;
            }
          })
          if(!flag){
            this.metertneterarr.push(param);
          }
        }else{
          this.$resetpost('rs/logic/sale_commonEnter', {data: param}, {resolveMsg: null, rejectMsg: null}).then((res) => {
            row.f_meter_state = res.data.f_meter_state
            row.f_whether_pay = res.data.f_whether_pay
            let f_result_state = '估表'
            if (row.f_result_state && row.f_result_state != '') {
              f_result_state = row.f_result_state
            }
            let f_input_date = ''
            if (row.f_input_date && row.f_input_date != '') {
              f_input_date = ` ,f_input_date = '${row.f_input_date}'`
            }
            let sqldata = `update t_handplan set f_result_state = '${f_result_state}' ${f_input_date} where id = '${row.id}'`
            this.$resetpost('rs/logic/runSQL', {data: {sql: sqldata}}, {resolveMsg: null, rejectMsg: '业务单号保存失败'})
          }).catch((error) => {
            row.state = '失败'
            Vue.set(row, 'error', JSON.stringify(error))
            this.speckText('抄表出错，请注意!')
          })
        }
      },
      nopass (row) {
        console.log('不通过。。。', row)
        let handplan = {
          id: row.id,
          f_oughtamount: 0,
          f_tablebase: 0,
          f_input_date: null,
          f_meter_state: '未抄表',
          f_meter_source: null
        }
        this.$resetpost('rs/entity/t_handplan', handplan, {
          resolveMsg: null,
          rejectMsg: '未通过，抄表数据返回未抄表保存出错!!!'
        }).then((res) => {
          row.f_tablebase = null
          row.f_meter_state = '未抄表'
          row.f_whether_pay = '否'
          this.search()
        }).catch((error) => {
          row.state = '失败'
          Vue.set(row, 'error', JSON.stringify(error))
          this.speckText('抄表录入出错，请注意!')
        })
      },
      clearError (row) {
        if (row.f_tablebase === 0) {
          row.f_tablebase = ''
        }
        Vue.set(row, 'error', null)
      },
      async speckText (str) {
        var url = 'http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=6&text=' + encodeURI(str)
        await new Audio(url).play()
        this.err = str
        this.showerr = true
        this.paycodefocus()
      },
      closeerr () {
        this.showerr = false
      },
      fileUpload () {
        this.uploadshow = true
      },
      // 删除这条计划
      delectHand (row) {
        this.$showMessage('删除后不可恢复，确认删除吗？', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            this.$resetpost('rs/logic/deletePlan', {data: row}).then(() => {
              this.$dispatch('refresh', '删除计划', row)
              this.search()
            })
          }
        })
      },
      cancelHand4 (row) {
        this.examinerow = row
        this.examineshow = true
        this.examinetype = true
      },
      cancelHand2 (row) {
        if (this.config.examine) {
          let handdate = new Date(row.f_hand_date)
          console.log('获取月份', handdate.getMonth())
          let ima = new Date()
          console.log('获取月份', ima.getMonth())
          if (handdate.getMonth() == ima.getMonth()) {
            this.cancelHand3(row)
          } else {
            if (!this.$login.r.find(value => value == '抄表隔月冲正')) {
              this.$showMessage('当前登录用户没有隔月冲正权限, 请联系管理员!')
            } else {
              this.cancelHand3(row)
            }
          }
        } else {
          this.cancelHand3(row)
        }
      },
      async cancelHand5 () {
        let sqldata = `update t_handplan set f_audit_state ='已审核',f_audit_person='${this.$login.f.name}',
        f_audit_date='${this.$login.toStandardTimeString()}' where  id ='${this.examinerow.id}'`
        await this.$resetpost('rs/logic/runSQL', {data: {sql: sqldata}}, {resolveMsg: null, rejectMsg: '更新收费记录订单号失败'})

        this.cancelHand3(this.examinerow)
      },
      cancelHand3 (row) {
        // 抄表加入权限
        if (!this.$login.r.find(value => value == '机表抄表冲正')) {
          this.$showMessage('当前登录用户没有冲正权限, 请联系管理员!')
          return
        }
        console.log('抄表冲正。、。。、', row)
        let param = {
          f_hand_id: row.id,
          operInfo: {
            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
          }
        }
        let url = 'rs/logic/sale_commonEnterCancel'
        this.$resetpost(url, {data: param}, {warnMsg: '确定对这条记录进行撤销吗？'}).then(() => {
          this.search()
          this.close()
        })
      },
      down (type, condition, data) {
        co(downGen(type, condition, data, this))
      },
      // 单条下发计划
      downHand (row) {
        console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' + row.f_userfiles_id)
        this.down('single', `f_userfiles_id = '${row.f_userfiles_id}'`, row)
      },
      // 批量下发计划
      batchDownHand () {
        this.down('batch', this.model.condition, this.model.count)
      },
      batchInputtorChange () {
        this.inputtor_show = true
      },
      inputtorConfirm () {
        this.$showMessage(`确认变更前请确认选择的时间区间和查询条件是否正确，确认变更当前 ${this.model.count} 户抄表员`, ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            inputtotChangeGen(this)
          }
        })
      },
      confirm () {
        // 正式提交下发
        // 进行日期校验,判断下发的日期是否属于选择的归属期内
        console.log('下发日期校验', this.downModel, this.$refs.paged.$refs.criteria.model)
        if (this.validateDate()) {
          this.show = false
          if (this.unhandplan.length > 0) {
            this.downConfirm = true
          } else {
            this.confirmDownHand()
          }
        } else {
          this.$showAlert('您选择的下发时间不在归属期内, 请重新选择下发时间', 'warning', 3000)
        }
      },
      validateDate () {
        let currentDown = new Date(this.downModel.downDate)
        console.log(new Date(this.$refs.paged.$refs.criteria.model.startDate))
        console.log(new Date(this.$refs.paged.$refs.criteria.model.endDate))
        return currentDown >= new Date(this.$refs.paged.$refs.criteria.model.startDate + ' 00:00:00') && currentDown <= new Date(this.$refs.paged.$refs.criteria.model.endDate + ' 23:59:59')
      },

      downContinue () {
        this.downConfirm = false
        this.confirmDownHand()
      },
      downFilter () {
        this.downConfirm = false
        console.log('过滤有未抄记录的抄表')
        let filterUser = ''
        for (let json of this.unhandplan) {
          filterUser += `'${json.f_userfiles_id}',`
        }
        filterUser = filterUser.slice(0, filterUser.length - 1)
        this.condition = this.condition + ` and  f_userfiles_id not in (${filterUser})`
        console.log('获取新的条件。', this.condition)
        this.confirmDownHand()
      },
      confirmDownHand () {
        console.log('下发数据。。', this.downModel)
        let param = {
          downDate: this.downModel.downDate,
          startDate: this.model.params.startDate,
          endDate: this.model.params.endDate,
          condition: this.condition,
          f_operator: this.$login.f.name,
          f_operatorid: this.$login.f.id
        }
        if (this.downModel.downWay === 'downWithSelf') {
          param.inputtor = this.downModel.downInputtor[0]
        }
        console.log('下发参数：', param)
        this.$resetpost('rs/logic/downHand', {data: param}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          // 将缓存的未抄表ID数组置空
          this.unhandplan = []
          this.initModal()
          this.search()
          this.$showAlert(`全部下发,总计下发${res.data}户`, 'success', 2000)
        }).catch((error) => {
          this.$showAlert(`下发失败,请注意查看，失败原因：${error}`, 'danger', 0)
        })
      },
      async examineconfirm () {
        let sqldata = `update t_handplan set f_audit_state ='审核中',f_examinereason='${this.examinerow.f_examinereason}' where  id ='${this.examinerow.id}'`
        await this.$resetpost('rs/logic/runSQL', {data: {sql: sqldata}}, {resolveMsg: null, rejectMsg: null})
        this.close()
        this.search()
      },
      // 关闭下发计划得弹出框
      close () {
        this.show = false
        this.inputtor_show = false
        this.downConfirm = false
        this.examineshow = false
        this.examinetype = false
        // 初始化模态框数据
        this.initModal()
        if (this.uploadshow) {
          this.uploadshow = false
          // 讲选的文件清空
          this.$refs.file.$el.querySelector('input').value = ''
        }
      },
      initModal () {
        this.downModel = {
          downDate: Vue.$login.toStandardDateString(),
          downWay: 'downWithUserfiles',
          downInputtor: []
        }
        this.inputtorModel = {
          inputtor: [],
          reason: ''
        }
      },
      // 判断当前登陆人是不是子公司的人员
      isHead () {
        return this.$login.f.parent.parent.name.includes('统一资源管理')
      },
      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.orderDefault}'`
        } else {
          this.model.paramSource.orderitem = `'${field} ${rule}'`
        }
        this.search()
      }
    },
    watch: {
      'downModel.downWay' (val) {
        if (val === 'downWithSelf') {
          console.log('抄表员。。', this.inputtores2)
          if (this.inputtores2.length > 0) {
            this.downModel.downInputtor = [this.inputtores2[0].value]
          }
        }
      }
    },
    computed: {
      // 使用类型获取
      usetype () {
        return this.$appdata.getParam('使用类型')
      },
      getCondition () {
        // return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
        return {startDate: this.$refs.paged.$refs.criteria.model.startDate,
          endDate: this.$refs.paged.$refs.criteria.model.endDate,
          orderitem: this.orderDefault ? this.orderDefault : 'id',
          condition: this.condition2}
      },

      inputtores () {
        // 获取抄表员
        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]
      },
      whetherpaies () {
        return [
          {label: '全部', value: ''},
          {label: '已缴费', value: '是'},
          {label: '未缴费', value: '否'}
        ]
      },
      // 界面细节权限
      jurisdiction () {
        console.log('抄表界面细节', this.$login.r)
        return this.$login.r ? this.$login.r : []
      },
      firestates () {
        return [
          {label: '全部', value: ''},
          {label: '已点火', value: '1'},
          {label: '未点火', value: '0'}
        ]
      },
      ischecked () {
        return function (row) {
          for (let plan of this.plans) {
            if (plan.id == row.f_userfiles_id) {
              return plan.state
            }
          }
        }
      }
    },
    events: {
      onFileUpload: function (file, res) {
        if (this.upshow) {
          let data = {
            model: {
              f_operator: this.$login.f.name,
              f_end_date: this.$login.nextMonth20(this.$login.toStandardTimeString())
            },
            filepath: res.f_downloadpath
          }
          let http2 = new HttpResetClass()
          http2.load('POST', 'rs/logic/batchSettleFileupdate', data, {resolveMsg: null, rejectMsg: '上传失败'})
          this.uploadshow = false
          try {
            this.$showAlert(`文件上传成功,正在后台批量结算......`, 'success', 2000)
          } catch (error) {
            console.log('抄表已经超时请求(不影响其他!)')
          }
          // this.$showMessage(`一共上传${res.data.allsize}条数据, 成功${res.data.size}条, 失败下发${filenum}条`+";;失败数据:"+res.data.error.join(",")+";;抄表数过低数据:"+res.data.error2.join(",")+";;用气量超过2000: "+res.data.infoData.join(","));
          this.$parent.search()
          this.batchMeterShow = false
        //   })
          return
        }
        let data = {
          model: {
            f_operator: this.$login.f.name,
            f_end_date: this.$login.nextMonth20(this.$login.toStandardTimeString())
          },
          filepath: res.path
        }
        if (res.f_downloadpath.includes('抄表数据')) {
          console.log('进入了抄表上传')
          let data1 = {
            filepath: res.f_downloadpath
          }
          this.$resetpost('rs/logic/upLoadHand', data1, {resolveMsg: null, rejectMsg: '上传失败'}, 0).then((res) => {
            // console.log('终于成功了', res)
            this.upshow = false
            // this.$showAlert(`一共上传${res.data.total}条数据, 成功${res.data.successnum}条, 未抄下发${res.data.nohandnum}条, 失败下发${res.data.failednum}条, 异常下发${res.data.exceptionnum}条`, 'success', 2000)
            // this.$parent.search()
          })
        } else if (data.filepath.includes('先锋')) {
          this.$resetpost('rs/logic/xfimport', data, {resolveMsg: null, rejectMsg: '上传失败'}, 0).then((res) => {
            // console.log('终于成功了', res)
            this.uploadshow = false
            this.$showAlert(`一共上传${res.data.total}条数据, 成功${res.data.successnum}条, 未抄下发${res.data.nohandnum}条, 失败下发${res.data.failednum}条, 异常下发${res.data.exceptionnum}条`, 'success', 2000)
            this.$parent.search()
          })
        } else if (data.filepath.includes('伦力')) {
          this.$resetpost('rs/logic/llimport', data, {resolveMsg: null, rejectMsg: '上传失败'}, 0).then((res) => {
            // console.log('终于成功了', res)
            this.uploadshow = false
            this.$showAlert(`一共上传${res.data.total}条数据, 成功${res.data.successnum}条, 未抄下发${res.data.nohandnum}条, 失败下发${res.data.failednum}条, 异常下发${res.data.exceptionnum}条`, 'success', 2000)
            this.$parent.search()
          })
        }
      }
    }
  }
</script>
<style lang="less" scoped>
  #handManager {
    display: flex;
    justify-content: space-around;
    align-items: center;
    .btn {
      margin: 0px;
    }
  }

  .hand-loading {
    border: 3px solid #ccc;
    border-right-color: #337ab7;
    border-radius: 50%;
    animation: spin 0.6s linear;
    position: absolute;
    animation-iteration-count: infinite;
    top: 0;
    right: 50%;
    z-index: 2;
    display: block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    pointer-events: none;
  }

  @keyframes spin {
    100% {
      transform: rotate(360deg);
    }
  }
</style>
