<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <div class="form-group">
            <datepicker id="startDate" placeholder="开始日期"
                        v-model="model.startDate"
                        :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="form-group">
            <!-- <label for="endDate">结束日期:</label> -->
            <datepicker id="endDate" placeholder="结束日期"
                        v-model="model.endDate"
                        :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="form-group">
            <button class="btn btn-success " @click="search()" v-el:cx>查询</button>
          </div>
        </div>
      </criteria>
      <data-grid  :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>发票号码</th>
            <th>气量</th>
            <th>金额</th>
            <th>操作人</th>
            <th>操作日期</th>
            <th>结算单状态</th>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body':model="model">
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td style="text-align:center">{{row.f_bill_number}}</td>
            <td style="text-align:center">{{row.f_gas}}</td>
            <td style="text-align:center">{{row.f_paid_money}}</td>
            <td style="text-align:center">{{row.f_operator}}</td>
            <td style="text-align:center">{{row.f_operate_date}}</td>
            <td style="text-align:center">{{row.f_bill_type}}</td>
            <td style="text-align:center">
<!--              <button class="btn btn-link" v-if="row.f_bill_state === '有效'" @click="$parent.$parent.$parent.redcancel(row)">冲正</button>-->
              <button class="btn btn-link" @click="$parent.$parent.$parent.revote(row)" v-if="row.f_bill_type == '正常'">补打</button>
            </td>
          </tr>
        </template>
        <template partial='foot'>
        </template>
      </data-grid>
    </criteria-paged>
    </div>
    <div class="form-group">
      <reissue-bill v-if="print" :show.sync="print" :data="data" @reissue-success="printok()" @cancel="close()"></reissue-bill>
    </div>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'

  export default {
    title: '已开收据',
    data () {
      return {
        model: new PagedList('rs/sql/sale_handReceiptQuery', 10),
        billData: {
          url: 'rs/report/meter_liquidation',
          bill: '',
          f_meter_classify: '机表'
        },
        billConfig: {
          hasBillManage: false
        },
        print: false,
        data: ''
      }
    },
    props: ['row'],
    ready () {
      this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
      this.search()
    },
    methods: {
      selfSearch (args) {
        if (this.row) {
          args.condition = `${args.condition} and f_userinfo_id = '${this.row.f_userinfo_id}'`
        }
        this.model.search(args.condition, this.model)
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      async revote (row) {
        await this.$showMessage('确认重开收据吗?', ['cancel', 'confirm']).then(
          (response) => {
            if (response === 'confirm') {
              this.flag = true
            } else if (response === 'cancel') {
              this.flag = false
            }
          })
        if (this.flag) {
          this.data = {
            id: row.f_charge_id,
            type: row.f_type,
            billUrl: 'rs/report/meter_liquidation',
            f_bill_type: '清算单'
          }
          this.print = true
        }
      },
      printok () {
        this.print = false
        this.$refs.paged.$refs.cri.search()
      },
      close () {
        this.print = false
        this.$refs.paged.$refs.cri.search()
      }
    }
  }
</script>
