<template>
    <div class="basic-main" style="height: 98%">
        <criteria-paged :model="model" v-ref:paged>
            <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
                <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
                    <div class="row">
                        <div class="col-sm-2  form-group">
                            <label for="startDate"  class="font_normal_body">同步时间:</label>
                            <datepicker id="startDate" placeholder="开始日期"
                                        v-model="model.startDate"  style="width: 60%"
                                        :value.sync="model.startDate"
                                        :disabled-days-of-Week="[]"
                                        :format="'yyyy-MM-dd 00:00:00'"
                                        condition = "f_operate_date >= '{}'"
                                        :show-reset-button="reset">
                            </datepicker>
                        </div>
                        <div class="col-sm-2  form-group">
                            <label for="endDate"  class="font_normal_body"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;:</label>
                            <datepicker id="endDate" placeholder="结束日期"
                                        v-model="model.endDate"  style="width: 60%"
                                        :value.sync="model.endDate"
                                        :disabled-days-of-Week="[]"
                                        :format="'yyyy-MM-dd 23:59:59'"
                                        condition = "f_operate_date <= '{}'"
                                        :show-reset-button="reset">
                            </datepicker>
                        </div>
                        <div class="col-sm-2  form-group">
                            <label for="handstartDate"  class="font_normal_body">抄表日期:</label>
                            <datepicker id="handstartDate" placeholder="开始日期"
                                        v-model="model.handstartDate"  style="width: 60%"
                                        :value.sync="model.handstartDate"
                                        :disabled-days-of-Week="[]"
                                        :format="'yyyy-MM-dd 00:00:00'"
                                        condition = "f_readtime >= '{}'"
                                        :show-reset-button="reset">
                            </datepicker>
                        </div>
                        <div class="col-sm-2  form-group">
                            <label for="handendDate"  class="font_normal_body"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <datepicker id="handendDate" placeholder="结束日期"
                                        v-model="model.handendDate"  style="width: 60%"
                                        :value.sync="model.handendDate"
                                        :disabled-days-of-Week="[]"
                                        :format="'yyyy-MM-dd 23:59:59'"
                                        condition = "f_readtime <= '{}'"
                                        :show-reset-button="reset">
                            </datepicker>
                        </div>
                        <div class="col-sm-2  form-group">
                            <label for="deviceno"  class="font_normal_body"> 气表编号;</label>
                            <input type="text" style="width:60%" class="input_search" v-model="model.deviceno"
                                   condition="deviceno like '%{}%' " placeholder="气表编号">
                        </div>
                        <div class="span" style="float:right;">
                            <button class="button_search button_spacing width-60" @click="search()" v-el:cx>查询</button>
                            <button class="button_clear  button_spacing" @click="$parent.$parent.getgassale()">获取gassale抄表</button>
                        </div>
                    </div>
                </div>
            </criteria>
            <data-grid :model="model" partial='list'  class="list_area table_sy" v-ref:grid>
                <template partial='head'>
                    <tr>
                        <th>序号</th>
                        <th>气表编号</th>
                        <th>温度</th>
                        <th>电压</th>
                        <th>当前单价</th>
                        <th style="white-space: nowrap;">最近抄表时间</th>
                        <th style="white-space: nowrap;">已用总额</th>
                        <th style="white-space: nowrap;">余额</th>
                        <th style="white-space: nowrap;">同步时间</th>
                    </tr>
                </template>
                <template partial='body'>
                    <td style="text-align: center;"><nobr>{{$index+1}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.deviceno}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.tempe}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.vol}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.curprice}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.f_readtime}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.usedtotal}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.remaintotal}}</nobr></td>
                    <td style="text-align: center;"><nobr>{{row.f_operate_date}}</nobr></td>
                </template>
            </data-grid>
        </criteria-paged>
    </div>
</template>
<script>
  import { PagedList } from 'vue-client'

  let readyGen = async function (self) {
    self.getfield = self.config.excelHeaders
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'

    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }

  export default {
    title: 'gassale抄表查循',
    data () {
      return {
        model: new PagedList('rs/sql/getgassalehand', 20,
          {}),
        config: {
          // 导出列要和查询列相同
          excelHeaders: {
            'f_orgname': '分公司名称',
            'f_total_fee': '微信金额',
            'f_collection': '收费记录金额',
            'f_time_end': '交易日期'
          }
        },
        payType: [
          {label: '全部', value: ''},
          {label: '微信支付', value: 'JSAPI'},
          {label: '二维码支付', value: 'NATIVE'},
          {label: '付款码支付', value: 'MICROPAY'}
        ],
        criteriaShow: false,
        getfield: {},
        condition2: '',
        f_orgid: '',
        other: [],
        footer: [],
        // 合计数据
        sumsmodel: {},
        msg: [],
        // 公司下拉
        curorgid: [this.$login.f.orgid]
      }
    },
    props: [],
    ready () {
      readyGen(this)
    },
    methods: {
      async getgassale () {
        let url = 'http://36.103.222.144:9196/TP-READ/MeterRead'
        let param = {
          url: url,
          type: 'gassale'
        }
        let res = await this.$resetpost('rs/logic/getCardHand', param)
        this.search()
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      dealmsg (val) {
        val.model = this.model.model
        this.$dispatch('deal-msg', val)
      },
      getotherfooter () {
        // this.$refs.paged.$refs.cri.$refs.exports.otherData=[];
        // this.$refs.paged.$refs.cri.$refs.exports.footerData=[];
        this.other = []
        this.footer = []
      // let exportdata = this.getCondition;
        let otherInData = []
        otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`)
        let footerData = [], exportfield = this.getfield
        footerData.push('合计')
        let self = this
        for (var field in self.sumsmodel) {
          footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`)
        }
        this.footer.push(footerData)
        this.other.push(otherInData)
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeid = val[0]
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      selfSearch (args) {
        this.model.params.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.model.params.endDate = this.$refs.paged.$refs.cri.model.endDate
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
        this.condition2 = args.condition
        this.model.search(args.condition, args.model)
      },
      modify (row) {
        console.log('返回数据1', row)
        this.$showMessage('确认重置微信支付状态么？', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            let data = {
              f_transaction_id: row.f_transaction_id
            }
            this.$resetpost('rs/logic/weChatMeter', data, {resolveMsg: null, rejectMsg: '重置出错!!!'}).then((res) => {
              console.log('返回数据3', res)
              this.$refs.paged.$refs.cri.search()
              this.$showAlert(`重置成功!`, 'success', 4000)
              // this.search()
            }).catch((error) => {
              console.log('重置异常', res)
            })
          }
        })
      }
    },
    computed: {
      getCondition () {
        return {
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate: this.$refs.paged.$refs.cri.model.endDate,
          condition: this.condition2}
      },
      chargeType () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('微信收费类型')]
      }
    },
    watch: {
      sumsmodel: {
        handler: function (val) {
          this.getotherfooter()
        },
        deep: true
      }
    }
  }
</script>
