<!--拆单审核中的申请信息部分-->
<template>
    <div v-if="detail && 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-item :label="$t('申请理由')" v-if="type == 1 || type == 2" :span="4">
                <div class="bold">
                    <div>
                        {{detail.charging ? $t('原全包价') : $t('原运费')}}：{{detail.orgFreight}} {{ currencyMap[detail.freightCurrency] }} / {{ unitMap[detail.freightVolume] }}，
                        {{detail.charging ? $t('新全包价') : $t('新运费')}}：{{detail.freight}} {{ currencyMap[detail.freightCurrency] }} / {{ unitMap[detail.freightVolume] }}
                    </div>
                    <div v-if="!detail.charging">
                        {{$t('原清关费')}}：{{detail.orgClearanceFreight}} {{ currencyMap[detail.clearanceFreightCurrency] }} / {{ unitMap[detail.clearanceFreightVolume] }}，
                        {{$t('新清关费')}}：{{detail.clearanceFreight}} {{ currencyMap[detail.clearanceFreightCurrency] }} / {{ unitMap[detail.clearanceFreightVolume] }}
                    </div>
                </div>
            </el-descriptions-item>
            <!-- 优惠申请 -->
            <el-descriptions-item :label="$t('申请理由')" v-if="type == 31 || type == 32" :span="4">
                <div class="bold" v-for="(item,index) in detail.batchApplyOrderItemDetailVOList" :key="index">
                  <div>{{index+1}}.【{{$l(item, 'prodTitle')}}】</div>
                    <div>
                        {{item.charging ? $t('原全包价') : $t('原运费')}}：{{item.orgFreight}} {{ currencyMap[item.freightCurrency] }} / {{ unitMap[item.freightVolume] }}，
                        {{item.charging ? $t('新全包价') : $t('新运费')}}：{{item.freight}} {{ currencyMap[item.freightCurrency] }} / {{ unitMap[item.freightVolume] }}
                    </div>
                    <div v-if="!item.charging">
                        {{$t('原清关费')}}：{{item.orgClearanceFreight}} {{ currencyMap[item.clearanceFreightCurrency] }} / {{ unitMap[item.clearanceFreightVolume] }}，
                        {{$t('新清关费')}}：{{item.clearanceFreight}} {{ currencyMap[item.clearanceFreightCurrency] }} / {{ unitMap[item.clearanceFreightVolume] }}
                    </div>
                </div>
            </el-descriptions-item>
            <!-- 重泡货 -->
            <el-descriptions-item :label="$t('申请理由')" v-if="type == 4 || type ==5" :span="4">
                <div class="bold" v-if="type == 4">
                    {{$t('重货优惠标准申请为:{new}kg/cbm,原重货标准:{old}kg/cbm', {
                        new: detail.wVolume,
                        old: detail.orgWVolume
                    })}}
                </div>
                <div class="bold" v-if="type == 5">
                    {{$t('泡货优惠标准申请为:{new}kg/cbm,原泡货标准:{old}kg/cbm', {
                        new: detail.vWeight,
                        old: detail.orgVWeight
                    })}}
                </div>
            </el-descriptions-item>

            <!-- 佣金设置 -->
            <el-descriptions-item :label="$t('申请理由')" v-if="type == 3" :span="4">
                <div class="bold">
                    <div class="item">
                        {{$t('商品')}}：{{$l(detail, 'prodTitle')}}
                    </div>
                    <div class="item">
                        {{$t('佣金规则')}}：{{$t('从【{oldType}】改为【{newType}】', {
                        oldType: getDictDataLabel(DICT_TYPE.COMMISSION_TYPE, detail.orgCommissionType) ,
                        newType: getDictDataLabel(DICT_TYPE.COMMISSION_TYPE, detail.commissionType),
                        })}}
                    </div>

                    <div>
                        {{$t('原运费')}}：{{detail.orgFreight}}{{currencyMap[detail.freightCurrency]}} / {{unitMap[detail.freightVolume]}}
                    </div>
                    <div>
                        {{$t('新运费')}}：{{Decimal(detail.orgFreight || 0).minus(detail.orgLightCommissionAmount || 0).plus(detail.lightCommissionAmount || 0)}}{{currencyMap[detail.freightCurrency]}} / {{unitMap[detail.freightVolume]}}
                    </div>
                    <div>
                       {{$t('成本价')}}：{{Decimal(detail.orgFreight || 0).minus(detail.orgLightCommissionAmount || 0).minus(detail.shadeCommissionAmount || 0)}} {{ currencyMap[detail.freightCurrency] }} / {{ unitMap[detail.freightVolume] }}
                    </div>
                    <div>
                        {{$t('明佣')}}：{{ detail.lightCommissionAmount}}{{currencyMap[detail.freightCurrency]}} / {{unitMap[detail.freightVolume]}}
                    </div>
                    <div>
                        {{$t('暗佣')}}：{{detail.shadeCommissionAmount }}{{currencyMap[detail.freightCurrency]}} / {{unitMap[detail.freightVolume]}}
                    </div>
                </div>
            </el-descriptions-item>

        </el-descriptions>
        <!-- 泡重优惠申请 -->
        <div v-if="type == 29" style="font-size: 14px; line-height: 1.5">
          <div>{{$t('原泡重')}}:{{detail.orgVWeight}}kg</div>
          <div>{{$t('新泡重')}}:{{detail.vWeight}}kg</div>
        </div>

    </div>
</template>
<script>
import {getOrder, getApproval} from '@/api/ecw/order'
import {getChannel} from '@/api/ecw/channel'
import {getUnitList} from "@/api/ecw/unit"
import { getCurrencyList } from '@/api/ecw/currency'
import Decimal from 'decimal.js'
/*
type含义
优惠申请	1
管理优惠	2
佣金设置	3
重货优惠	4
泡货优惠	5
拆单申请	6
控货订单放货修改	7
控货订单反复核	8
控货订单已放货记录调货审批	9
控货订单取消放货	10
合单申请	11
费用申请	12
调仓申请	13
订单修改	14
预装审核	18
封柜审核	19
入仓修改	22
退仓	23
*/
export default {
    name: 'OrderApprovalDetail',
    props:{
        id: [String, Number],
        path: String
    },
    data(){
        return {
            type: null,
            detail: null,
            order: null,
            channel: null,
            ShowLandingBill: false,

            unitList:[],
            currencyList:[],
        }
    },
    watch:{
        id(){
            this.getData()
        },
        detail(){
            this.getOrder()
        },
        order(){
            if(this.order.channelId){
                this.getChannel()
            }
        },
        type(){
            if([1,2,3,4,5,31,32].indexOf(this.type) > -1){
                // 加载费用体积单位
                getUnitList().then(res => this.unitList = res.data)
                getCurrencyList().then(res => this.currencyList = res.data)
            }
        }
    },
    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
        }
    },
    created(){
        if(this.id){
            this.getData()
        }
    },
    methods:{
        Decimal,
        getData(){
            getApproval(this.id).then(res => {
                this.type = res.data.type
                this.detail = JSON.parse(res.data.details)
                console.log(this.detail)
            })
        },
        getOrder(){
            getOrder(this.detail.orderId).then(res => {
                this.order = res.data
            })
        },
        getChannel(){
            getChannel(this.order.channelId).then(res => {
                this.channel = res.data
            })
        },/*
        getBillOfLandingInProcessing(){
            getBillOfLandingInProcessing({orderId: this.detail.orderId}).then(res => {
                console.log(res)
            })
        } */
    }
}
</script>
<style scoped lang="scss">
.title{
    padding: 10px 0;
    span{
        font-size: 14px;
        font-weight: bold;
    }
}
.bold{
    font-weight: bold;
}
</style>
