<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="`${mainData.billno}`"
        :oldFormPath="{edit:'HDrpManagement/invoiceapp/modules'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221216143103"
        delApiId="20221216143203"
        idname="sa_invoiceapplyid"
        ownertable="sa_invoiceapply"
        :statusCheck="[{key:'status',value:'提交'},{key:'status',value:'审核'},{key:'status',value:'关闭'}]"
        :tabs="['申请开票订单明细','蓝票信息','红票信息','系统信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <el-button v-if="tool.checkAuth($route.name,'submit')" type="primary" size="mini" @click="submitInvoice" :disabled="mainData.status !== '新建' && mainData.status !== '提交'">{{mainData.status ==='新建'?'提交':'撤回'}}</el-button>
        <el-button v-if="tool.checkAuth($route.name,'check')" type="primary" size="mini" @click="checkInvoice" :disabled="mainData.status !== '提交' && mainData.status !== '审核'">{{mainData.status === '审核'?'反审核':'审核'}}</el-button>
        <el-button v-if="tool.checkAuth($route.name,'toManual')" type="primary" size="mini" class="inline-16" :disabled="mainData.byhand === 1 || mainData.status !== '新建' && mainData.status !== '提交'" @click="toManual">转手工</el-button>
      </div>
      <div slot="slot0" >
        <invoiceOrder :status="mainData.status" :sys_enterpriseid="mainData.sys_enterpriseid"></invoiceOrder>
      </div>
      <div slot="slot1" >
        <blueInvoice :data="mainData"></blueInvoice>
      </div>
      <div slot="slot2">
        <redInvoice :data="mainData" :status="mainData.status"></redInvoice>
      </div>
      <div slot="slot3">
        <detailInfo :more="true" :data="detailInfo"></detailInfo>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailInfo from '@/components/detailInfo/index'
import invoiceOrder from './tab/invoiceOrder/invoiceOrder.vue'
import blueInvoice from './tab/blueInvoice/index.vue'
import redInvoice from './tab/redInvoice/index.vue'

export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      detailInfo:[]
    }
  },
  components:{
    invoiceOrder,
    blueInvoice,
    redInvoice,
    detailInfo
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20221216143003,
        "content": {
          "sa_invoiceapplyid": this.$route.query.id
        }
      })
      this.mainData = res.data
      this.changeDataStructure()
      console.log(this.mainData,'---')
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
        {
          label:'客户',
          value:this.mainData.agententerprisename
        },
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '新建':
                style = {color:"#000000"}
                break;
              case '提交':
                style = {color:"#d90a0a"}
                break;
              case '审核':
                style = {color:"#52C41A"}
                break;
              default:
                break;
            }
            return style
          }
        },
        {
          label:'发票种类',
          value:this.mainData.invoiceline === 's'?'专用发票':'普通发票(电票)'
        },
        {
          label:'开票金额',
          value:this.tool.formatAmount(this.mainData.suminvoiceamount,2)
        },
        {
          label:'开票方式',
          value:this.mainData.byhand === 1?'手工开票':'线上开票'
        },
        {
          label:'开票单位',
          value:this.mainData.enterprisename
        },
        {
          label:'税号',
          value:this.mainData.taxno
        },

         {
          label:'开票地址',
          value:this.mainData.address
        },
        {
          label:'联系方式',
          value:this.mainData.phonenumber
        },

        {
          label:'开户行及账号',
          value:this.mainData.bank + this.mainData.bankcardno
        },
        {
          label:'发票限额',
          value:this.tool.formatAmount(this.mainData.quota,2)
        },


        {
          label:'复核人',
          value:this.mainData.invoicechecker
        },
        {
          label:'开票人',
          value:this.mainData.invoiceclerk
        },
        {
          label:'收款人',
          value:this.mainData.invoicepayee
        },
        {
          label:'备注',
          value:this.mainData.remarks
        },
        
      ]
      this.detailInfo = [
        {
          title:'系统信息',
          info: [
            {label:'创建人',value:this.mainData.createby},
            {label:'创建时间',value:this.mainData.createdate},
            {label:'提交人',value:this.mainData.submitby},
            {label:'提交时间',value:this.mainData.submitdate},
            {label:'审核人',value:this.mainData.checkby},
            {label:'审核时间',value:this.mainData.checkdate},
          ]
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/invoiceDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    checkInvoice () {
      this.$confirm(this.mainData.status === '提交'?'确定审核吗?':'确定反审核吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await this.$api.requested({
          "id": this.mainData.status === '提交'?"20221217145603":"20221217145703",
          "content": {
            "sa_invoiceapplyid":this.$route.query.id
          }
        })
        this.tool.showMessage(res,()=>{
          this.queryMainData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });          
      });
    },
    submitInvoice () {
      this.$confirm(this.mainData.status === '新建'?'确定提交吗?':'确定撤回吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await this.$api.requested({
         "id": this.mainData.status === '新建'?20221219133803:20221219133903,
          "version":1,
          "content": {
            "sa_invoiceapplyid":this.$route.query.id
          }
        })
        this.tool.showMessage(res,()=>{
          this.queryMainData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });          
      });
    },
    toManual () {
      this.$confirm('确认要转手工吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await this.$api.requested({
          "id": "20221228150403",
          "content": {
            "sa_invoiceapplyid":this.$route.query.id
          }
        })
        this.tool.showMessage(res,()=>{
          this.queryMainData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>