<template xmlns:v-ref="" xmlns:v-el="http://www.w3.org/1999/xhtml">
  <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 class="font_normal_body">组织机构:</label>
              <res-select :initresid='$parent.$parent.curorgid'
                          @res-select="$parent.$parent.getorg"
                          class="select select_list"
                          restype='organization'
                          style="width: 60%">
              </res-select>
            </div>
            <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: 55%"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :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: 55%"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="reset">
              </datepicker>
            </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"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="WeChatPayPos"
                            template-name='pos对账查询导出' :choose-col="true"></export-excel>
              <div
                @click="$parent.$parent.hidden()"
                class="button_spacing"
                style="float: right">
              </div>
            </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 style="white-space: nowrap;">交易日期</th>
            <th>pos订单号</th>
            <th>pos金额</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_time_end}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_out_trade_no}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_total_fee}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_serial_id}}</nobr></td>
          <td style="text-align: center;"><nobr>
            <span v-if="row.f_bill_state=='0'">未支付</span>
            <span v-if="row.f_bill_state=='1'">已支付</span>
            <span v-if="row.f_bill_state=='2'">支付失败</span>
            <span v-if="row.f_bill_state=='3'">退款</span>
          </nobr></td>
          <button class="button_search button_spacing width-60" @click="$parent.$parent.$parent.resetting(row)" v-el:cz>重置</button>
        </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: 'pos对账',
    data () {
      return {
        model: new PagedList('rs/sql/WeChatPayPos', 20),
        config: {
          // 导出列要和查询列相同
          excelHeaders: {
            'f_time_end': '交易日期',
            'f_out_trade_no': 'pos订单号',
            'f_total_fee': 'pos金额',
            'f_serial_id': '收费订单号',
            'f_bill_state': '支付状态'
          }
        },

        criteriaShow: false,
        getfield: {},
        condition2: '',
        f_orgid: '',
        other: [],
        footer: [],
        msg: [],
        resid: [],  // 存放新增的f_files表中id
        // 公司下拉
        curorgid: [this.$login.f.orgid]

      }
    },
    props: [],
    ready () {
      readyGen(this)
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      dealmsg (val) {
        val.model = this.model.model
        this.$dispatch('deal-msg', val)
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeid = val[0]
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      resetting (row) {
        console.log(row)
        this.$resetpost('rs/logic/weChatPos', {data: row})
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        console.log('查询。。。', this.f_orgid)
        if (this.f_orgid) {
          args.condition = `${args.condition} and f_orgid  in ${this.f_orgid}`
        }
        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)
      }
    },
    computed: {
      getCondition () {
        return {
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate: this.$refs.paged.$refs.cri.model.endDate,
          condition: this.condition2}
      }
    },
    watch: {
      sumsmodel: {
        handler: function (val) {
          this.getotherfooter()
        },
        deep: true
      }
    }
  }
</script>
