<template>
  <criteria-paged :simple="true" :model="model" v-ref:paged>
    <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch">
      <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
      </div>
    </criteria>
    <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
      <template partial='head'>
        <tr>
          <th>客户编号</th>
          <th>用户姓名</th>
          <th>用气性质</th>
          <th>金额</th>
          <th>业务类型</th>
          <th>操作</th>
        </tr>
      </template>
      <template partial='body'>
        <td>{{ row.f_userinfo_code }}</td>
        <td>{{ row.f_user_name }}</td>
        <td>{{ row.f_gasproperties }}</td>
        <td>{{ row.f_collection }}</td>
        <td>{{ row.type }}</td>
        <td style="text-align: center;">
          <button @click.stop="$parent.$parent.$parent.report(row)" class="btn btn-link" name="button" type="button"
                  v-if="row.f_state==='已生成'">票据补打
          </button>
<!--          <button @click.stop="$parent.$parent.$parent.cancel(row)" class="btn btn-link" name="button" type="button"-->
<!--                  v-if="row.f_state==='已生成'">撤销记录-->
<!--          </button>-->
        </td>
      </template>
    </data-grid>
  </criteria-paged>
  <record-cancel :data="cancel_data" :show.sync="cancel_show" @cancel="cancelOper()" @cancel-success="cancelSucc()" v-if="cancel_show"></record-cancel>
  <reissue-bill :data="reissue_data" :show.sync="reissue_show" @cancel="reissueOper()" @reissue-success="reissueSucc()"
                v-if="reissue_show"></reissue-bill>
</template>
<script>
import {PagedList} from 'vue-client'
import co from 'co'

let reprintGen = function* (self, row) {
  try {
    let reissueData = {}
    reissueData = Object.assign({}, reissueData, row)
    reissueData.f_bill_type = '预存缴费'
    reissueData.f_bill_style = '普通收据'
    reissueData.f_operator = self.$login.f.name
    reissueData.f_operatorid = self.$login.f.id
    reissueData.f_orgid = self.$login.f.orgid
    reissueData.f_orgname = self.$login.f.orgs
    reissueData.f_depid = self.$login.f.depids
    reissueData.f_depname = self.$login.f.deps
    reissueData.billUrl = 'rs/report/MakeUp'
    self.reissue_data = reissueData
    self.reissue_show = true
  } catch (error) {
    if (error.status) {
      self.$warn(`加载数据出错, ${JSON.stringify(error)}`, 'CardList')
    }
    throw error
  }
}
export default {
  title: '批量预存',
  props: ['batchId'],
  data () {
    return {
      model: new PagedList('rs/sql/batchDeductionQuery', 30),
      reissue_show: false,
      cancel_show: false,
      cancel_data: null,
      reissue_data: null
    }
  },

  ready () {
    this.search()
  },
  methods: {
    cancel (row) {
      this.cancel_show = true
      this.cancel_data = row
    },
    cancelOper () {
      this.cancel_data = null
      this.cancel_show = false
    },
    cancelSucc () {
      this.cancel_show = false
      this.search()
      this.$dispatch('refresh')
    },
    selfSearch (args) {
      args.condition = args.condition + ` and tbd.f_batch_id = '${this.batchId}'`
      this.model.search(args.condition, this.model)
    },
    reissueSucc () {
      this.reissue_show = false
      this.$dispatch('refresh')
    },
    reissueOper () {
      this.reissue_data = null
      this.reissue_show = false
    },
    report (row) {
      let reprint = reprintGen(this, row)
      return co(reprint)
    },
    search () {
      this.$refs.paged.$refs.criteria.search()
    }
  }

}
</script>
<style lang="less" scoped>
</style>
