<template>
  <div>
    <el-button-group v-if="tool.checkAuth($route.name,'editBlueInvioce')" style="margin-bottom:10px">
      <el-button size="small" type="primary" :disabled="selectData.length === 0" @click="clickCreateRedInvioce">勾选创建发票</el-button>
      <el-button size="small" type="primary" :disabled="selectData.length === 0" @click="clickInvioceQuery">发票创建查询</el-button>
    </el-button-group>
    <invoiceTable :status="status" ref="invoiceTable" @activeRow="activeRow" @selection="selection"></invoiceTable>
    <invoiceTablemx :status="status" ref="invoiceTablemx"></invoiceTablemx>
  </div>
</template>

<script>
import invoiceTable from './components/invoiceTable'
import invoiceTablemx from './components/invoiceTablemx'

export default {
  props:['status'],
  components:{
    invoiceTable,
    invoiceTablemx
  },
  data () {
    return {
      sa_invoicebillid:0,
      selectData:[]
    }
  },
  methods:{

    activeRow (row){
      this.$refs['invoiceTablemx'].listData(row.sa_invoicebillid)
    },
    selection (selection) {
      this.selectData = selection
    },
    clickCreateRedInvioce () {
      this.selectData.forEach(e=>{
        this.createRedInvioce(e.sa_invoicebillid)
      })
    },
    // 创建红字发票
    async createRedInvioce(sa_invoicebillid) {
      const res = await this.$api.requested({
        "id": "20221226151903",
        "content": {
          "sa_invoiceapplyid":this.$route.query.id,
          "sa_invoicebillid":sa_invoicebillid
        }
      })
      this.tool.showMessage(res,()=>{
        this.$refs['invoiceTable'].listData()
      })
    },
    clickInvioceQuery () {
      this.selectData.forEach(e=>{
        this.invioceQuery(e.sa_invoicebillid)
      })
    },
    // 发票查询
    async invioceQuery (sa_invoicebillid) {
      const res = await this.$api.requested({
        "id": "20221226152003",
        "content": {
          "sa_invoicebillid":sa_invoicebillid
        }
      })
      this.tool.showMessage(res,()=>{
        this.$refs['invoiceTable'].listData()
      })
    },
  }
}

</script>
<style>
</style>