<template>
<div>
  <h1>
    申请信息【订单信息】
  </h1>
  <el-table  v-if="type === 1">
    <el-table-column
      label="订单编号">
    </el-table-column>
    <el-table-column
      label="唛头">
    </el-table-column>
    <el-table-column
      label="已到箱数/总箱数">
    </el-table-column>
    <el-table-column
      label="下单统计">
    </el-table-column>
    <el-table-column
      label="入仓统计">
    </el-table-column>
    <el-table-column
      label="入仓时间">
    </el-table-column>
    <el-table-column
      label="运输方式">
    </el-table-column>
    <el-table-column
      label="出货渠道">
    </el-table-column>
    <el-table-column
    label="始发仓">
  </el-table-column>
    <el-table-column
    label="目的地">
  </el-table-column>
    <el-table-column
    label="发货人">
  </el-table-column>
    <el-table-column
      label="收货人">
    </el-table-column>
  </el-table>
  <el-descriptions  v-else :column="4" border>
    <el-descriptions-item label="订单号">{{FeeDetails.orderNo}}</el-descriptions-item>
    <el-descriptions-item label="运输方式">
      <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="FeeDetails.transportId"></dict-tag>
    </el-descriptions-item>
    <el-descriptions-item label="出货方式">
      {{selectChannel(FeeDetails.channelId)}}
    </el-descriptions-item>
    <el-descriptions-item label="订单状态">
      <dict-tag :type="DICT_TYPE.ORDER_ABNORMAL_STATE" :value="FeeDetails.abnormalState"></dict-tag>
    </el-descriptions-item>
    <el-descriptions-item label="唛头">
      {{FeeDetails.marks}}
    </el-descriptions-item>
    <el-descriptions-item label="始发仓">{{FeeDetails.startWarehouse}}</el-descriptions-item>
    <el-descriptions-item label="目的仓">{{FeeDetails.destWarehouse}}</el-descriptions-item>
  </el-descriptions>
  <div v-if="type === 1">
    <p>
      申请说明
    </p>
    <div >
      从【{{selectWarehouse(FeeDetails.details && FeeDetails.details.warehouseInId ? FeeDetails.details.warehouseInId : '' )}}】 调到
        【{{selectWarehouse(FeeDetails.details && FeeDetails.details.warehouseOutId ? FeeDetails.details.warehouseOutId : '' )}}】
    </div>
  </div>
  <div v-if="type === 2">
    <p>申请理由</p>
    <div>
      {{FeeDetails.remarks}}
    </div>
  </div>
  <div v-if="type === 3">
    <p>申请理由</p>
    <div>
      {{ FeeDetails.details && FeeDetails.details.reason ? FeeDetails.details.reason :''}}
    </div>
  </div>
</div>
</template>

<script>
import {
  warehouseApprovalGetByFormId,
  warehouseApprovalGetById,
  warehouseAreaPositionList
} from "@/api/ecw/batchSingleApplication";
import {applicationGetOrderByProcessId, feeApplicationGet, getOrder,} from "@/api/ecw/order";
import { getChannelList } from '@/api/ecw/channel';
export default {
  props:{
    type:{
      type: Number,
       default:1,
    },
    processId:{
      type:[Number,String],
    }
  },
  name: "warehouseDetails",
  data(){
    return{
      FeeDetails:{},
      transfer:{},
      warehouseList:[],
      channelList:[],
      processInstanceID:undefined
    }
  },
  created() {
    getChannelList().then(r => this.channelList = r.data);
    warehouseAreaPositionList().then(r => this.warehouseList = r.data)

       if(this.type === 2){
         feeApplicationGet({id:this.processId}).then(r => {
           if(r.code === 0){
             this.processInstanceID = r.data.bpmProcessId;
             this.getDetails()
           }
         })
       }else {
         warehouseApprovalGetById({id:this.processId}).then(r => {
           if(r.code === 0){
             this.processInstanceID = r.data.formId;
             this.getDetails()
           }
         })
       }
  },
  methods:{
    selectWarehouse(val){
      if(this.warehouseList.length > 0 && !!val){
       return  this.warehouseList.find(e => e.id === val).titleZh
      }
        return ''
    },
    selectChannel(val){
      if(this.channelList.length > 0 && !!val) return this.channelList.find(e => e.channelId === val).nameEn
      return ''
    },
    getDetails(){
      switch (this.type){
        case 1:
          //调仓
          warehouseApprovalGetByFormId({formId:this.processInstanceID}).then( r => {
            this.FeeDetails = r.data
            this.FeeDetails.details = JSON.parse(r.data.details)

          });
          break;
        case 2:
          // 费用申请
          applicationGetOrderByProcessId({processId:this.processInstanceID}).then(r => {
            this.FeeDetails = r.data
          })
          break;
        case 3:
          //退仓
          warehouseApprovalGetByFormId({formId:this.processInstanceID}).then( res => {
            getOrder(res.data.orderIds).then(r =>{
              this.FeeDetails = r.data
              this.FeeDetails.details = JSON.parse(res.data.details)
            })
          });
          break;
      }
    }

  }
}
</script>

<style scoped>

</style>
