<template>
  <div class="basic-main" style="height: 98%">
    <div class="flex">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' v-ref:cri @condition-changed="$parent.selfSearch">
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <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"
                            condition="f_hand_date >='{} 00:00:00'"
                            :format="'yyyy-MM-dd'"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;&emsp;至&emsp;</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 class="button_search button_spacing" @click="$parent.$parent.search()">查询</button>
                <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
                <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">表&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_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">抄&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>

          </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>表编号</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>上次抄表日期</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>
              <!--            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>{{row.f_user_id}}</td>
            <td> <nobr>{{row.f_user_name}}&nbsp;&nbsp;{{row.f_address}} </nobr></td>
            <td>{{row.f_user_level}}</td>
            <!--<td>{{row.f_building}}</td>-->
            <!--<td>{{row.f_unit}}</td>-->
            <!--<td>{{row.f_room}}</td>-->
            <td>{{row.f_adjustable_name}}</td>
            <td>{{row.f_inputtor}}</td>
            <td>{{row.f_balacne}}</td>
            <td>{{row.f_meter_base}}</td>
            <td id="hand-creat">{{row.f_tablebase}}</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_oughtfee}}</td>
            <td>{{row.f_result_state}}</td>
            <td><nobr>{{row.f_last_input_date}}</nobr></td>
            <td><nobr>{{row.f_hand_date}}</nobr></td>
            <td><nobr>{{row.f_input_date}}</nobr></td>
            <td> <nobr>{{row.f_book_name}} </nobr></td>
            <td style="text-align: center;"><nobr>
              <img-self :src="row.f_handplan_image" v-if="row.f_handplan_image" :width="50" :height="50"></img-self>
              <img-self :src="`rs/image/file/${row.f_notified_path}`" v-if="row.f_notified_path" :width="100" :height="100"></img-self>
            </nobr></td>
            <td style="text-align: center;" class="row auto">
              <nobr>
              <button type="button" name="button" class="button_search button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.pass(row)"
                      v-if="row.f_meter_state === '待审核'">通过
              </button>

              <button type="button" name="button" class="button_search button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.nopass(row)"
                      v-if="row.f_meter_state === '待审核' ">不通过
              </button>
              </nobr>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
  <modal :show.sync="imgshow" v-ref:modal backdrop="true">
    <header slot="modal-header" class="modal-header">
      抄表图像识别照片
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="from-group">
        <img-self :src="imgfilename"   width="500" height="500"></img-self>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-success" @click='imgclose'>关闭</button>
    </footer>
  </modal>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
  import Vue from 'vue'
  import * as Util from '../../../Util'

  let readyGen = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate =  self.$login.toStartAndEndDateString()[0]
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
    await self.$LoadParams.loadMeterBook(self.f_filialeid)
    self.loadMeterBooks()
    self.getaddress()
  }

  export default {
    title: '卡表审核',
    data () {
      return {
        model: new PagedList('rs/sql/getAuditCardHand', 20),
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        imgfilename: '',
        // 小区
        residentialArea: [],
        imgshow: false,
        criteriaShow:false,
        orgCondtionStr: '',
        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('调压箱名称')] : [],
        meterbooks: [{label: '全部', value: ''}],
        // 公司下拉
        curorgid: [this.$login.f.orgid]
      }
    },
    props: [],
    ready () {
      readyGen(this)
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      getRes (obj) {
        this.orgCondtionStr = obj
      },
      view (row) {
        this.$parent.showupload = true
        this.$parent.row = row
      },
      imgclose () {
        this.imgshow = false
      },
      imgShow (val) {
        console.log("-----------val2:",val)
        this.imgfilename = `rs/image/file/` + val
        console.log("-----------imgfilename2:",this.imgfilename)
        this.imgshow = true
      },
      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
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + ' and f_orgid = ' + this.$login.f.orgid
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }
        this.model.search(args.condition, args.model)
      },
      pass (row) {
        let param = {
          f_meter_classify: row.f_meter_classify,
          f_meter_brand: row.f_meter_brand,
          f_hand_id: row.id,
          id: row.id,
          f_userfiles_id: row.f_userfiles_id,
          f_operator: Vue.$login.f.name,
          f_tablebase: row.f_tablebase,
          f_autotable_base: row.f_autotable_base,
          f_userinfo_id: row.f_userinfo_id,
          f_meter_state: '已抄表',
          f_result_state: '成功'
        }
        this.$resetpost('rs/logic/cardCommonEnter', {data: param}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          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_tablebase: 0,
          f_input_date: null,
          f_meter_state: '未抄表',
          f_hand_state: '作废',
          f_meter_source: null
        }
        this.$resetpost('rs/entity/t_cardhand', 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('抄表录入出错，请注意!')
        })
      },
      loadMeterBooks () {
        this.meterbooks = [...this.meterbooks, ...this.$GetSaleParam.getMeterBooks()]
      }
    },
    computed: {
      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]
      }
    },
    watch: {

    }
  }
</script>
