From 31e9f68fb09c519403f25f73b1d27c54cf9aa133 Mon Sep 17 00:00:00 2001 From: TraeAI Date: Sat, 7 Mar 2026 17:13:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E6=A0=BC=E4=BB=B6?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E9=80=92=E9=97=AE=E9=A2=98=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E4=B8=8D=E5=90=8C=E8=A7=84=E6=A0=BC=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E4=BB=B6=E6=95=B0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=87=8D=E9=87=8F=E5=92=8C=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/freight-calculator/index.js | 155 +++++++++++++++++++++++----- pages/freight-calculator/index.wxml | 6 ++ 2 files changed, 137 insertions(+), 24 deletions(-) diff --git a/pages/freight-calculator/index.js b/pages/freight-calculator/index.js index 5e75e7b..65da3f2 100644 --- a/pages/freight-calculator/index.js +++ b/pages/freight-calculator/index.js @@ -105,6 +105,7 @@ Page({ distance: '', weight: '', volume: '', + quantity: '', waitTime: '40', // 车型信息 @@ -189,14 +190,21 @@ Page({ // 从重量规格中提取数字 const weightMatch = firstSpec.weightSpec.match(/(\d+(?:\.\d+)?)/); if (weightMatch && weightMatch.length > 1) { - const weightPerUnit = parseFloat(weightMatch[1]); - const quantity = parseInt(firstSpec.soldQuantity || goodsInfo.quantity) || 1; + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (firstSpec.weightSpec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + + const quantity = parseInt(firstSpec.quantity || goodsInfo.quantity) || 1; weight = (weightPerUnit * quantity) / 2; // 换算为公斤 } } // 计算体积 - if (goodsInfo.producting && (goodsInfo.quantity || firstSpec.soldQuantity)) { - const quantity = parseInt(firstSpec.soldQuantity || goodsInfo.quantity) || 1; + if (goodsInfo.producting && (goodsInfo.quantity || firstSpec.quantity)) { + const quantity = parseInt(firstSpec.quantity || goodsInfo.quantity) || 1; volume = this.calculateVolumeFromPackaging({ ...goodsInfo, quantity: quantity }); } } @@ -219,6 +227,9 @@ Page({ // 生成格式化后的规格列表(用于 picker 显示) const formattedSpecList = specList.map((item, index) => item.weightSpec || '规格' + (index + 1)); + // 获取第一个规格的件数 + const firstSpecQuantity = firstSpec ? (parseInt(firstSpec.soldQuantity) || parseInt(goodsInfo.quantity) || 1) : 1; + this.setData({ selectedGoods: goodsInfo, specList: specList, @@ -226,7 +237,7 @@ Page({ selectedSpecIndex: selectedSpecIndex, 'goodsInfo.weight': weight, 'goodsInfo.volume': volume, - 'goodsInfo.quantity': goodsInfo.quantity || 1, + 'goodsInfo.quantity': firstSpecQuantity, weight: weight, // 同步到运输参数的重量输入框 volume: volume // 同步到运输参数的体积输入框 }); @@ -274,14 +285,21 @@ Page({ // 从重量规格中提取数字 const weightMatch = firstSpec.weightSpec.match(/(\d+(?:\.\d+)?)/); if (weightMatch && weightMatch.length > 1) { - const weightPerUnit = parseFloat(weightMatch[1]); - const quantity = parseInt(firstSpec.soldQuantity || goodsData.quantity) || 1; + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (firstSpec.weightSpec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + + const quantity = parseInt(firstSpec.quantity || goodsData.quantity) || 1; weight = (weightPerUnit * quantity) / 2; // 换算为公斤 } } // 计算体积 - if (goodsData.producting && (goodsData.quantity || firstSpec.soldQuantity)) { - const quantity = parseInt(firstSpec.soldQuantity || goodsData.quantity) || 1; + if (goodsData.producting && (goodsData.quantity || firstSpec.quantity)) { + const quantity = parseInt(firstSpec.quantity || goodsData.quantity) || 1; volume = this.calculateVolumeFromPackaging({ ...goodsData, quantity: quantity }); } } @@ -304,6 +322,10 @@ Page({ // 生成格式化后的规格列表(用于 picker 显示) const formattedSpecList = specList.map((item, index) => item.weightSpec || '规格' + (index + 1)); + // 获取第一个规格的件数 + const firstSpec = specList.length > 0 ? specList[0] : null; + const firstSpecQuantity = firstSpec ? (parseInt(firstSpec.soldQuantity) || parseInt(goodsData.quantity) || 1) : (parseInt(goodsData.quantity) || 1); + this.setData({ selectedGoods: goodsData, specList: specList, @@ -311,9 +333,10 @@ Page({ selectedSpecIndex: selectedSpecIndex, 'goodsInfo.weight': weight, 'goodsInfo.volume': volume, - 'goodsInfo.quantity': goodsData.quantity || 1, + 'goodsInfo.quantity': firstSpecQuantity, weight: weight, // 同步到运输参数的重量输入框 - volume: volume // 同步到运输参数的体积输入框 + volume: volume, // 同步到运输参数的体积输入框 + quantity: firstSpecQuantity // 同步到运输参数的件数输入框 }); // 自动匹配车型和车长 @@ -417,14 +440,21 @@ Page({ // 从重量规格中提取数字 const weightMatch = firstSpec.weightSpec.match(/(\d+(?:\.\d+)?)/); if (weightMatch && weightMatch.length > 1) { - const weightPerUnit = parseFloat(weightMatch[1]); - const quantity = parseInt(firstSpec.soldQuantity || goodsItem.quantity) || 1; + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (firstSpec.weightSpec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + + const quantity = parseInt(firstSpec.quantity || goodsItem.quantity) || 1; weight = (weightPerUnit * quantity) / 2; // 换算为公斤 } } // 计算体积 - if (goodsItem.producting && (goodsItem.quantity || firstSpec.soldQuantity)) { - const quantity = parseInt(firstSpec.soldQuantity || goodsItem.quantity) || 1; + if (goodsItem.producting && (goodsItem.quantity || firstSpec.quantity)) { + const quantity = parseInt(firstSpec.quantity || goodsItem.quantity) || 1; volume = this.calculateVolumeFromPackaging({ ...goodsItem, quantity: quantity }); } } @@ -444,14 +474,20 @@ Page({ }); } + // 获取第一个规格的件数 + const firstSpec = specList.length > 0 ? specList[0] : null; + const firstSpecQuantity = firstSpec ? (parseInt(firstSpec.soldQuantity) || parseInt(goodsItem.quantity) || 1) : 1; + // 生成格式化后的规格列表(用于 picker 显示) const formattedSpecList = specList.map((item, index) => item.weightSpec || '规格' + (index + 1)); - // 设置规格列表 + // 设置规格列表和件数 this.setData({ specList: specList, formattedSpecList: formattedSpecList, - selectedSpecIndex: selectedSpecIndex + selectedSpecIndex: selectedSpecIndex, + 'goodsInfo.quantity': firstSpecQuantity, + quantity: firstSpecQuantity // 同步到运输参数的件数输入框 }); // 自动匹配车型和车长 @@ -472,7 +508,14 @@ Page({ // 从规格字符串中提取数字 const weightMatch = spec.match(/(\d+(?:\.\d+)?)/); if (weightMatch && weightMatch.length > 1) { - const weightPerUnit = parseFloat(weightMatch[1]); + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (spec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + // 计算总重量:重量(斤) * 件数 / 2(换算为公斤) const totalWeight = (weightPerUnit * quantity) / 2; console.log('计算得到的总重量:', totalWeight, '公斤'); @@ -671,24 +714,36 @@ Page({ if (selectedSpec.weightSpec) { const weightMatch = selectedSpec.weightSpec.match(/(\d+(?:\.\d+)?)/); if (weightMatch && weightMatch.length > 1) { - const weightPerUnit = parseFloat(weightMatch[1]); - const quantity = parseInt(selectedSpec.soldQuantity || this.data.goodsInfo.quantity) || 1; + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (selectedSpec.weightSpec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + + const quantity = parseInt(selectedSpec.quantity || this.data.goodsInfo.quantity) || 1; weight = (weightPerUnit * quantity) / 2; // 换算为公斤 } } // 计算体积 - if (this.data.selectedGoods.producting && (this.data.goodsInfo.quantity || selectedSpec.soldQuantity)) { - const quantity = parseInt(selectedSpec.soldQuantity || this.data.goodsInfo.quantity) || 1; + if (this.data.selectedGoods.producting && (this.data.goodsInfo.quantity || selectedSpec.quantity)) { + const quantity = parseInt(selectedSpec.quantity || this.data.goodsInfo.quantity) || 1; volume = this.calculateVolumeFromPackaging({ ...this.data.selectedGoods, quantity: quantity }); } - // 更新重量和体积 + // 获取当前规格的件数 + const specQuantity = parseInt(selectedSpec.quantity || this.data.goodsInfo.quantity) || 1; + + // 更新重量、体积和件数 this.setData({ 'goodsInfo.weight': weight, 'goodsInfo.volume': volume, + 'goodsInfo.quantity': specQuantity, weight: weight, // 同步到运输参数的重量输入框 - volume: volume // 同步到运输参数的体积输入框 + volume: volume, // 同步到运输参数的体积输入框 + quantity: specQuantity // 同步到运输参数的件数输入框 }); // 自动匹配车型和车长 @@ -1514,6 +1569,58 @@ Page({ this.autoMatchVehicle(this.data.weight, volume); }, + // 件数输入处理 + bindQuantityInput: function(e) { + const quantity = e.detail.value; + this.setData({ quantity: quantity }); + + // 如果有选中的规格,重新计算重量和体积 + if (this.data.specList.length > 0 && this.data.selectedSpecIndex >= 0) { + const selectedSpec = this.data.specList[this.data.selectedSpecIndex]; + if (selectedSpec) { + let weight = ''; + let volume = ''; + + // 从规格中提取重量 + if (selectedSpec.weightSpec) { + const weightMatch = selectedSpec.weightSpec.match(/(\d+(?:\.\d+)?)/); + if (weightMatch && weightMatch.length > 1) { + let weightPerUnit = parseFloat(weightMatch[1]); + + // 如果是净重,需要加上5斤的箱托重量 + if (selectedSpec.weightSpec.includes('净重')) { + weightPerUnit += 5; + console.log('净重加上箱托重量后:', weightPerUnit, '斤'); + } + + const qty = parseInt(quantity) || 1; + weight = (weightPerUnit * qty) / 2; // 换算为公斤 + } + } + + // 计算体积 + if (this.data.selectedGoods.producting && quantity) { + const qty = parseInt(quantity) || 1; + volume = this.calculateVolumeFromPackaging({ ...this.data.selectedGoods, quantity: qty }); + } + + // 更新重量和体积 + this.setData({ + 'goodsInfo.weight': weight, + 'goodsInfo.volume': volume, + 'goodsInfo.quantity': quantity, + weight: weight, // 同步到运输参数的重量输入框 + volume: volume // 同步到运输参数的体积输入框 + }); + + // 自动匹配车型和车长 + if (weight && volume) { + this.autoMatchVehicle(weight, volume); + } + } + } + }, + // 根据重量和体积自动匹配车型和车长 autoMatchVehicle: function(weight, volume) { const weightNum = parseFloat(weight) || 0; diff --git a/pages/freight-calculator/index.wxml b/pages/freight-calculator/index.wxml index c937291..2ed936c 100644 --- a/pages/freight-calculator/index.wxml +++ b/pages/freight-calculator/index.wxml @@ -95,6 +95,12 @@ + + + 件数 + + +