<template>
  <div class="flex-row" id="machineHandManager">
    <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:filebattch :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 color-red">归属起始</label>
                <datepicker placeholder="开始日期"
                            style="width:60%"
                            class="datepicker"
                            v-model="model.startDate"
                            condition="f_hand_date >='{} 00:00:00'"

                            :value.sync="model.startDate"
                            :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body color-red">归属结束</label>
                <datepicker placeholder="结束日期"
                            style="width:60%"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            condition="f_hand_date <='{} 23:59:59'"
                            :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 v-if="$parent.$parent.jurisdiction.includes('单户抄表')"
                  class="button_search button_spacing" style="width:90px" @click="$parent.$parent.danhuShow()">
                  单户抄表
                </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_delete button_spacing"  @click="$parent.$parent.deletehand()">删除抄表</button>
                <button  class="button_search button_spacing" style="width: 90px" @click="$parent.$parent.downloadFiles()">模板下载
                </button>
                <button class="button_search button_spacing" @click="$parent.$parent.clickupshow()">导入抄表</button>

                <export-excel
                  :data="$parent.$parent.getCondition"
                  :field="$parent.$parent.getfield"
                  sqlurl="rs/logic/saleExport" sql-name="getPlan" 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>
                <v-select :value.sync="model.f_audit_state"
                          class="select_list select"
                          v-model="model.f_audit_state"
                          style="width: 60%"
                          condition="f_meter_state = '{}'"
                          :options='$parent.$parent.auditState' placeholder='抄表状态'
                          close-on-select v-el:cc>
                </v-select>
              </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_meternumber"
                       condition="f_meternumber like '%{}%'" placeholder='表号'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户姓名</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_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>
              </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 like '%{}%'" placeholder='门牌号'>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户地址</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_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 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">用户等级</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="font_normal_body color-red">抄&ensp;表&ensp;册</label>
                <v-select :value.sync="model.f_meter_book" v-model="model.f_meter_book"
                          :options='$parent.$parent.meterbooks' placeholder='抄表册'
                          :multiple="true"
                          style="width:60%"
                          condition="f_meter_book_num in {}"></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>
              <div class="col-sm-2 flex-row" style="white-space: nowrap" >
                <label  class="font_normal_body">应交气量</label>
                <div class="row">
                  <input type="text" style="width:30%" class="input_search" v-model="model.oughtamountmin"
                         condition="f_oughtamount >= {} " placeholder="">
                  <label   class="font_normal_body">  ≤ x ≤ </label>
                  <input type="text" style="width:30%" class="input_search" v-model="model.oughtamountmax"
                         condition="f_oughtamount <= {} " placeholder="">
                </div>
              </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>
                <datepicker placeholder="开始日期"
                            style="width:60%"
                            class="datepicker"
                            v-model="model.startDate1"
                            condition="f_input_date >='{} 00:00:00'"

                            :value.sync="model.startDate1"
                            :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.endDate1"
                            :value.sync="model.endDate1"
                            condition="f_input_date <='{} 23:59:59'"
                            :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
            </div>


            <!-- 多选框 -->
            <!--<div class="col-sm-2 form-group">-->
            <!--<button class="btn btn-success" @click="$parent.$parent.batchDownHand()">计划下发</button>-->
            <!--</div>-->

            <!--<div class="form-group" v-if="$parent.$parent.meter_state">-->
            <!--<button class="btn btn-success" @click="$parent.$parent.allDownHand()" >全部下发</button>-->
            <!--</div>-->
            <!-- 多选框结束 -->

            <!--<div class="col-sm-2 form-group">-->
            <!--<button class="btn btn-success" @click="$parent.$parent.adjust()">抄表员调整</button>-->
            <!--</div>-->
            <!--<div class="col-sm-2 form-group">-->
            <!--<button class="btn btn-success" @click="$parent.$parent.fileUpload()">文件上传</button>-->
            <!--</div>-->
            <!--<div class="col-sm-2 form-group">-->
            <!--<button class="btn btn-success" @click="search(), $parent.$parent.clean()">打印</button>-->
            <!--</div>-->

          </div>
        </criteria>
        <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid id="hand_manager_grid">
          <template partial='head'>
            <tr>
              <!--<th><input type='checkbox' v-model="$parent.$parent.$parent.all" @change="$parent.$parent.$parent.chooseAll"></th>-->
              <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>&emsp;&emsp;小区&emsp;&emsp;</nobr>
              </th>
              <!--              <th>基本信息</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><data-order field="f_building" name="楼号"-->
              <!--:order.sync="$parent.$parent.$parent.orderFields.f_building"></data-order></nobr>-->
              <!--</th>-->
              <!--<th><nobr><data-order field="f_unit" name="单元号"-->
              <!--:order.sync="$parent.$parent.$parent.orderFields.f_unit"></data-order></nobr>-->
              <!--</th>-->
              <!--<th><nobr><data-order field="f_room" name="房号"-->
              <!--:order.sync="$parent.$parent.$parent.orderFields.f_room"></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>上次抄表日期</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>下发日期</th>-->
              <th>
                <nobr>
                  <data-order field="f_hand_date" name="下发日期"
                              :order.sync="$parent.$parent.$parent.orderFields.f_hand_date"></data-order>
                </nobr>
              </th>
              <!--              <th>抄表日期</th>-->
              <th>
                <nobr>
                  <data-order field="f_input_date" name="抄表录入日期"
                              :order.sync="$parent.$parent.$parent.orderFields.f_input_date"></data-order>
                </nobr>
              </th>
              <!--              <th>抄表册</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>
              <th>
                <nobr>抄表员</nobr>
              </th>
              <th>
                <nobr>录入人员</nobr>
              </th>
              <th>
                <nobr>下发人员</nobr>
              </th>
              <th>
                <nobr>操作</nobr>
              </th>
              <!--            f_oughtfee-->
            </tr>
          </template>
          <template partial='body'>
            <!--<td style="text-align: center;">-->
            <!--<input  v-if="row.f_meter_state === '未下发'"-->
            <!--:id="model.pageIndex" type='checkbox' @change="$parent.$parent.$parent.chooseOne($event,row,model.rows)"-->
            <!--:checked="$parent.$parent.$parent.ischecked(row)"/>-->
            <!--</td>-->
            <td style="text-align: center;">{{$index + 1}}</td>
            <td>{{row.f_userinfo_code}}</td>
            <td style="width: 200px">{{row.area}}</td>
            <td>{{row.f_user_name}}&nbsp;&nbsp;{{row.f_address}}</td>
            <td>{{row.f_user_level}}</td>
            <!--<td>{{row.f_building}}</td>-->
            <!--<td>{{row.f_unit}}</td>-->
            <!--<td>{{row.f_room}}</td>-->
            <td>{{row.belongmonth}}</td>
            <td style="text-align: center;">{{row.f_balance}}</td>
            <td style="text-align: center;">{{Math.round(row.avggas)}}</td>
            <td>{{row.f_meternumber}}</td>
            <td>{{row.f_last_tablebase}}</td>
            <td id="hand-creat" v-if="row.f_meter_state === '未抄表' && row.crossyear && $parent.$parent.$parent.config.crossyear ">
              <div class="form-group" style="margin-bottom:0px;display: contents;" :class="{
                       'has-success has-feedback': !row.error,
                       'has-error has-feedback': row.error}"
              >
                <button type="button" name="button" class="btn btn-link"

                        @click.stop="$parent.$parent.$parent.yearhand(row) "
                >跨年抄表
                </button>
<!--                <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>

              <span v-if="row.error && row.error !== ''" style="color: #ff0000;">{{row.error}}</span>
            </td>
            <td id="hand-creat" v-if="row.f_meter_state === '未抄表' && ! row.crossyear ">
              <div class="form-group" style="margin-bottom:0px;display: contents;" :class="{
                       'has-success has-feedback': !row.error,
                       'has-error has-feedback': row.error}"
              >

                <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>

              <span v-if="row.error && row.error !== ''" style="color: #ff0000;">{{row.error}}</span>
            </td>
            <td id="hand-creat" v-if="row.f_meter_state !== '未抄表' ">
              {{row.f_tablebase}}
            </td>
            <!--<td style="text-align: center;" v-if="row.f_oughtamount">{{ row.f_oughtamount }}</td>-->
            <td style="text-align: center;">{{$parent.$parent.$parent.calculationBase(row)}}</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 === '未抄表' && row.states !== 0 && $parent.$parent.$parent.jurisdiction.includes('增量录入')">
                <input title="只能录入整数" type="number" class="input_search" v-model="row.f_adjustment_volume"
                       style="width: 100px;padding: 6px;"
                       :disabled="row.state === '开始'">
              </div>
              <div v-else>
                {{row.f_adjustment_volume}}
              </div>
            </td>
            <td style="text-align: center;">{{row.f_oughtfee}}</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="margin-right:90px" width="100%"
                          :value-single="true"
                          close-on-select
                          condition="f_adjustable_name = '{}'"></v-select>
                <!-- <span id="inputError2Status" class="sr-only">(error)</span> -->
              </div>
              <div style="text-align: center;" v-else>
                {{row.f_result_state}}
              </div>
            </td>
            <td style="text-align: center;">{{row.f_whether_pay}}</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_book_name}}</td>
            <td>{{row.f_adjustable_name}}</td>
            <td>{{row.f_inputtor}}</td>
            <td>{{row.f_input_person}}</td>
            <td>{{row.f_operator}}</td>
            <td style="text-align: center;"><nobr>
              <!-- 已抄表，还没审核-->
              <button type="button" name="button" class="button_search button_spacing width-60"
                      v-if="row.f_meter_state === '待审核' && (row.id == row.maxid || !row.maxid)"
                      @click.stop="$parent.$parent.$parent.cancelAuditHand(row)">撤销
              </button>
              <!-- 未抄表，删除计划,直接删表内数据-->
              <button type="button" name="button" class="btn btn-danger"
                      v-if="row.f_meter_state === '未抄表'"
                      @click.stop="$parent.$parent.$parent.delectHand(row)  && row.states === 1"
              >删除
              </button>
              <!-- 已抄表，已审核，冲正（状态改为冲正,添加负记录，需要重新下发）-->
              <button type="button" name="button" class="button_search button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.cancelHand(row)"
                      v-if="row.f_meter_state === '已抄表' && row.maxid==row.id && (row.f_whether_pay === '否' ||  row.f_accounts_state === '自动下账' || (row.f_whether_pay === '是'))" >冲正
              </button>

              <!--              <button type="button" name="button" class="btn btn-link"-->
              <!--                      v-if="row.f_meter_state === '待审核' ">待审核-->
              <!--              </button>-->


            </nobr>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <table class="table-hover">
        <tr style="position: relative" class="table-bordered">
          <td
            style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">
            汇总信息
          </td>
          <td
            style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
            应缴气量:&emsp;{{sumsmodel.f_oughtamount}}
          </td>
          <td
            style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
            应缴金额:&emsp;{{sumsmodel.f_oughtfee}}
          </td>
        </tr>
      </table>
      <split-price :showdata="splitdata" :pricesplit="priceSplit" v-if="priceSplit"></split-price>

      <modal :show.sync="danhu.show" :title='danhutitle' backdrop="false" coverstyle="danhumodal">
        <article slot="modal-body" class="modal-body">
          <div class="panel panel-primary datapanel">
            <div class="row">
              <label class="control-label col-sm-6 flex-row" style="transform: translate(0,8px)">客户姓名：{{danhu.info.f_user_name}}</label>
              <label class="control-label col-sm-6 flex-row" style="transform: translate(0,8px)">客户编号：{{danhu.info.f_userinfo_code}}</label>
              <label class="control-label col-sm-6 flex-row" style="transform: translate(0,8px)">用户证号：{{danhu.info.f_book_no}}</label>
              <label class="control-label col-sm-12 flex-row" style="transform: translate(0,8px)">客户地址：{{danhu.info.f_address}}</label>
              <label class="control-label col-sm-6 flex-row" style="transform: translate(0,8px)">上次抄表日期：{{danhu.info.f_hand_date}}</label>
              <label class="control-label col-sm-6 flex-row" style="transform: translate(0,8px)">上期底数：{{danhu.info.f_tablebase}}</label>
            </div>
          </div>
          <div class="panel panel-primary datapanel">
            <div class="row">
              <div class="col-sm-6 flex-row" style="margin-top: 2px">
                <label for="danhucode" class="control-label" style="transform: translate(0,8px)">客户编号</label>
                <input id="danhucode" type="text" class="input_search " style="width: 60% !important;"
                       v-model="danhu.f_userinfo_code" v-ref:danhucode @keyup.enter.stop="danhuCodeSearch"
                       placeholder='客户编号'/>
              </div>
              <div class="col-sm-6 flex-row" style="margin-top: 2px">
                <label for="danhubase" class="control-label" style="transform: translate(0,8px)">本期底数</label>
                <input id="danhubase" type="number" class="input_search " style="width: 60% !important;"
                       v-model="danhu.f_tablebase" @keyup.enter.stop="downAndHand"
                       placeholder='本期底数'/>
              </div>
            </div>
          </div>
        </article>
        <footer slot="modal-footer">
        </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="showstair" 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">
            <div class="form-group col-sm-12">
              <label class="col-xs-2 col-sm-2 col-md-2 form-group">本期表底数</label>
              <div class="col-xs-4 col-sm-4 col-md-4 form-group">
                <input  type="number" class="form-control show-font" v-model="row.f_tablebase"  width="80%" @blur="getamount(row)" placeholder="本期表底数" maxlength="10">
              </div>

            </div>
            <div  class="form-group col-sm-12">
              <label class="col-xs-2 col-sm-2 col-md-2 form-group">用气量</label>
              <div class="col-xs-4 col-sm-4 col-md-4 form-group">
                <input  type="number" class="form-control show-font" v-model="row.f_oughtamount"  width="80%" disabled placeholder="用气量" maxlength="10">
              </div>
            </div>

          <div v-for="(index,item) in stairdata" class="row">
            <div class="col-xs-2 col-sm-2 col-md-2 form-group">
              <span class="text-left font" style="color: darkblue">{{ item.year }}周期</span>
            </div>
            <div class="col-xs-4 col-sm-4 col-md-4 form-group">
              <input type="number" class="form-control show-font" v-model="item.f_dispensed_amount"  width="80%" placeholder="分配量(单位：方)" maxlength="10">
            </div>
            <div class="col-xs-4 col-sm-4 col-md-4 form-group">
              <input type="number" class="form-control show-font" v-model="item.f_dispensed_price" placeholder="金额（单位：元）" maxlength="10">
            </div>
          </div>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button  type="button" class="btn btn-default" @click='closeyear'>取消</button>
          <button  type="button" class="btn btn-default" @click='confirmyearhand'>确认</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>

      <modal :show.sync="detailsShow" v-ref:model_details backdrop="true" width="700px">
        <article slot="modal-body" class="modal-body">
          <div class="flex-row">
            <div style="width: 50%">
              <mix-price-info :data="row" v-if="row.f_price_type === '固定气价'" v-ref:mix_price></mix-price-info>
              <stairinfo :data="row" v-if="row.f_price_type === '阶梯气价'" v-ref:statir></stairinfo>
            </div>
            <div style="width: 50%" class="panel">
              <div class="panel-heading detail-panel">
                <h4>计算工具</h4>
              </div>
              <form class="form-horizontal" style="padding: 10px">
                <div class="form-group">
                  <label class="col-sm-4 col-md-4 control-label" style="text-align: left">预购金额:</label>
                  <div class="col-sm-8 col-md-8">
                    <input type="number" class="form-control" placeholder="预购金额" @blur="computeAmount" v-el:inputmoney>
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-4 col-md-4 control-label" style="text-align: left">当前底数:</label>
                  <div class="col-sm-8 col-md-8">
                    <input type="number" class="form-control" placeholder="当前底数" v-model="row.f_last_tablebase" disabled>
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-4 col-md-4 control-label" style="text-align: left">应抄底数:</label>
                  <div class="col-sm-8 col-md-8">
                    <input type="number" class="form-control" placeholder="应抄底数" v-model="should_base" disabled>
                  </div>
                </div>
                <div class="form-group">
                  <label class="col-sm-12 col-md-12 control-label" style="text-align: center">计算公式</label>
                  <div class="col-sm-12 col-md-12">
                    <input type="text" class="form-control" placeholder="计算公式" v-model="designFormulas" disabled>
                  </div>
                </div>
              </form>
            </div>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="button_search button_spacing" @click='customPricing()'>自定义划价</button>
        </footer>
      </modal>

      <modal :show.sync="priceModel" 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>
            <mix-price-info :data="row" v-if="row.f_price_type === '固定气价'" v-ref:mix_price></mix-price-info>
            <stairinfo :data="row" v-if="row.f_price_type === '阶梯气价'" v-ref:statir></stairinfo>
          </div>
          <div class="row">
            <template v-if="row.f_price_type === '固定气价'">
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">单价</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_price1" placeholder='单价'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">数量</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_gas1" placeholder='数量'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">金额</label>
                <p class="form-control" style="width:60%" disabled>{{ row.f_stair_money1 = stairMoney(row.f_stair_price1, row.f_stair_gas1) }}</p>
              </div>
            </template>

            <template v-if="row.f_price_type === '阶梯气价'">
              <div class="col-sm-4 form-group" >
                <label class="font_normal_body">阶梯一单价</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_price1" placeholder='阶梯一单价'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯一数量</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_gas1" placeholder='阶梯一数量'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯一金额</label>
                <p class="form-control" style="width:60%" disabled>{{ row.f_stair_money1 = stairMoney(row.f_stair_price1, row.f_stair_gas1) }}</p>
              </div>
              <div class="col-sm-4 form-group" >
                <label class="font_normal_body">阶梯二单价</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_price2" placeholder='阶梯二单价'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯二数量</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_gas2" placeholder='阶梯二数量'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯二金额</label>
                <p class="form-control" style="width:60%" disabled>{{ row.f_stair_money2 = stairMoney(row.f_stair_price2, row.f_stair_gas2) }}</p>
              </div>
              <div class="col-sm-4 form-group" >
                <label class="font_normal_body">阶梯三单价</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_price3" placeholder='阶梯三单价'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯三数量</label>
                <input type="text" class="form-control" style="width:60%" v-model="row.f_stair_gas3" placeholder='阶梯三数量'></input>
              </div>
              <div class="col-sm-4 form-group">
                <label class="font_normal_body">阶梯三金额</label>
                <p class="form-control" style="width:60%" disabled>{{ row.f_stair_money3 = stairMoney(row.f_stair_price3, row.f_stair_gas3) }}</p>
              </div>
            </template>
            <div class="col-sm-4 form-group" >
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">总用气量</label>
              <p class="form-control" style="width:60%" disabled>{{ ((row.f_stair_gas1 - 0)+(row.f_stair_gas2 - 0)+(row.f_stair_gas3 - 0)).toFixed(2) }}</p>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">总用气金额</label>
              <p class="form-control" style="width:60%" disabled>{{ row.f_oughtfee = ((row.f_stair_money1 - 0)+(row.f_stair_money2 - 0)+(row.f_stair_money3 - 0)).toFixed(2)  }}</p>
            </div>
            <p style="color: red">注意: 自定义气量总量必须等于本次抄表用气量, 本次抄表总量: {{row.f_oughtamount}}</p>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="button_clear button_spacing" @click="close()">取消</button>
          <button type="button" class="button_search button_spacing" @click='customPricingConfirm()'>确认</button>
        </footer>
      </modal>
    </div>
  </div>
</template>
<script>
  import MixPriceInfo from '../../components/revenue/base/leftview/MixPriceInfo'
  import {PagedList, HttpResetClass} from 'vue-client'
  import Vue from 'vue'
  import co from 'co'

  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.sumsmodel = self.$refs.paged.$refs.grid.model.sums
    self.reflash()
  }

  let downGen = function* (type, condition, data, self) {
    // if(data == 0 ) {
    //   self.$showAlert('下发计划户数为0！请选择需要下发的计划！！', 'danger', 0)
    //   return
    // }
    self.condition = condition
    self.msg = '确认下发计划'
    // 判断之前是否有未抄表数据
    let getUnhand = null
    // let getUnhand = yield Vue.resetpost('rs/sql/getUnhand', {data: {startDate: self.startDate, condition: self.condition}}, {resolveMsg: null, rejectMsg: '获取未抄表数据异常!!'})
    // if (type === 'batch' || type === 'single') {
    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)
    }
  }

  export default {
    title: '机表抄表',
    components: { MixPriceInfo },
    data () {
      return {
        priceModel: false,
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        showstair: false,
        stairdata: [],
        sumsmodel: [],
        orgCondtionStr: '',
        priceSplit: false,
        deletestate: false,
        criteriaShow: false,
        model: new PagedList('rs/sql/getPlan', 50, {orderitem: this.orderDefault ? '"' + this.orderDefault + ' "' : `'f_hand_date desc'`}, {
          f_oughtamount: 0,
          f_oughtfee: 0
        }),
        config: {
          crossyear: true,
          // 导出列要和查询列相同
          excelHeaders: {
            'f_user_id': '表编号',
            'f_meternumber': '表号',
            'f_inputtor': '抄表员',
            'f_balance': '上期结余',
            'f_last_input_date': '上次抄表',
            'f_hand_date': '下发时间',
            'f_input_date': '抄表日期',
            'f_userinfo_code': '客户编号',
            'f_address': '客户地址',
            'area': '小区名称',
            'f_user_name': '客户姓名',
            'f_last_tablebase': '上期底数',
            'f_tablebase': '本期指数',
            'f_oughtfee': '应交金额',
            'f_oughtamount': '应交气量',
            'f_whether_pay': '是否缴费',
            'f_book_name': '抄表册',
            'f_input_person': '录入人员',
            'f_operator': '下发人员',
            'f_meter_classify': '气表分类',
            '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: []
        },
        inputtorModel: {
          inputtor: [],
          reason: ''
        },
        auditState: [{label: '全部', value: ''}, {label: '未抄表', value: '未抄表'}, {label: '待审核', value: '待审核'}, {label: '已抄表', value: '已抄表'}],

        plans: [], // 记录当前行是否被勾选
        all: false, // 是否全选
        show: false, // 下发日期模态框显示
        unhandplan: [], // 之前是否有未抄表记录
        downConfirm: false, // 下发若有未抄记录，确认框
        uploadshow: false,
        // 小区
        residentialArea: [],

        //  downDate: this.$login.toStandardYearMonth().replace("-", ""),
        msg: '',
        condition: '',
        headers: {'username': Vue.$login.f.name, 'blodid': Vue.$login.guid()},
        orderDefault: 'f_hand_date',
        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: [],
        upshow: false,
        inputid: 0,
        examineshow: false,
        examinerow: null,
        showfiles: false,
        uploadText: '抄表',
        examinetype: false,
        danhu: {
          show: false,
          f_userinfo_code: '',
          f_tablebase: '',
          info: {}
        },
        showerr: false,
        err: '',
        // 请求对象(批量导入,查询进度使用)
        HttpReset: new HttpResetClass(),
        // 气价使用详情展示
        detailsShow: false,
        row: null,
        // 应抄底数
        should_base: 0,
        // 计算公式
        designFormulas: null,
        usermlimit: this.$appdata.getSingleValue('民用自动审核区间'),
        userfmlimit: this.$appdata.getSingleValue('非民用自动审核区间')
      }
    },
    ready () {
      this.getaddress()
      readyGen(this)
    },
    mounted () {
      console.log(this.inputid)
      document.getElementById(this.inputid).focus()
    },
    methods: {
      getamount (row) {
        if(row.f_tablebase<row.f_last_tablebase){
          this.$showMessage('本地底数小于上期底数')
        }else{
          row.f_oughtamount = (row.f_tablebase - 0) - (row.f_last_tablebase - 0)
        }
      },
      closeyear(){
        this.showstair =false
        this.row = null
      },
      confirmyearhand () {
        if (this.stairdata){
          let amount = 0
          let price = 0
          let f_oughtamount = this.row.f_oughtamount

          for (let i=0;i<this.stairdata.length;i++){
            console.log('qiliang----------------->',this.stairdata[i].f_dispensed_amount)
            if (this.stairdata[i].f_dispensed_amount && this.stairdata[i].f_dispensed_price){
              amount = amount + parseFloat(this.stairdata[i].f_dispensed_amount)
              console.log("amount-------->",amount)
              price = price + parseFloat(this.stairdata[i].f_dispensed_price)
              console.log("price-------->",price)
            }
          }

          console.log("amount--最后算的------>",amount)
          console.log("f_oughtamount--最后算的------>",f_oughtamount)

          if (f_oughtamount !== amount && amount >0){
            this.$showMessage('请重新录入分配气量')
            return
          }
        }
        this.row.dataArr = this.stairdata
        let url = 'rs/logic/yearCommonEnter'
        this.$resetpost(url, {data: this.row}, {warnMsg: '确定对这条记录进行抄表吗？'}).then(() => {
          this.search()
          this.showstair =false
          this.row = null
        })
      },
      yearhand (data) {
        this.stairdata = []
        this.row = data
        if (data.f_last_input_date) {
          console.log('核算时间----------', data.f_last_input_date)
          let date1 = data.f_last_input_date  // 上次抄表时间
          let date2 = new Date(Date.parse(date1)) // 上次抄表时间
          let date3 = new Date() // 当前时间
          let days = date3.getFullYear() - date2.getFullYear()
          console.log('年份差值----------->', days)
          if (days >= 1) {
            console.log('days大于1就进来')
            for (let i = 0; i <= days; i++) {
              let year = date2.getFullYear() + i
              console.log('加入的年份------->', year)
              let temp = {
                f_dispensed_amount: null,
                f_dispensed_price: null,
                year: year
              }
              this.stairdata.push(temp)
            }
            this.showstair = true
            console.log('数组长度---------->', this.stairdata)
          }
        }
      },
      stairMoney (price, gas) {
        return (price * gas).toFixed(2) - 0
      },
      async customPricingConfirm () {
        let sumGas = (this.row.f_stair_gas1 - 0) + (this.row.f_stair_gas2 - 0) + (this.row.f_stair_gas3 - 0)
        if (sumGas !== (this.row.f_oughtamount - 0)) {
          this.$showMessage('自定义划价总气量不符, 请检查')
          return
        }
        let row = {
          id: this.row.id,
          f_oughtfee: this.row.f_oughtfee,
          f_stair_price1: this.row.f_stair_price1,
          f_stair_gas1: this.row.f_stair_gas1,
          f_stair_money1: this.row.f_stair_money1,
          f_stair_price2: this.row.f_stair_price2,
          f_stair_gas2: this.row.f_stair_gas2,
          f_stair_money2: this.row.f_stair_money2,
          f_stair_price3: this.row.f_stair_price3,
          f_stair_gas3: this.row.f_stair_gas3,
          f_stair_money3: this.row.f_stair_money3
        }
        await this.$resetpost('rs/logic/customPricing', {data: row}, {resolveMsg: '保存成功', rejectMsg: '保存失败'}).then(res => {
          this.close()
          this.search()
        })
      },
      customPricing () {
        if (!this.$login.r.find(value => value == '抄表自定义划价')) {
          this.$showMessage('当前登录用户没有【抄表自定义划价】权限, 请联系管理员!')
          return
        }
        if (this.row.f_meter_state !== '已抄表') {
          this.$showMessage('当前抄表单不是已抄表状态,无法进行自定义划价!')
          return
        }
        if (this.row.f_whether_pay !== '否') {
          this.$showMessage('当前抄表单已经缴费,无法进行自定义划价!')
          return
        }
        this.detailsShow = false
        this.priceModel = true
      },
      downloadFiles () {
        let downurl = 'rs/downloadfile/file?filename=机表抄表导入Excel模板_zhongyi'
        this.$downFile(downurl, '机表抄表导入Excel模板.xlsx')
      },
      calculationBase (row) {
        let oughtamount = null
        if (row.f_tablebase) {
          if (row.f_share_gas) {
            oughtamount = (row.f_tablebase - 0 - (row.f_last_tablebase - 0)).toFixed(4) + (row.f_share_gas > 0 ? '+' : '') + row.f_share_gas.toFixed(2)
          } else {
            if (row.f_capacity && row.f_capacity > 0 && row.f_tablebase < row.f_last_tablebase) {
              oughtamount = (row.f_tablebase - 0 + (row.f_capacity - row.f_last_tablebase)).toFixed(2)
            } else {
              oughtamount = (row.f_tablebase - 0 - (row.f_last_tablebase - 0)).toFixed(2)
            }
          }
        } else {
          oughtamount = 0
        }
        row.f_oughtamount = oughtamount
        return oughtamount
      },
      cancelHand (row) {
        if (this.config.examine) {
          let handdate = new Date(row.f_hand_date)
          let ima = new Date()
          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)
        }
      },

      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()
        })
      },
      cancelAuditHand (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) => {
          this.search()
        })
      },
      async danhuCodeSearch () {
        this.danhu.f_userinfo_code = this.danhu.f_userinfo_code.replace(/(^\s*)|(\s*$)/g, '')
        await this.$resetpost('rs/sql/getInfoOfDanhu', {
          data: {
            f_userinfo_code: this.danhu.f_userinfo_code,
            f_orgid: this.f_filialeid
          }
        },
          {resolveMsg: null, rejectMsg: '查询用户信息失败，网络错误'}).then(res => {
            if (res.data.length !== 1) {
              this.$showAlert(res.data.length === 0 ? '没有查询到用户' : '查询到多条用户信息', 'warning', 3000)
              return
            }
            if (res.data[0].f_meter_state === '待审核') {
              this.$showAlert('用户有待审核的记录', 'warning', 3000)
              return
            }
            if (res.data[0].f_whether_pay === '否') {
              this.$showAlert('用户有未缴费的抄表记录', 'warning', 3000)
            }
            this.danhu.info = res.data[0]
          // = Object.assign(this.danhu,{info:res.data[0]})
            document.getElementById('danhubase').focus()
          })
      },
      // 单户抄表 下发计划并抄表
      async downAndHand () {
        if (!this.danhu.info.f_userinfo_code || this.danhu.info.f_userinfo_code === '') {
          this.$showAlert(`请先查询用户信息`, 'warning', 2000)
          return
        }

        if (this.danhu.f_tablebase < 0) {
          this.$showAlert(`底数不能小于0，请注意!`, 'warning', 2000)
          return
        } else if (this.danhu.f_tablebase - parseInt(this.danhu.f_tablebase) !== 0) {
          this.$showAlert(`底数只能输入整数，请注意!`, 'warning', 2000)
          return
        } else if (this.danhu.f_tablebase < this.danhu.info.f_tablebase && !this.danhu.info.f_capacity) {
          this.$showAlert(`本期表底数不能低于上期表底数`, 'warning', 2000)
          return
        } else {
          if (this.danhu.f_tablebase < this.danhu.info.f_tablebase) {
            this.$showMessage('本次抄表已超越最大量程, 请熟知!')
          }
        }
        let param = {
          downDate: this.downModel.downDate,
          startDate: this.model.params.startDate,
          endDate: this.model.params.endDate,
          condition: ` f_userfiles_id = '${this.danhu.info.f_userfiles_id}' `,
          f_operator: this.$login.f.name,
          f_operatorid: this.$login.f.id,
          danhu: true,
          userfilesid: this.danhu.info.f_userfiles_id
        }
        console.log('下发参数：', param)
        this.$resetpost('rs/logic/downHand', {data: param}, {resolveMsg: null, rejectMsg: '下发失败，请检查该用户是否在该归属期内已有抄表记录'}).then((res) => {
          console.log('下发计划成功', res)
          this.$resetpost('/rs/sql/querySingleTable', {
            data: {
              items: 'max(id) id',
              tablename: 't_handplan',
              condition: ` f_userfiles_id = '${this.danhu.info.f_userfiles_id}' `
            }
          }, {resolveMsg: null, rejectMsg: '查询抄表信息失败'}).then((res2) => {
            let handParam = {
              f_meter_classify: this.danhu.info.f_meter_classify,
              f_meter_brand: this.danhu.info.f_meter_brand,
              f_hand_id: res2.data[0].id,
              f_tablebase: this.danhu.f_tablebase,
              f_userinfo_id: this.danhu.info.f_userinfo_id
            }
            this.$resetpost('rs/logic/sale_commonEnter', {data: handParam}, {
              resolveMsg: null,
              rejectMsg: null
            })
          }).then((res) => {
            this.$showAlert(`单户抄表成功!`, 'success', 2000)
            this.danhuShow()
          }).catch((error) => {
            this.danhu.show = false
            this.$showAlert(`单户抄表失败!` + JSON.toString(error), 'danger', 2000)
          })
        }).catch((error) => {
          this.danhu.show = false
          this.$showAlert(`抄表失败,请注意查看，失败原因：` + JSON.toString(error), 'danger', 2000)
        })
      },
      // 获得本月的最后一天。
      getLastDayOfMonth (year, month) {
        let new_year = year    // 取当前的年份
        let new_month = month++// 取下一个月的第一天，方便计算（最后一天不固定）
        if (month > 12)            // 如果当前大于12月，则年份转到下一年
        {
          new_month -= 12        // 月份减
          new_year++            // 年份增
        }
        let new_date = new Date(new_year, new_month, 1)                // 取当年当月中的第一天
        let date_count = (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate()// 获取当月的天数
        // let last_date = new Date(new_date.getTime() - 1000 * 60 * 60 * 24);//获得当月最后一天的日期
        return date_count
      },
      danhuShow () {
        this.model.params.startDate = this.$refs.paged.$refs.criteria.model.startDate
        this.model.params.endDate = this.$refs.paged.$refs.criteria.model.endDate
        this.downModel.downDate = this.$login.toStandardTimeString()
        this.danhu = {
          show: true,
          f_userinfo_code: '',
          f_tablebase: '',
          info: {}
        }
        setTimeout(() => {
          document.getElementById('danhucode').focus()
          this.$refs.paged.$refs.criteria.search()
        }, 100)
      },
      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.$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] = []
        })
      },

      // 判断当前页是否全选
      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) {
          // this.chooseInfo[index-1] = []
          // for (let row of this.model.rows){
          //   this.chooseInfo[index-1].push(row)
          // }
          // this.chooseInfo = Object.assign([],this.chooseInfo,this.model.rows)

          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 () {
        if (!this.$login.r.find(value => value == '机表抄表导入抄表')) {
          this.$showMessage('你没有机表抄表导入抄表的权限,请联系管理员!')
          return
        }
        this.upshow = !this.upshow
      },
      deletehand () {
        if (!this.$login.r.find(value => value == '抄表计划删除')) {
          this.$showMessage('你没有【抄表计划删除】的权限,请联系管理员!')
        } else {
          if (this.deletestate) {
            console.log('mode', this.model)
            let cons = this.model.params
            this.$showMessage('删除后不可恢复，确认删除该批未抄表计划吗？', ['confirm', 'cancel']).then((res) => {
              if (res === 'confirm') {
                this.$resetpost('rs/logic/deletePlanAll', {data: cons}).then((res) => {
                  this.$dispatch('refresh', '删除计划', cons)
                  console.log('ressss:', res)
                  this.$showAlert(`共计删除${res.data.index}条记录`, 'success', 2000)
                  this.search()
                })
              }
            })
          } else {
            this.$showMessage('为保证误删操作，请先选择抄表单查询条件为未抄表，查询后，再点击删除计划按钮!')
          }
        }
      },
      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) {
        this.meter_state = args.condition.includes('未下发')
        this.inputtor_change = args.condition.includes('未抄表')
        console.log('=====抄表1====', args.condition.includes('未抄表'))
        console.log('=====抄表1====', this.deletestate)
        if (args.condition.includes('未抄表')) {
          this.deletestate = true
        } else {
          this.deletestate = false
        }
        console.log('=====抄表1====', this.deletestate)
        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, ``)
          console.log('=====抄表员model22222222222绑定====', str)
          // 查询多个抄表员时条件
          args.condition += ` and f_inputtor in  ( ${str} )`
        }
        // 小区查询条件
        this.area = this.$refs.paged.$refs.criteria.model.f_residential_area
        console.log('=====小区model绑定====', this.area)
        if (this.area.length !== 0) {
          let str = JSON.stringify(this.area)
          str = str.replace(/"/g, `'`)
          str = str.replace(/\[/g, ``)
          str = str.replace(/\]/g, ``)
          console.log('=====小区model22222222222绑定====', str)
          // 查询多个小区时条件
          args.condition += ` and f_residential_area 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.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 < 0) {
            row.state = '失败'
            Vue.set(row, 'error', '底数不能小于0')
            this.speckText('底数不能小于0，请注意!')
          } else if (row.f_tablebase - parseInt(row.f_tablebase) !== 0) {
            row.state = '失败'
            Vue.set(row, 'error', '底数只能输入整数')
            this.speckText('底数只能输入整数，请注意!')
          } else if (row.f_tablebase < row.f_last_tablebase && !row.f_capacity) {
            row.state = '失败'
            Vue.set(row, 'error', '本期表底数不能低于上期表底数')
            this.speckText('本期表底数不能低于上期表底数，请注意!')
          } else {
            if (row.f_tablebase < row.f_last_tablebase) {
              this.$showMessage('本次抄表已超越最大量程, 请熟知!')
            }
            // 抄表结果状态没选默认给正常
            row.f_result_state = row.f_result_state ? row.f_result_state : '正常'
            beforenterGen(this, index, row)
          }
        }
      },
      enter (index, row) {
        console.log('录入数据。..', row)
        let auditFlag = false
        let num = (row.f_tablebase - row.f_last_tablebase)
        let reg = /^\d+,\d+$/
        if (row.f_user_type === '民用' && this.usermlimit) {
          if (!reg.test(this.usermlimit)) {
            this.$showMessage('民用自动审核区间参数设置有误, 请检查!')
            return
          }
          let limit = this.usermlimit.split(',')
          if (!(limit[0] - 0 <= num && num <= limit[1] - 0)) {
            auditFlag = true
          }
        } else if (row.f_user_type === '非民用' && this.userfmlimit) {
          if (!reg.test(this.userfmlimit)) {
            this.$showMessage('非民用自动审核区间参数设置有误, 请检查!')
            return
          }
          let limit = this.userfmlimit.split(',')
          if (!(limit[0] - 0 <= num && num <= limit[1] - 0)) {
            auditFlag = true
          }
        } else if (this.$appdata.getSingleValue('抄表审核') === '启用') {
          auditFlag = true
        }
        if (auditFlag) {
          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_adjustment_volume: row.f_adjustment_volume ? row.f_adjustment_volume : 0,
            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.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_adjustment_volume: row.f_adjustment_volume ? row.f_adjustment_volume : 0
        }
        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
          row.f_oughtfee = res.data.f_oughtfee
          row.f_oughtamount = res.data.f_oughtamount
          // this.$resetpost('rs/logic/getMeterSms', {data: param}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          // this.search()
          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('抄表出错，请注意!')
          // })
          // this.search()
        }).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)
      },
      // batchDownHand () {
      //   this.condition = ''
      //   let count = 0
      //   for (let plan of this.plans){
      //     if(plan.state){
      //       this.condition = this.condition + plan.id + ','
      //       count = count + 1
      //     }
      //   }
      //   this.down('batch', `f_user_id in (${this.condition.substring(0,this.condition.length-1)})`,count)
      // },
      // allDownHand () {
      //   this.down('all', this.model.condition, this.model.count)
      // },

      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')
      },

      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.detailsShow = false
        this.priceModel = 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()
      },
      guid () {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          let r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8)
          return v.toString(16)
        })
      },
      computeAmount (event) {
        let money = event.target.value
        if (this.row.f_price_type === '固定气价') {
          let price = this.$refs.mix_price.model.f_price
          // 可以购买的总气量
          let purchaseSum = (money / price).toFixed(2)
          // 计算应抄底数
          this.should_base = (this.row.f_last_tablebase - 0) + (purchaseSum - 0)
          // 计算公式
          this.designFormulas = `${purchaseSum}X${price}`
        } else {
          let mydata = this.$refs.statir.mydata
          // 剩余1阶气量
          let surplus1 = (mydata.f_stair1ceiling - (mydata.f_hasuse1 > 0 ? mydata.f_hasuse1 : 0))
          // 把1阶买完的钱
          let price1 = surplus1 * mydata.f_stair1price
          // 剩余2阶气量
          let surplus2 = (mydata.f_stair2ceiling - mydata.f_stair1ceiling - (mydata.f_hasuse2 > 0 ? mydata.f_hasuse2 : 0)).toFixed(2)
          // 把2阶买完的钱
          let price2 = surplus2 * mydata.f_stair2price
          // 兼容一下
          if (this.$refs.statir.jt != 3) {
            this.$showMessage('暂不支持该气价类型的运算,请联系开发人员!')
          }
          // 开始计算
          // 可以购买各阶梯量
          let purchase1 = 0
          let purchase2 = 0
          let purchase3 = 0
          if (money <= price1) {
            purchase1 = (money / mydata.f_stair1price).toFixed(2)
          } else if (money <= (price1 + price2)) {
            purchase1 = surplus1
            purchase2 = ((money - price1) / mydata.f_stair2price).toFixed(2)
          } else {
            purchase1 = surplus1
            purchase2 = surplus2
            purchase3 = ((money - price1 - price2) / mydata.f_stair3price).toFixed(2)
          }
          // 可以购买的总气量
          let purchaseSum = (purchase1 - 0) + (purchase2 - 0) + (purchase3 - 0)
          // 计算应抄底数
          this.should_base = (this.row.f_last_tablebase - 0) + purchaseSum
          // 计算公式
          this.designFormulas = `${purchase1}X${mydata.f_stair1price} + ${purchase2}X${mydata.f_stair2price} + ${purchase3}X${mydata.f_stair3price}`
        }
        this.should_base = this.should_base.toFixed(2) - 0
      }
    },
    watch: {
      'downModel.downWay' (val) {
        if (val === 'downWithSelf') {
          console.log('抄表员。。', this.inputtores2)
          if (this.inputtores2.length > 0) {
            this.downModel.downInputtor = [this.inputtores2[0].value]
          }
        }
      },
      'detailsShow' (val) {
        if (!val) {
          this.should_base = 0
          this.designFormulas = null
          this.$els.inputmoney.value = 0
        }
      }
      // 'model.rows'(val){
      //   console.log('页面切换',val)
      //   if(this.isChooseAll(val)){
      //     this.all = true
      //   }else{
      //     this.all = false
      //   }
      // },
    },
    computed: {
      danhutitle () {
        return '单户抄表    当前计划年月：' + this.downModel.downDate
      },
      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: async function (file, res) {
        if (this.upshow) {
          let uuid = this.guid()
          let data = {
            model: {
              f_operator: this.$login.f.name,
              f_end_date: this.$login.nextMonth20(this.$login.toStandardTimeString()),
              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,
            filepath: res.f_downloadpath
          }
          try {
            await this.HttpReset.load('POST', 'rs/logic/batchSettleFileupdate', data, {resolveMsg: null, rejectMsg: null}, 1000)
          } catch (e) {}
          this.$showAlert(`文件上传成功,正在后台批量结算, 请耐心等待结果......`, 'success')
          // 启动定时器定时查询上传结果
          let 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) {
              res.data.msg ? this.$showAlert(`${res.data.msg}`, 'success', 2000) : this.$showAlert(`${res.data.error}`, 'danger')
              this.upshow = false
              this.search()
              clearInterval(timer)
            }
          }, 5000)
          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()
          })
        }
      },
      dblclick: function (row, index) {
        this.row = row
        this.detailsShow = true
      }
    }
  }
</script>
<style lang="less">
  #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);
      }
    }
    .detail-panel {
      text-align: center;
      color: #31708f;
      background-color: #e8f1f9;
      border-color: #F2F6FA;
    }
  }

  #hand_manager_grid {
    thead {
      position: relative;
      z-index: 2;
    }
  }
  #machineHandManager {
    .color-red {
      color: red;
    }
  }
</style>
