<!--拆单审核中的申请信息部分-->
<template>
    <div v-if="order">
        <el-descriptions :column="4" v-if="order" :colon="false">
            <el-descriptions-item :label="$t('订单号')">{{order.orderNo}}</el-descriptions-item>
            <el-descriptions-item :label="$t('运输方式')">
                <dict-tag class="mr-10" :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="order.transportId" />
            </el-descriptions-item>
            <el-descriptions-item :label="$t('出货方式')">
                {{channel ? channel.nameZh : '/'}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('订单状态')">
                {{order.statusMsg}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('唛头')">{{order.marks}}</el-descriptions-item>
            <el-descriptions-item :label="$t('始发仓')">
                {{order.logisticsInfoDto.startTitleZh}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('目的仓')" :span="2">
                {{order.logisticsInfoDto.destAddressZh}}
            </el-descriptions-item>
        </el-descriptions>
        <el-descriptions v-if="order" :colon="false">
            <el-descriptions-item :label="$t('申请理由')" :span="2">
                 {{$l(orderExceptionData.orderExceptionDescVO, 'desc')}}
            </el-descriptions-item>
        </el-descriptions>
        <el-table border :data="order.orderItemVOList">
          <el-table-column :label="$t('序号')" align="center" prop="id" type="index">
              <template slot-scope="scope">
                  <span>{{scope.$index + 1}}</span>
              </template>
            </el-table-column>
          <el-table-column :label="$t('中文名')" align="center"  prop="prodTitleZh" min-width="60" />
          <el-table-column :label="$t('英文名')" align="center"  prop="prodTitleEn" min-width="60" />
          <el-table-column :label="$t('品牌')" align="center" min-width="50" prop="brandType">
            <template slot-scope="scope">
                <dict-tag :type="DICT_TYPE.ECW_IS_BRAND" :value="scope.row.brandType"></dict-tag>
              </template>
            </el-table-column>
          <el-table-column :label="$t('填单箱数')" prop="num" min-width="60" />
          <!-- v2.0  入仓特性异常 -->
          <el-table-column :label="$t('填单特性')" prop="prodAttrIds" min-width="100">
            <template slot-scope="scope">
                  {{getProdAtrr(scope.row.prodAttrIds)}}
              </template>
            </el-table-column>
          <el-table-column :label="$t('入仓箱数')" min-width="60">
            <template slot-scope="scope">
                {{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.cartonsNum:0}}
            </template>
          </el-table-column>
          <!-- v2.0  入仓特性异常 -->
          <el-table-column :label="$t('入仓特性')" prop="num" min-width="100">
          <template slot-scope="scope">
                {{scope.row.warehouseInInfoVO&&scope.row.warehouseInInfoVO.prodAttrIds?getProdAtrr(scope.row.warehouseInInfoVO.prodAttrIds):''}}
            </template>
          </el-table-column>
          <el-table-column :label="$t('方数')" prop="volume" min-width="50">
            <template slot-scope="scope">
                {{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.volume:0}}
              </template>
            </el-table-column>
          <el-table-column :label="$t('重量')" prop="weight" min-width="50">
            <template slot-scope="scope">
                {{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.weight:0}}
              </template>
            </el-table-column>
          <el-table-column :label="$t('数量')" prop="quantity" min-width="50">
            <template slot-scope="scope">
                {{scope.row.warehouseInInfoVO?scope.row.warehouseInInfoVO.quantityAll:0}}
              </template>
            </el-table-column>
          <el-table-column :label="$t('货值')" prop="worth" min-width="50" />
          <el-table-column :label="$t('运费/全包价')" prop="quantity" min-width="160">
            <template slot-scope="scope" >
               <div v-if="scope.row.charging ==1" class="channel">
                     <span v-if="!scope.row.oneSeaFreight">{{$t('全包价')}}:{{$t('未报价')}}</span>
                     <span v-else>{{$t('全包价')}}:{{scope.row.oneSeaFreight}} {{currencyMap[scope.row.seaFreightCurrency]}} / {{unitMap[scope.row.seaFreightVolume]}}</span>
               </div>
               <div v-else class="channel">
                   <span v-if="!scope.row.oneSeaFreight">{{$t('运费')}}:{{$t('未报价')}}</span>
                   <span v-else>{{$t('运费')}}:{{scope.row.oneSeaFreight}} {{currencyMap[scope.row.seaFreightCurrency]}} / {{unitMap[scope.row.seaFreightVolume]}}</span>
               </div>
            </template>
          </el-table-column>
          <el-table-column :label="$t('清关费')" prop="quantity" min-width="160">
            <template slot-scope="scope">
                 <div class="channel">
                     <span v-if="!scope.row.oneClearanceFreight">{{$t('未报价')}}</span>
                     <span v-else>{{scope.row.oneClearanceFreight}} {{currencyMap[scope.row.clearanceFreightCurrency]}} / {{unitMap[scope.row.clearanceFreightVolume]}}</span>
                 </div>
            </template>
          </el-table-column>
        </el-table>
        <el-descriptions :colon="false" style="margin-top:10px">
            <el-descriptions-item :label="$t('备注')" :span="2">
                 {{orderExceptionData.applyNotes}}
            </el-descriptions-item>
        </el-descriptions>
    </div>
</template>
<script>
import {getOrder} from '@/api/ecw/order'
import {getChannel} from '@/api/ecw/channel'
import {getUnitList} from "@/api/ecw/unit"
import { getCurrencyList } from '@/api/ecw/currency'
import {getProductAttrList} from '@/api/ecw/productAttr'
import Decimal from 'decimal.js'
import {getExceptionDetailByBusinessId,getOrderExceptionChannelPriceList} from '@/api/ecw/orderException'

export default {
    name: 'NotShipingChannel',
    props:{
        id: [String, Number],
        path: String
    },
    data(){
        return {
            orderExceptionData: null,
            order: null,
            channel: null,
            unitList:[],
            currencyList:[],
            detail:null
        }
    },
    watch:{
        id(){
            this.getData()
        },
        order(){
            if(this.order.channelId){
                this.getChannel()
            }
        },
    },
    computed:{
        currencyMap(){
            let map = {}
            this.currencyList.forEach(item => {
                map[item.id] = this.$l(item, 'title')
            })
            return map
        },
        unitMap(){
            let map = {}
            this.unitList.forEach(item => {
                map[item.id] = this.$l(item, 'title')
            })
            return map
        }
    },
    async created(){
        await getUnitList().then(res => this.unitList = res.data)
        await getCurrencyList().then(res => this.currencyList = res.data)
        this.productAttrList = (await getProductAttrList()).data
        if(this.id){
            this.getData()
        }
    },
    methods:{
        Decimal,
        getData(){
            getExceptionDetailByBusinessId({businessId:this.id}).then(res => {
                this.orderExceptionData = res.data
                if(res.data.orderId){
                    getOrder(res.data.orderId).then(res => {
                        this.order = res.data
                        this.getExceptionPriceList(res.data.orderId)
                    })
                }
            })
        },
        getProdAtrr(ids){
          if(!ids) return ''
          let attr = []

          let attrIds = ids.split(',')
          this.productAttrList.forEach(item=>{
             if(attrIds.indexOf(item.id) > -1||attrIds.indexOf(item.id+'')>-1){
               attr.push(this.$l(item, 'attrName'))
             }
          })
          return attr.join(',')
        },
        getChannel(){
            getChannel(this.order.channelId).then(res => {
                this.channel = res.data
            })
        },
        getExceptionPriceList(orderId){
          let that = this
          getOrderExceptionChannelPriceList({orderId:orderId,exceptionId:this.orderExceptionData.id,exceptionResultId:parseInt(that.id)}).then(res=>{
            if(res.code==0&&res.data.length>0){
              that.order.orderItemVOList.map(v=>{
               var item = res.data.find(vs=>vs.orderItemId==v.orderItemId)
               if(item){
                 v.oneSeaFreight = item.freightFee
                 v.seaFreightCurrency = item.freightCurrencyId
                 v.seaFreightVolume = item.freightUnitId
                 v.oneClearanceFreight = item.clearanceFee
                 v.clearanceFreightCurrency = item.clearanceCurrencyId
                 v.clearanceFreightVolume = item.clearanceUnitId
               }
              })
            }

          })
        }
    }
}
</script>
<style scoped lang="scss">
.title{
    padding: 10px 0;
    span{
        font-size: 14px;
        font-weight: bold;
    }
}
.bold{
    font-weight: bold;
}
::v-deep .prepay_exception_detail .el-form-item{
    margin-bottom: 0;
}
</style>