<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.billno"
        formPath="cashcoupon"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        :turnPageId="20230216192902"
        :delApiId="20230216183402"
        idname="sa_cashbillid"
        ownertable="sa_cashbill"
        :tabs="['支出明细','详细信息']"
        :statusCheck="[{key:'status',value:'审核'}]"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="customOperation">
        <examine class="inline-16" v-if="tool.checkAuth($route.name,'check')" :data="mainData"  @examineSuccess="onSuccess"></examine>
      </div>
      <div slot="slot1" >
        <detailed :data="mainData"></detailed>
      </div>
      <div slot="slot0">
        <payDetails></payDetails>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailed from '../component/detailed'
import payDetails from "@/HDrpManagement/cashcoupon/component/payDetails";
import examine from '../component/examine'
export default {
  name: "detail",
  components:{detailed,payDetails,examine},
  data(){
    return {
      mainData:{},
      mainAreaData:[],
    }
  },
  methods:{
    async queryMainData(id){
      const res = await this.$api.requested({
        "id": "20230216191602",
        "content": {
          "sa_cashbillid":this.$route.query.id
        }
      })
      this.mainData = res.data
      console.log(this.mainData);

      this.changeDataStructure()
    },
    changeDataStructure(){
      let that = this
      this.mainAreaData = [
        {
          label:'单号',
          value:this.mainData.billno
        },
        {
          label:'单据日期',
          value:this.mainData.billdate
        },
        {
          label:'企业名称',
          value:this.mainData.enterprisename
        },
        {
          label:'金额',
          value:this.tool.formatAmount(this.mainData.amount,2)
        },
        {
          label:'分类明细',
          value:this.mainData.subclass
        },
        {
          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.rebate_enddate
        },
        {
          label:'余额',
          value:this.mainData.rebate_balance
        },
        {
          label:'备注',
          value:this.mainData.remarks
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/cashcouponDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.queryMainData(this.$route.query.id)
    },
  },
  created() {
    console.log('触发111');

    this.queryMainData(this.$route.query.id)
  }
}
</script>

<style scoped>

</style>