<template>
  <div class="auto form-horizontal" >
    <modal :show.sync="show"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h3 style="color:black" class="modal-title">受理单</h3>
      </header>
      <article slot="modal-body" style = "display: flex;justify-content: center;" id="bill">
        <div v-if="bill.data">
          {{{bill.data}}}
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-success" @click='print()'>打印</button>
        <!--<report-print id='bill' top='15mm' left='5mm'  width='90%'  height='70%' :notrepeat="true" v-ref:reportprint></report-print>-->
        <report-print id='bill' top='15mm' left='5mm'  width='90%'  height='70%' :notrepeat="false" :showbtn="false" v-ref:reportprint></report-print>
        <button type="button" class="btn btn-default"  @click='cancel()' v-if="!billManager">取消</button>
      </footer>
    </modal>
  </div>
</template>
<script>
  import { DataModel } from 'vue-client'

  let getBillData = async function(self) {
    console.log('看看打票里面的data', self.billUrl)
    // console.log('看看打票里面的self.billdata111', self.billdata)
    Object.assign(self.billdata,{reprint: "'正常'"},{operator:`'${self.$login.f.name}'`})
    console.log('看看打票里面的self.billdata222', self.billdata)
    // console.log('看看打票里面的self.billdata333', {reprint: "'正常'",reason: `'${self.billdata.reason}'`, cardfee: `'${self.billdata.f_cardfees}'`,operator:`'${self.$login.f.name}'`})
    // self.bill = new DataModel(self.billUrl, {reprint: "'正常'",reason: `'${self.billdata.reason}'`, cardfee: `'${self.billdata.f_cardfees}'`,operator:`'${self.$login.f.name}'`})
    self.bill = new DataModel(self.billUrl, self.billdata)
    await self.bill.search(self.data.f_userinfo_id)
  }

  export default {
    title: '收费发票',
    data () {
      return {
        bill: {}
      }
    },
    props: ['show', 'data', 'billUrl','billdata'],
    ready () {
    },
    methods: {
      cancel  () {
        this.$dispatch('toggle')
      },
      async print () {
        // 更新系统发票号
        try{
          console.log('不需要票号，直接打印')
          this.$refs.reportprint.print()
        } catch (error) {
          this.$dispatch('refresh')
        }

      }
    },
    watch: {
      'show' (val) {
        if (val) {
          getBillData(this, val).then(() => {
            this.$emit('ready')
          }).catch((error) => {
            this.$emit('error', error)
          })
        }
      }
    },
    events: {
      'print-success' () {
        // 对票据明细进行更新或插入操作
        this.$dispatch('closeaccept')
      },
      'print' () {
        // 对票据明细进行更新或插入操作
        this.$dispatch('printok', '发票打印', this.data)
      },
      'print-error' () {
        this.$dispatch('error', '发票打印', this.data, null)
      }
    }
  }

</script>
<style >
</style>
