<!--拆单审核中的申请信息部分-->
<template>
    <div v-if="order">
        <el-descriptions :column="3" 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.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-item :label="$t('异常描述')+':'" :span="2">
                {{$l(orderExceptionData.orderExceptionDescVO, 'desc')}}
            </el-descriptions-item>
        </el-descriptions>
        <div v-for="(row,index) in orderItemData" :key="row.orderItemId">
            <div style="font-weight:600;font-size:14px;margin-bottom:10px">品名{{parseInt(index)+1}}:{{$l(row, 'prodTitle')}}</div>
            <div v-if="row.charging ==1"  class="price_list">

               <span>旧成交价:</span>
                 <div>
                   <div v-if="!row.freightFee">
                    <span>{{$t('全包价')}}:</span>
                    <span>{{$t('未报价')}}</span>
                   </div>
                   <div v-else>
                    <span>{{$t('全包价')}}:</span>
                    <span>【{{row.freightFee}} {{currencyMap[row.freightCurrencyId]}} / {{unitMap[row.freightUnitId]}} 】</span>
                  </div>
                 </div>
            </div>
            <div v-else class="price_list">
                 <span>旧成交价:</span>
                 <div>
                   <div v-if="!row.freightFee">
                     <span>{{$t('运费')}}:</span>
                     <span>{{$t('未报价')}}</span>
                    </div>
                    <div v-else>
                     <span>{{$t('运费')}}:</span>
                     <span>【{{row.freightFee}} {{currencyMap[row.freightCurrencyId]}} / {{unitMap[row.freightUnitId]}} 】</span>
                   </div>
                 </div>
                 <div>
                   <div v-if="!row.clearanceFee">
                     <span >{{$t('清关费')}}:</span>
                     <span>{{$t('未报价')}}</span>
                    </div>
                    <div v-else>
                     <span>{{$t('清关费')}}:</span>
                     <span>【{{row.clearanceFee}} {{currencyMap[row.clearanceCurrencyId]}} / {{unitMap[row.clearanceUnitId]}} 】</span>
                   </div>
                 </div>
              </div>
              <div v-if="loopOrderItem.length>index&&loopOrderItem[index].charging ==1"  class="price_list">
                 <span>新成交价:</span>
                   <div>
                     <div v-if="!loopOrderItem[index].freightFee">
                      <span >{{$t('全包价')}}:</span>
                      <span>{{$t('未报价')}}</span>
                     </div>
                     <div v-else>
                      <span >{{$t('全包价')}}:</span>
                      <span>【{{loopOrderItem[index].freightFee}} {{currencyMap[loopOrderItem[index].freightCurrencyId]}} / {{unitMap[loopOrderItem[index].freightUnitId]}} 】</span>
                    </div>
                   </div>
              </div>
              <div v-else-if="loopOrderItem.length>index"  class="price_list">
                   <span>新成交价:</span>
                   <div>
                     <div v-if="!loopOrderItem[index].freightFee">
                       <span>{{$t('运费')}}:</span>
                       <span>{{$t('未报价')}}</span>
                      </div>
                      <div v-else>
                       <span >{{$t('运费')}}:</span>
                       <span>【{{loopOrderItem[index].freightFee}} {{currencyMap[loopOrderItem[index].freightCurrencyId]}} / {{unitMap[loopOrderItem[index].freightUnitId]}} 】</span>
                     </div>
                   </div>
                   <div>
                     <div v-if="!loopOrderItem[index].clearanceFee">
                       <span >{{$t('清关费')}}:</span>
                       <span>{{$t('未报价')}}</span>
                      </div>
                      <div v-else>
                       <span>{{$t('清关费')}}:</span>
                       <span>【{{loopOrderItem[index].clearanceFee}} {{currencyMap[loopOrderItem[index].clearanceCurrencyId]}} / {{unitMap[loopOrderItem[index].clearanceUnitId]}} 】</span>
                     </div>
                   </div>
                </div>
          </div>
        <!-- <div v-for="row in loopOrderItem" :key="row.orderItemId"> -->

          <!-- </div> -->
          <el-descriptions :column="3" v-if="order" :colon="false">
              <el-descriptions-item :label="$t('备注')+':'" :span="2">
                  {{orderExceptionData.orderExceptionNotes||'/'}}
              </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: 'overweightException',
    props:{
        id: [String, Number],
        path: String
    },
    data(){
        return {
            orderExceptionData: null,
            order: null,
            channel: null,
            unitList:[],
            currencyList:[],
            detail:null,
            loopOrderItem:[],
            orderItemData:[]
        }
    },
    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(this.orderExceptionData.orderExceptionRemark){
                  this.orderExceptionData.orderExceptionRemark=JSON.parse(this.orderExceptionData.orderExceptionRemark)
                }
                if(res.data.oldPriceJson){
                  this.orderItemData = JSON.parse(res.data.oldPriceJson)
                }
                if(res.data.orderId){
                    getOrder(res.data.orderId).then(res => {
                        this.order = res.data
                        this.orderItemData.map(v=>{
                           let item = this.order.orderItemVOList.find(vs=>vs.orderItemId==v.orderItemId)
                           if(item){
                             v.prodTitleZh = item.prodTitleZh
                             v.prodTitleEn = item.prodTitleEn
                           }
                        })
                        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
          that.loopOrderItem = []
          getOrderExceptionChannelPriceList({orderId:orderId,exceptionId:this.orderExceptionData.id,exceptionResultId:parseInt(that.id)}).then(res=>{
            if(res.code==0&&res.data.length>0){
              that.orderItemData.map(v=>{
               let item = res.data.find(vs=>vs.orderItemId==v.orderItemId)
               let orderItem = {}
               if(item){
                 // orderItem.oneSeaFreight = item.freightFee
                 // orderItem.seaFreightCurrency = item.freightCurrencyId
                 // orderItem.seaFreightVolume = item.freightUnitId
                 // orderItem.oneClearanceFreight = item.clearanceFee
                 // orderItem.clearanceFreightCurrency = item.clearanceCurrencyId
                 // orderItem.clearanceFreightVolume = item.clearanceUnitId
                 item.charging = v.charging
                 that.loopOrderItem.push(item)
                 console.log(that.loopOrderItem)
                 // that.orderItemData.push(v)
               }
              })
            }

          })
        }
    }
}
</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;
}
  .price_list{
    display: flex;
    align-items: center;
    margin-right:10px;
    font-weight: 700;
    font-size: 14px;
    color:#333;
    margin-bottom:10px;
  }
  .price_list div{

  }
</style>