<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.billno"
        formPath="cashcouponPay"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        :turnPageId="20230217095002"
        :delApiId="20230302140502"
        idname="sa_cashbillid"
        ownertable="sa_cashbill"
        :tabs="['详细信息']"
        @pageChange="pageChange"
        :statusCheck="[{key:'status',value:'审核'}]"
        @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="slot0" >
        <detailed :data="mainData"></detailed>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailed from '../component/detailed'
import examine from '../component/examine'
export default {
  name: "detail",
  components:{detailed,examine},
  data(){
    return {
      mainData:{},
      mainAreaData:[],
    }
  },
  methods:{
    async queryMainData(id){
      const res = await this.$api.requested({
        "id": "20230217095102",
        "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.mainData.rebate_billno
        },
        {
          label:'返利金有效期',
          value:this.mainData.rebate_enddate
        },
        {
          label:'支出金额',
          value:this.tool.formatAmount(this.mainData.amount,2)
        },
        {
          label:'备注',
          value:this.mainData.remarks
        },
        {
          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
          }
        },
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.flag = false
      this.$router.replace({path:'/cashcouponPayDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.queryMainData(this.$route.query.id)
    }
  },
  created() {
    this.queryMainData(this.$route.query.id)
  }
}
</script>

<style scoped>

</style>