From 23bd9d883c076d8fe33bc754a530c7477f578416 Mon Sep 17 00:00:00 2001
From: DragonDean <dragondean@qq.com>
Date: Fri, 28 Jul 2023 00:11:41 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8B=86=E5=8D=95=E8=B4=A7?=
 =?UTF-8?q?=E5=80=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/api/ecw/orderHandle.js               |  4 +--
 src/views/ecw/order/splitApply/index.vue | 38 ++++++++++++++++++------
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/api/ecw/orderHandle.js b/src/api/ecw/orderHandle.js
index d3dc923c..061b201c 100644
--- a/src/api/ecw/orderHandle.js
+++ b/src/api/ecw/orderHandle.js
@@ -147,10 +147,10 @@ export function deleteAllSplit(orderId) {
 }
 
 // 获取拆单订单的总货值与箱数拆分记录
-export function splitItemWorthCheck(orderId) {
+export function splitItemWorthCheck(orderId, orderSplitItemId) {
   return request({
     url: '/order/split-item/worth/check',
     method: 'get',
-    params: {orderId}
+    params: {orderId, orderSplitItemId}
   })
 }
diff --git a/src/views/ecw/order/splitApply/index.vue b/src/views/ecw/order/splitApply/index.vue
index 518092f2..b14e53b1 100644
--- a/src/views/ecw/order/splitApply/index.vue
+++ b/src/views/ecw/order/splitApply/index.vue
@@ -625,13 +625,28 @@ export default {
       // 默认取以前放入的品名
       let split = this.splitData.find(item => item.id == this.splitData[this.splitIndex].id)
       this.shopForm.specsRecordVOList = []
+      let splitItemId = undefined
+      let splitItem = undefined
       if(split) {
-        let specsRecordVOList = split.orderSplitItemBackVOList.find(item => item.orderItemId == this.shopForm.orderItemId)?.specsRecordVOList || []
-        specsRecordVOList.forEach(item => {
-          const [boxGauge1, boxGauge2, boxGauge3] = item.boxGauge.split('*')
-          this.shopForm.specsRecordVOList.push({...item, boxGauge1, boxGauge2, boxGauge3})
-        })
+        splitItem = split.orderSplitItemBackVOList.find(item => item.orderItemId == this.shopForm.orderItemId)
+        if(splitItem){
+          let specsRecordVOList = splitItem.specsRecordVOList || []
+          specsRecordVOList.forEach(item => {
+            const [boxGauge1, boxGauge2, boxGauge3] = item.boxGauge.split('*')
+            this.shopForm.specsRecordVOList.push({...item, boxGauge1, boxGauge2, boxGauge3})
+          })
+
+          splitItemId = splitItem.id
+
+        }
       }
+      // 填充原来的收费数据和货值
+      this.$set(this.shopForm, 'chargeVolume', splitItem?.chargeVolume || 0)
+      this.$set(this.shopForm, 'chargeWeight', splitItem?.chargeWeight || 0)
+      this.$set(this.shopForm, 'worth', splitItem?.worth || 0)
+
+      // 获取剩余货值,排除当前品名已放入数据
+      this.getOrderLeftData(splitItemId)
     },
     'shopForm.worth'(val, oldVal){
       console.log('worth change from', oldVal, 'to', val)
@@ -1014,6 +1029,11 @@ export default {
           specsRecordVOList:this.shopForm.specsRecordVOList
         }
 
+        // 货值不能超过可拆货值
+        if(params.worth > this.orderLeftData.splitResidueWorth){
+          return this.$message.error(this.$t('货值不能超过可拆货值'))
+        }
+
         // 体积重量不能为0
         const fields = {
           'volume': this.$t('体积'),
@@ -1155,8 +1175,8 @@ export default {
 
       // 货值按照订单的总货值比例计算,所以需要判断是否是最后一次放入
       let worth = (this.orderLeftData.totalWorth * this.putin.num / this.orderLeftData.sumNum).toFixed(2)
-      // 如果是最后放入
-      if(this.orderLeftData.splitResidueNum == this.putin.num){
+      // 如果是最后放入,或者超过了剩余货值,则直接取剩余货值
+      if(this.orderLeftData.splitResidueNum == this.putin.num || worth > this.orderLeftData.splitResidueWorth){
         worth = this.orderLeftData.splitResidueWorth
       }
       this.$set(this.shopForm, 'worth', worth)
@@ -1173,8 +1193,8 @@ export default {
       this.$store.dispatch('tagsView/delCurrentView')
     },
     // 查询订单剩余数据
-    getOrderLeftData(){
-      splitItemWorthCheck(this.queryParams.orderId).then(res => {
+    getOrderLeftData(orderSplitItemId){
+      splitItemWorthCheck(this.queryParams.orderId, orderSplitItemId).then(res => {
         this.orderLeftData = res.data
       })
     }
-- 
2.22.0