<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.writeoffbillidbillno"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221124090104"
        idname="sa_writeoffbillid"
        ownertable="sa_writeoffbill"
        delApiId="20221124090304"
        :statusCheck="[{key:'status',value:'审核'}]"
        tags=""
        :tabs="['订单','详细信息']"
        @pageChange="pageChange"

        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <edit class="inline-16" :disabled="isUse" :data="mainData" @onSuccess="queryMainData" v-if="tool.checkAuth($route.name,'update')"></edit>
        <check :disabled="isUse" class="inline-16" v-if="mainData" @onSuccess="queryMainData" :data="mainData"/>
        <calc :disabled="isUse" v-if="tool.checkAuth($route.name,'calc')" class="inline-16" @onSuccess="queryMainData;$refs.orderTable.listData();queryMainData()"/>
      </div>
      <div slot="slot0" >
        <order-table ref="orderTable" @onSuccess="queryMainData" v-if="mainData">
          <add-order :disabled="isUse" v-if="tool.checkAuth($route.name,'addOrder')" slot="addOrder" :data="mainData" @onSuccess="$refs.orderTable.listData();queryMainData()"></add-order>
          <template v-slot:editOrder="scope">
              <el-button class="inline-16" :disabled="isUse" v-if="tool.checkAuth($route.name,'editOrder')" type="text" size="mini" @click="$refs.orderTable.currentItem=scope.data">编 辑</el-button>
          </template>
          <template v-slot:delOrder="scope">
            <Del :data="scope.data" v-if="tool.checkAuth($route.name,'delOrder')" @onSuccess="$refs.orderTable.listData()" :disabled="isUse"></Del>
          </template>
        </order-table>
      </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 check from '../components/check'
import edit from '../components/edit'
import orderTable from './order/index'
import calc from './order/calc'
import addOrder from './order/addOrder'
import Del from './order/delete'
export default {
  name: "detail",
  data() {
    return {
      mainData:'',
      mainAreaData:{},
      detailInfo:'',
      /* 是否能操作 */
      isUse:false,
    }
  },
  components:{
    BaseInfo,
    check,
    orderTable,
    addOrder,
    calc,
    edit,
    Del
  },
  watch: {
    mainData: {
      handler (val) {
        val.status == '新建' ? this.isUse = false : this.isUse = true
      },
      immediate:true
    }
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20221124090804,
        "content": {
          "sa_writeoffbillid": this.$route.query.id
        }
      })
      this.mainData = res.data[0]
      console.log(this.mainData);
      this.changeDataStructure()
    },
    changeDataStructure() {
      let that = this
      this.mainAreaData = [
        {
          label:'核销单号',
          value:this.mainData.writeoffbillidbillno
        },
        {
          label:'凭证单号',
          value:this.mainData.cashbillidbillno
        },
        {
          label:'经销商简称',
          value:this.mainData.enterprisename
        },
        {
          label:'账户类型',
          value:this.mainData.accountname
        },
        
        {
          label:'未核销金额',
          value:this.mainData.unwriteoffamount
        },
        {
          label:'本次核销金额',
          value:this.mainData.writeoffamount
        },
        {
          label:'创建人',
          value:this.mainData.createby
        },
        {
          label:'审核人',
          value:this.mainData.checkby
        },
        {
          label:'状态',
          value:this.mainData.status,
          style:function () {
            let style = {}
            switch (that.mainData.status) {
              case '审核':
                style = {color: '#52C41A'}
                break;
              case '新建':
                style = {color: '#000000'}
                break;
              default:
                break;
            }
            return style
          }
        },
        {
          label:'备注',
          value:this.mainData.remarks
        },
      ]
      this.detailInfo = {
        baseInfo: [
          {
            label:'核销单号',
            value:this.mainData.writeoffbillidbillno
          },
          {
            label:'凭证单号',
            value:this.mainData.cashbillidbillno
          },
          {
            label:'企业名称',
            value:this.mainData.enterprisename
          },
          {
            label:'账户类型',
            value:this.mainData.accountname
          },
          
          {
            label:'凭证未核销金额',
            value:this.mainData.unwriteoffamount
          },
          {
            label:'本次核销金额',
            value:this.mainData.writeoffamount
          },
          {
            label:'创建人',
            value:this.mainData.createby
          },
          {
            label:'审核人',
            value:this.mainData.checkby
          },
          {
            label:'状态',
            value:this.mainData.status,
            style:function () {
              let style = {}
              switch (that.mainData.status) {
                case '审核':
                  style = {color: '#52C41A'}
                  break;
                case '新建':
                  style = {color: '#000000'}
                  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.changeby},
          {label:'最近编辑时间',value:this.mainData.changedate},
          {label:'审核人',value:this.mainData.checkby},
          {label:'最近审核时间',value:this.mainData.checkdate},
        ]
      }
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex) {
      this.$router.replace({path:'/writeoffbillDetail',query:{id:id,rowindex:rowindex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>