<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>
                <export-excel
                  :data="{condition: $parent.$parent.excelCondition}"
                  :field="$parent.$parent.fields"
                  sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="getAuditMachineHand"
                  template-name='抄表审核导出'
                  :choose-col="true">
                </export-excel>
                <div
                  :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">表&emsp;&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">抄&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%"
                          :multiple="true"
                          condition="f_meter_book_num in {}"></v-select>
              </div>
              <res-select-group :show-component="['company','department','operator']" :initres="$parent.$parent.initres" @re-res="$parent.$parent.getRes"
                                v-ref:sel></res-select-group>
            </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><nobr>客户编号</nobr></th>
              <th><nobr>基本信息</nobr></th>
              <th><nobr>上期结余</nobr></th>
              <th><nobr>表号</nobr></th>
              <th><nobr>上期底数</nobr></th>
              <th><nobr>本期底数</nobr></th>
              <th><nobr>上次抄表录入日期</nobr></th>
              <th><nobr>下发日期</nobr></th>
              <th><nobr>抄表录入日期</nobr></th>
              <th><nobr>抄表册</nobr></th>
              <th><nobr>抄表员</nobr></th>
              <th><nobr>操作</nobr></th>
            </tr>
          </template>
          <template partial='body'>
            <td>{{row.f_userinfo_code}}</td>
            <td> <nobr>{{row.f_user_name}}&nbsp;&nbsp;{{row.f_address}} </nobr></td>
            <td>{{row.f_balance}}</td>
            <td>{{row.f_meternumber}}</td>
            <td>{{row.f_last_tablebase}}</td>
            <td>{{row.f_tablebase}}</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>{{row.f_inputtor}}</td>
            <td>
              <button type="button" name="button" class="button_search button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.synchronization(row)"
              >同步
              </button>
            </td>

          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>

</template>
<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import co from "co";

  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 {
        timer: null,
        model: new PagedList('rs/sql/getMachineUploaded', 50,{startDate: 'this.model.startDate', endDate: 'this.model.endDate', }),
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        config: {
          examine: false
        },
        imgfilename: '',
        // 小区
        residentialArea: [],
        imgshow: false,
        criteriaShow: false,
        orgCondtionStr: '',
        excelCondition: '',
        fields: {
          'f_userinfo_code': '客户编号',
          'f_user_name': '客户名称',
          'f_address': '客户地址',
          'f_balance': '上期结余',
          'f_meternumber': '表号',
          'f_last_tablebase': '上期底数',
          'f_tablebase': '本期底数',
          'f_last_input_date': '上次抄表录入日期',
          'f_hand_date': '下发日期',
          'f_input_date': '抄表录入日期',
          'f_book_name': '抄表册',
          'f_inputtor': '抄表员'
        },
        auditState: [{label: '全部', value: ''}, {label: '已审核', value: '已抄表'}, {label: '未审核', value: '待审核'}],
        auditState1: [{label: '全部', value: ''}, {label: '审核失败', value: '审核失败'}],
        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: [],
        // 公司下拉
        curorgid: [this.$login.f.orgid]
      }
    },
    props: [],
    beforeDestroy () {
      // 销毁定时器
      if (this.timer) clearInterval(this.timer)
    },
    ready () {
      this.model.pageSizeMax = 9999999
      readyGen(this)
    },
    methods: {
      synchronization(row){
        this.$resetpost('rs/logic/syncHandAudit', {data: row}).then(() => {
          this.$dispatch('refresh', '同步抄表册数据', row)
          this.search()
        })
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      getRes (obj) {
        this.orgCondtionStr = obj
      },
      view (row) {
        this.$parent.showupload = true
        this.$parent.row = row
      },
      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()
      },
      clear () {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      selfSearch (args) {
        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + ' and f_orgid = ' + this.$login.f.orgid
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }
        this.excelCondition = args.condition
        this.$refs.paged.$refs.grid.selectInit()
        this.model.search(args.condition, args.model)
      },
      loadMeterBooks () {
        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>
