<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="`单号:${mainData.billno}`"
        :oldFormPath="{edit:'HDrpManagement/rebatesettlement/modules'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20230104194002"
        idname="sa_rebatesettlementid"
        ownertable="sa_rebatesettlement"
        delApiId="20230104193402"
        tags=""
        :tabs="['明细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <el-button v-if="tool.checkAuth($route.name,'check')" class="inline-16" size="mini" type="primary" :disabled="mainData.status !== '新建'" @click="checkBill">审 核</el-button>
      </div>
      <div slot="slot0" >
        <rebatemx></rebatemx>
      </div>
      <div slot="slot1" >
      </div>
    </basicDetails>
  </div>
</template>

<script>
import rebatemx from './tabs/rebatesettlementmx.vue'
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{}
    }
  },
  components:{
    rebatemx
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id": "20230104200802",
        "content": {
          "sa_rebatesettlementid": this.$route.query.id
        },
      })
      this.mainData = res.data
      this.changeDataStructure()
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
        {
          label:'结算企业',
          value:this.mainData.enterprisename
        },
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '新建':
                style = {color:"#000000"}
                break;
              case '审核':
                style = {color:"#52C41A"}
                break;
              default:
                break;
            }
            return style
          }
        },
        {
          label:'单据日期',
          value:this.mainData.billdate
        },
        {
          label:'合同编号',
          value:this.mainData.billno_contract
        },
        {
          label:'关联订单',
          value:this.mainData.sonum
        },
        {
          label:'订单金额',
          value:this.tool.formatAmount(this.mainData.amount,2)
        },
        {
          label:'订单金额比例',
          value:this.mainData.calculatemodel
        },
        {
          label:'产品折扣',
          value:this.mainData.productdiscount
        },
        {
          label:'居间费',
          value:this.mainData.rebate
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/customerDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    checkBill () {
      this.$confirm('确定审核该单据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await this.$api.requested({
          "id": "20230104191602",
          "content": {
            "sa_rebatesettlementid": 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>