<template>
<!-- :tabs="['详细信息']" -->
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.billno"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20230104160703"
        idname="sa_aftersalesmagid"
        ownertable="sa_aftersalesmag"
        delApiId="20230104160803"
        :statusCheck="[{key:'status',value:'审核'},{key:'status',value:'复核'},{key:'status',value:'提交'}]"
        tags=""
        :tabs="['商品明细','详细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)"
        @updateParam="updateParam">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <Edit v-if="tool.checkAuth($route.name,'update') && mainData.status == '新建'" class="inline-16" @onSuccess="queryMainData()" :data="mainData" />
        <customBtn
          class="inline-16"
          btnName="提 交"
          message="确定提交当前返退单吗?"
          idName="20230105161603"
          keyName="sa_aftersalesmagid"
          :id="$route.query.id"
          @onSuccess="queryMainData()"
          v-if="mainData.status == '新建' && tool.checkAuth($route.name,'submit')"
        />
        <customBtn
          class="inline-16"
          btnName="取 消 提 交"
          message="当前返退单确定取消提交吗?"
          idName="20230105161703"
          keyName="sa_aftersalesmagid"
          :id="$route.query.id"
          @onSuccess="queryMainData()" 
          v-if="mainData.status == '提交' && tool.checkAuth($route.name,'cancelSubmit')"
        />
        <Check 
          class="inline-16"
          @onSuccess="queryMainData()"
          v-if="mainData.status == '提交' && tool.checkAuth($route.name,'check')"
          ></Check>
        <customBtn
          class="inline-16"
          btnName="反 审 核"
          message="确定反审核当前返退单吗?"
          idName="20230104161103"
          keyName="sa_aftersalesmagid"
          :paramData="[{key:'ischeck',value:false}]"
          :id="$route.query.id"
          @onSuccess="queryMainData()" 
          v-if="mainData.status == '审核' && tool.checkAuth($route.name,'cancelCheck')"
        />
        <customBtn
          class="inline-16"
          btnName="复 核"
          message="确定复核当前返退单吗?"
          idName="20230104160903"
          keyName="sa_aftersalesmagid"
          :id="$route.query.id"
          @onSuccess="queryMainData()" 
          v-if="mainData.status == '审核' && tool.checkAuth($route.name,'reCheck')"
        />
      </div>
      <div slot="slot0" >
        <productDetail ref="productDetail">
          <addProduct v-if="mainData.status == '新建' && tool.checkAuth($route.name,'productDetailManage') && mainData" @onSuccess="$refs.productDetail.listData()" slot="addProduct" :data="mainData" />
          <template v-slot:editProduct="scope">
            <el-button v-if="mainData.status == '新建' && tool.checkAuth($route.name,'productDetailManage')" class="inline-16" type="text" size="mini" :disabled="!isEdit" @click="$refs.productDetail.currentProduct=scope.data">编 辑</el-button>            
          </template>
          <template v-slot:delProduct="scope">
            <delete-btn 
              message="确定删除当前商品吗?"
              nameId="20230105111203" 
              nameKey="sa_aftersalesmag_itemsids" 
              :id="scope.data.sa_aftersalesmag_itemsid"
              @deleteSuccess="$refs.productDetail.listData()"
              v-if="mainData.status == '新建' && tool.checkAuth($route.name,'productDetailManage')"
            ></delete-btn>
          </template>
        </productDetail>
      </div>
      <div slot="slot1" >
        <base-info v-if="detailInfo" :detailInfo="detailInfo"></base-info>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import BaseInfo from '@/HDrpManagement/projectChange/modules/modules/baseInfo/baseInfo'
import Edit from '../components/edit'
import productDetail from './productDetail/index'
import addProduct from './productDetail/add'

import Check from '../components/check'
export default {
  name: "detail",
  data() {
    return {
      mainData:'',
      mainAreaData:{},
      detailInfo:'',
      isEdit:true
    }
  },
  components:{
    BaseInfo,
    Edit,
    productDetail,
    addProduct,
    Check
  },
  provide () {
    return {
      isEdit: () => this.isEdit
    }
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id": "20230104160603",
        "content": {
          "sa_aftersalesmagid": this.$route.query.id
        }
      })
      this.mainData = res.data
      this.mainData.status != '新建' ? this.isEdit = false : this.isEdit = true
      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.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '新建':
                style = {color:'#000000'}
                break;
              case '提交':
                style = {color:'#d90a0a'}
                break;
              case '审核':
                style = {color:'#52C41A'}
                break;
              case '复核':
                style = {color:'#3874f6'}
                break;
            }
            return style
          }
        },
        {
          label:'类型',
          value:this.mainData.type
        },
        {
          label:'经销商编号',
          value:this.mainData.agentnum
        },
        {
          label:'经销商',
          value:this.mainData.enterprisename
        },
        {
          label:'来源单号',
          value:this.mainData.sonum
        },
        {
          label:'订单使用返利占比',
          value:this.mainData.rebate_userate
        },
        {
          label:'订单账户',
          value:this.mainData.accountname
        },
        {
          label:'是否实物退回',
          value:this.mainData.isitemreturn ? '是' : '否'
        },
        {
          label:'退款金额',
          value:this.mainData.returnamount
        },
        {
          label:'物流单号',
          value:this.mainData.logisticno
        },
        {
          label:'原因',
          value:this.mainData.reason
        }
      ]
      this.detailInfo = {
        baseInfo:[
          {
            label:'单号',
            value:this.mainData.billno
          },
          {
            label:'单据日期',
            value:this.mainData.billdate
          },
          {
            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;
              case '复核':
                style = {color:'#3874f6'}
                break;
              }
              return style
            }
          },
          {
            label:'类型',
            value:this.mainData.type
          },
          {
            label:'经销商编号',
            value:this.mainData.agentnum
          },
          {
            label:'经销商',
            value:this.mainData.enterprisename
          },
          {
            label:'来源单号',
            value:this.mainData.sonum
          },
          {
            label:'订单使用返利占比',
            value:this.mainData.rebate_userate
          },
          {
            label:'订单账户',
            value:this.mainData.accountname
          },
          {
            label:'是否实物退回',
            value:this.mainData.isitemreturn ? '是' : '否'
          },
          {
            label:'退款金额',
            value:this.mainData.returnamount
          },
          {
            label:'物流单号',
            value:this.mainData.logisticno
          },
          {
            label:'原因',
            value:this.mainData.reason
          }
        ],
        systemInfo: [
          {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},
          {label:'复核人',value:this.mainData.recheckby},
          {label:'复核时间',value:this.mainData.recheckdate},
        ]
      }
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/afterSalesmagDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex,type:this.$route.query.type}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    updateParam (param) {
      param.content.type = this.$route.query.type
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>