<template>
  <div class="auto">
    <validator name='v'>
      <form class="form-horizontal">
        <div class="row" style="display: flex;justify-content: center;"  id="testbill">
          <div v-if="bill.data">
            {{{ bill.data}}}
          </div>
          <div v-if="prebill.data">
            {{{ prebill.data}}}
          </div>
          <div v-if="returnsbill.data">
            {{{ returnsbill.data}}}
          </div>
          <div v-if="cardbill.data">
            {{{ cardbill.data}}}
          </div>
          <div v-if="replacebill.data">
            {{{ replacebill.data}}}
          </div>
        </div>
        <div class="row" style="margin-top: 10px">
          <div  :class="[$v.f_cause.required ? 'has-error' : 'has-success']">
            <label for="f_cause" class=" col-sm-2 control-label">补打原因:</label>
            <div class="col-sm-7">
              <textarea class="form-control" v-model="model.f_cause"
              v-validate:f_cause='{required: true }' rows="3" placeholder="补打原因"></textarea>
            </div>
          </div>
        </div>
      </form>
      <div style="text-align:right;height:auto;margin-top:30px;margin-right:50px;">
        <report-print id='testbill' top='25mm' left='60mm' width='100%' height='80%' style='td,th{font-size: 10pt!important;}'
         :notrepeat="true" v-if= '(bill.data || prebill.data || cardbill.data || returnsbill.data || replacebill.data)'></report-print>
        <button class="btn btn-default" @click="clean()">取消</button>
      </div>
    </validator>
  </div>
</template>
<script>
/**
*票据补打
*/

import { DataModel } from 'vue-client'
export default {
  title: '票据补打',
  data () {
    return {
      id: '',
      bill: new DataModel('rs/report/machine_bill', {reprint: "'补打'"}),
      prebill: new DataModel('rs/report/pre_sell', {reprint: "'补打'"}),
      cardbill: new DataModel('rs/report/card_bill', {reprint: "'补打'"}),
      returnsbill: new DataModel('rs/report/returns_bill', {reprint: "'补打'"}),
      replacebill: new DataModel('rs/report/replace_sell', {reprint: "'补打'"}),
      model: {
        f_cause: ''
      }
    }
  },
  props: ['data'],
  watch: {
    'data' (val) {
      this.id = val.id
    }
  },
  ready () {
    this.getBill()
  },
  methods: {
    getBill () {
      this.id = this.data.id
      if (this.data.type === '机表收费' || this.data.type === '自动下账') {
        let tablename = 't_sellinggas'
        let condition = 'id = ' + "'" + this.id + "'"
        this.$SqlService.singleTable(tablename, condition).then((res) => {
          if (res.data[0].f_pregas > 0) {
            this.bill.search(this.id)
          } else {
            this.prebill.search(this.id)
          }
        })
      } else if (this.data.type === '卡表收费') {
        this.cardbill.search(this.id)
      } else if (this.data.type === '用户退费') {
        this.returnsbill.search(this.id)
      } else if (this.data.type === '补卡') {
        this.replacebill.search(this.id)
      }
    },
    clean () {
      this.$info('取消操作')
      this.$dispatch('clean', '票据补打', this.row)
    }
  },
  events: {
    'print-success' () {
      if (this.model && this.data) {
        this.$dispatch('success', '票据补打', this.data)
      }
    },
    'print-error' () {
      this.$showAlert('打印失败，若有需要，请补打发票', 'error', 3)
      this.$dispatch('error', '票据补打', this.data, null)
    }
  }
}
</script>

<style>
</style>
