
<template>
  <basicDetails 
    ref="details"
    :titleText="mainData.billno"
    :editData="mainData"
    :mainAreaData="mainAreaData" 
    :turnPageId="20221008155103" 
    idname="sa_creditbillid"
    :tags="[]"
    :tabs="['经销商信息','详细信息']"
    @pageChange="pageChange"
    delApiId="20221008155403"
    :statusCheck="[{key:'status',value:'审核'}]"
    @onEditSuccess="queryMainData($route.query.id)">
    <div slot="tags">
      <!-- 使用此插槽可不传[tags] -->
      <!-- :tabs="['经销商团队','代理区域','营销类别','账户余额']" -->
    </div>
    <div slot="customOperation">
      <Edit class="inline-16" v-if="tool.checkAuth($route.name,'update') && mainData.status == '新建'" :data="mainData" @onSuccess="queryMainData"/>
      <customBtn
          class="inline-16"
          btnName="审 核"
          message="确定审核当前信用单吗?"
          idName="20221008155303"
          keyName="sa_creditbillid"
          :id="$route.query.id"
          @onSuccess="queryMainData()" 
          v-if="mainData.status == '新建' && tool.checkAuth($route.name,'check')"
        />
      <!-- 此区域提供了自定义操作按钮 -->
    </div>
    <div slot="slot0" >
      <enterpriseTable ref="enterprise">
        <template v-slot:edit="scope">
            <el-button class="inline-16" v-if="tool.checkAuth($route.name,'enterpriseInfoManage') && mainData.status == '新建'" type="text" size="mini" @click="$refs.enterprise.currentEdit=scope.data">编 辑</el-button>
        </template>
        <template v-slot:del="scope">
          <delete-btn v-if="tool.checkAuth($route.name,'enterpriseInfoManage') && mainData.status == '新建'" nameId="20230104101003" nameKey="sa_creditbilldetailids" :id="scope.data.sa_creditbilldetailid" message="确定删除当前数据吗?" @deleteSuccess="$refs.enterprise.listData()"></delete-btn>
        </template>
        <Add slot="add" v-if="tool.checkAuth($route.name,'enterpriseInfoManage') && mainData.status == '新建'" @onSuccess="$refs.enterprise.listData()"></Add>
      </enterpriseTable>
    </div>
    <div slot="slot1">
      <base-info v-if="detailInfo" :detailInfo="detailInfo"></base-info>
    </div>
  </basicDetails>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import enterpriseTable from './enterpriseTable/index'
import Add from './enterpriseTable/add'

import Edit from '@/Form/Creditbilladj/edit'
export default {
  data () {
    return {
      mainData:{},
      mainAreaData:[],
      detailInfo:''
    }
  },
  components:{
    enterpriseTable,
    Add,
    Edit,
    BaseInfo
  },
  methods:{
    async queryMainData (id) {
      const res = await this.$api.requested({
        "id": "20221008155203",
        "version":1,
        "content": {
            "sa_creditbillid":this.$route.query.id
        }
      })
      this.mainData = res.data
      this.changeDataStructure()
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.$router.replace({path:'/creditbilladjDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    /* 审核 */
    async checkBuill(data) {
      if(data.status != '新建') return
      let res = this.$api.requested({
        "id": "20221008155303",
        "version":1,
        "content": {
            "sa_creditbillid":data.sa_creditbillid
        }
      })
      this.tool.showMessage(res,() => {
        this.queryMainData()
      })
    },
    changeDataStructure () {
      let that = this
      this.mainAreaData = [
        {
          label:'额度单号',
          value: this.mainData.billno
        },
        {
          label:'单据日期',
          value: this.mainData.createdate
        },
        {
          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.remarks
        },
      ]
      this.detailInfo = {
        baseInfo: [
          {
            label:'额度单号',
            value: this.mainData.billno
          },
          {
            label:'单据日期',
            value: this.mainData.createdate
          },
          {
            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.remarks
          },
        ],
        systemInfo: [
          {label:'创建人',value:this.mainData.createby},
          {label:'创建时间',value:this.mainData.createdate},
          {label:'审核人',value:this.mainData.checkby},
          {label:'审核时间',value:this.mainData.checkdate},
        ]
      }
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created () {
    // 验证权限
    // this.tool.checkAuth(this.$route.name,'update')?'':this.$router.go(-1)
  },
}

</script>
<style>
</style>