<!--拆单审核中的申请信息部分-->
<template>
    <div v-if="detail">
        <el-descriptions :column="4" v-if="order">
            <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('订单状态')">
                <el-tag size="small">
                    <!-- <dict-tag :type="DICT_TYPE.ORDER_STATUS" :value="order.status" /> -->
                    {{order.statusMsg}}
                </el-tag>
            </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('目的仓')">
                {{order.logisticsInfoDto.destAddressZh}}
            </el-descriptions-item>
        </el-descriptions>

        <template v-for="item in detail.orderSplitBackVOList">
            <div class="title mt-20" :key="item.orderNo">
                <span class="mr-10">{{item.orderNo}}</span>
                <dict-tag class="mr-10" :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="item.transportId" />
                <span class="mr-10" v-if="item.channelName">{{item.channelName}}</span>
                <span>{{$t('发往')}}{{item.dstWarehouseName}}</span>
            </div>
            <el-table :data="item.orderSplitItemBackVOList" :key="'items-' + item.orderNo">
                <el-table-column :label="$t('序号')">
                    <template slot-scope="scope">{{scope.$index+1}}</template>
                </el-table-column>
                <el-table-column :label="$t('中文品名')">
                    <template slot-scope="{row}">{{row.prodTitleZh}}</template>
                </el-table-column>
                <el-table-column :label="$t('英文品名')">
                    <template slot-scope="{row}">{{row.prodTitleEn}}</template>
                </el-table-column>
                <el-table-column :label="$t('品牌')">
                    <template slot-scope="{row}">
                        <dict-tag :type="DICT_TYPE.ECW_IS_BRAND" :value="row.brandType" />
                    </template>
                </el-table-column>
                <el-table-column :label="$t('入仓体积')">
                    <template slot-scope="{row}">{{row.volume}} m³</template>
                </el-table-column>
                <el-table-column :label="$t('收费体积')">
                  <template slot-scope="{row}">{{row.chargeVolume}} m³</template>
                </el-table-column>
                <el-table-column :label="$t('入仓重量')">
                    <template slot-scope="{row}">{{row.weight}}kg</template>
                </el-table-column>
                <el-table-column :label="$t('收费重量')">
                  <template slot-scope="{row}">{{row.chargeWeight}}kg</template>
                </el-table-column>
                <el-table-column :label="$t('箱数')">
                    <template slot-scope="{row}">
                      <el-button type="text" @click="showWarehouseRecord(row)">{{row.num}}</el-button>
                    </template>
                </el-table-column>
                <el-table-column :label="$t('数量')">
                    <template slot-scope="{row}">{{row.quantity}}</template>
                </el-table-column>
              <el-table-column :label="$t('货值')">
                <template slot-scope="{row}">{{row.worth}}{{$t('元')}}</template>
              </el-table-column>
              <el-table-column :label="$t('成交单价')" align="center" min-width="220px" v-if="[3,4].indexOf(order.transportId) > -1">
                <template slot-scope="scope">
                  <template v-if="scope.row.charging != 1">
                    <div class="flex">
                      {{$t('运费')}}
                      <el-input v-model="scope.row.oneSeaFreight" disabled size="mini" style="width: 80px"></el-input>
                      {{currencyMap[scope.row.seaFreightCurrency]}} / {{unitMap[scope.row.seaFreightVolume]}}
                    </div>
                    <div class="flex">
                      {{$t('清关费')}}
                      <el-input v-model="scope.row.oneClearanceFreight" disabled size="mini" style="width: 80px"></el-input>
                      {{currencyMap[scope.row.clearanceFreightCurrency]}} / {{unitMap[scope.row.clearanceFreightVolume]}}
                    </div>
                  </template>
                  <template v-else>
                    {{$t('全包价')}}<el-input v-model="scope.row.oneSeaFreight" @change="updateField(scope.row, 'oneSeaFreight')" size="mini" style="width: 80px"></el-input>
                    {{currencyMap[scope.row.currencyId]}}
                    {{unitMap[scope.row.clearanceFreightVolume]}}
                  </template>
                </template>
              </el-table-column>
            </el-table>
        </template>
      <warehouse-record v-if="currentWarehouseRecord" :list="currentWarehouseRecord" append-to-body @close="currentWarehouseRecord=null"></warehouse-record>
    </div>
</template>
<script>
import {getOrder} from '@/api/ecw/order'
import {getBoxApproval} from '@/api/ecw/box'
import {getChannel} from '@/api/ecw/channel'
import WarehouseRecord from "@/views/ecw/order/splitApply/components/WarehouseRecord";
import Template from "@/views/cms/template/index.vue";
import {getCurrencyList} from "@/api/ecw/currency";
import {getUnitList} from "@/api/ecw/unit";
export default {
  components: {Template, WarehouseRecord},
  props:{
        id: [String, Number]
    },
    data(){
        return {
            detail: null,
            order: null,
            channel: null,
            // 查看入仓记录的条目
            currentWarehouseRecord: null,
            currencyList:[],
            unitList: []
        }
    },
    watch:{
        id(){
            this.getData()
        },
        detail(){
            this.getOrder()
        },
        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
      }
    },
    created(){
        if(this.id){
            this.getData()
        }
    },
    methods:{
        getData(){
            getBoxApproval({id: this.id}).then(res => {
                this.detail = JSON.parse(res.data.details)
            })
        },
        getOrder(){
            getOrder(this.detail.orderId).then(res => {
                this.order = res.data

                if([3, 4].indexOf(this.order.transportId) > -1){
                  getCurrencyList().then(res => this.currencyList = res.data)
                  getUnitList().then(res => this.unitList = res.data)
                }
            })
        },
        getChannel(){
            getChannel(this.order.channelId).then(res => {
                this.channel = res.data
            })
        },
        showWarehouseRecord(row){
          if(!row.specsRecordVOList){
            return this.$message.info(this.$t('暂无入仓记录'))
          }
          this.currentWarehouseRecord = row.specsRecordVOList
        }
    }
}
</script>
<style scoped lang="scss">
.title{
    padding: 10px 0;
    span{
        font-size: 14px;
        font-weight: bold;
    }
}
</style>