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

            <res-select-group :initres="$parent.$parent.initres" :show-component="['company']"
                              @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>

            <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"
                          condition="f_delivery_date  >= '{} 00:00:00'"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2  form-group">
              <label for="endDate" class="font_normal_body">结束日期</label>
              <datepicker id="endDate" placeholder="结束日期"
                          v-model="model.endDate" style="width: 60%"
                          :value.sync="model.endDate"
                          condition="f_delivery_date <= '{} 23:59:59'"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2  form-group">
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                     placeholder='客户编号'
                     condition="f_userinfo_code = '{}'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">终端编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_terminal_num"
                     placeholder='终端编号'
                     condition="f_terminal_num like '%{}%'">
            </div>

            <div class="span" style="float:right;">
              <button class="button_search button_spacing width-60" @click="search()" v-el:cx>查询</button>
              <export-excel :data="$parent.$parent.getCondition" class="button_export button_spacing"
                            :footer="$parent.$parent.footer"
                            :field="$parent.$parent.getExportField"
                            :header="$parent.$parent.other"
                            sqlurl="rs/logic/saleExport" sql-name="wechatSelling" 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="form-group col-sm-2">
              <label class="font_normal_body">客户名称</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name"
                     placeholder='客户名称'
                     condition="f_user_name = '{}'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">&nbsp;&nbsp;&nbsp;电话&nbsp;&nbsp;&nbsp;</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_user_phone" placeholder='电话'
                     condition="f_user_phone like '{}%'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">客户地址</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_address" placeholder='客户地址'
                     condition="f_address like '%{}%'">
            </div>
            <!--<div class="col-sm-2  form-group">-->
            <!--<label  class="font_normal_body">订单状态</label>-->
            <!--<v-select-->
            <!--v-model="model.msg"-->
            <!--placeholder='订单状态'-->
            <!--condition="f_states like '%{}%'"-->
            <!--:value.sync="model.msg"-->
            <!--:options='$parent.$parent.letter'-->
            <!--close-on-select ></v-select>-->
            <!--</div>-->
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>客户编号</th>
            <th>客户姓名</th>
            <th>客户电话</th>
            <th>客户地址</th>
            <th>终端编号</th>
            <th>订单号</th>
            <th>退款金额</th>
            <th>订单发生日期</th>
            <th>订单状态</th>
            <th>付款方式</th>
            <th>购气量</th>
            <th>购气金额</th>
            <th>系统收费时间</th>
            <th>系统收费状态</th>
            <th>系统写卡状态</th>
            <th>操作人</th>
            <th>退款时间</th>
            <th>备注</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">
            <nobr>{{ $index + 1 }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_userinfo_code }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_user_name }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_user_phone }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_address }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_terminal_num }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_transaction_id }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_total_fee }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_time_out }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_states }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_payment }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_pregas }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_collection }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_delivery_date }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_charge_state }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_write_card }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_operator }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_operate_date }}</nobr>
          </td>
          <td style="text-align: center;">
            <nobr>{{ row.f_comments }}</nobr>
          </td>

        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
import {PagedList} from 'vue-client'
import Vue from 'vue'

let readyGen = async function (self) {
  // self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
  // self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
  self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
}

export default {
  title: '自助机对账',
  data () {
    return {
      model: new PagedList('rs/sql/wechatSelling', 20, {}, {f_total_fee: '', f_collection: ''}),
      criteriaShow: false,
      show: false,
      watchComment: '',
      orgCondtionStr: '',
      getfield: {},
      // 合计数据
      sumsmodel: {},
      initres: {
        org: [this.$login.f.orgid]
      },
      msgData: [],
      getExportField: {
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户姓名',
        'f_user_phone': '客户电话',
        'f_address': '客户地址',
        'f_meter_classify': '气表类型',
        'f_bank_name': '缴费银行',
        'f_terminal_num': '终端编号',
        'f_transaction_id': '订单号',
        'f_total_fee': '订单金额',
        'f_time_out': '订单发生日期',
        'f_states': '订单状态',
        'f_payment': '付款方式',
        'f_pregas': '购气量',
        'f_collection': '购气金额',
        'f_delivery_date': '系统收费时间',
        'f_charge_state': '系统收费状态',
        'f_write_card': '系统写卡状态',
        'f_operator': '操作人',
        'f_operate_date': '退款时间'
      },
      condition2: '',
      other: [],
      footer: []
    }
  },
  props: [],
  ready () {
    readyGen(this)
  },
  methods: {
    async getRes (condition, obj) {
      this.orgCondtionStr = condition
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    updateState (val) {
      this.show = true
      this.msgData = val
    },
    close () {
      this.show = false
      this.watchComment = ''
      this.msgData = []
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    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)
    },
    selfSearch (args) {
      this.model.params.startDate = this.$refs.paged.$refs.cri.model.startDate
      this.model.params.endDate = this.$refs.paged.$refs.cri.model.endDate
      if (!this.orgCondtionStr) {
        args.condition = `${args.condition}` + `and f_orgid = '${this.$login.f.orgid}'` + `and f_bill_state = '4'`
      } else {
        args.condition = `${args.condition}` + this.orgCondtionStr  + `and f_bill_state = '4'`
      }
      // args.condition = `${args.condition}` + `and f_orgid = '${this.$login.f.orgid}'`
      this.condition2 = args.condition
      this.model.search(args.condition, args.model)
    }

  },
  events: {},
  computed: {
    authArr () {
      return this.$login.r ? this.$login.r : []
    },
    getCondition () {
      return {
        condition: this.condition2
      }
    }
  },
  watch: {
    sumsmodel: {
      handler: function (val) {
        this.getotherfooter()
      },
      deep: true
    }
  }
}
</script>
