From f19223fcdaa90ec637250c4879b386e4d48c982f Mon Sep 17 00:00:00 2001 From: lzx_win <2602107437@qq.com> Date: Fri, 7 Nov 2025 15:00:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=A2=E5=8D=95=E8=AE=A1=E7=AE=97):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=A0=E7=89=A9=E8=B4=B9=E7=94=A8=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E4=B8=AD=E7=9A=84=E6=95=B0=E5=80=BC=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复宠物额外费用计算中未处理price_config为空的情况,增加大型犬费用计算 修复定制服务费用计算中的数值转换问题,增加NaN检查和错误处理 将环境变量从trial改为release --- pages/newOrder/confirmOrder.vue | 34 +++++++++++++++++++++++++++------- pages/newOrder/serviceNew2.vue | 27 ++++++++++++++++++++------- utils/getUrl.js | 2 +- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/pages/newOrder/confirmOrder.vue b/pages/newOrder/confirmOrder.vue index f987762..c779ada 100644 --- a/pages/newOrder/confirmOrder.vue +++ b/pages/newOrder/confirmOrder.vue @@ -611,10 +611,27 @@ } // 所有宠物定制服务费用 - const customServiceCost = pets.reduce((acc, pet) => acc + this.calculatePetCustomServiceCost(pet), 0) - console.log(baseServiceCost + additionalCost + multServicesTotalCost + customServiceCost); + const customServiceCost = pets.reduce((acc, pet) => Number(acc) + Number(this.calculatePetCustomServiceCost(pet)), 0) + // console.log(baseServiceCost + additionalCost + multServicesTotalCost + customServiceCost); console.log(baseServiceCost , additionalCost , multServicesTotalCost , customServiceCost); + if (isNaN(baseServiceCost)) { + console.log('baseServiceCost is not a number', baseServiceCost); + } + if (isNaN(additionalCost)) { + console.log('additionalCost is not a number', additionalCost); + } + if (isNaN(multServicesTotalCost)) { + console.log('multServicesTotalCost is not a number', multServicesTotalCost); + } + if (isNaN(customServiceCost)) { + console.log('customServiceCost is not a number', customServiceCost, pets); + uni.showToast({ + title: '定制服务费用计算错误', + icon: 'none' + }) + } + // 确保所有数值都是有效的数字,避免NaN const safeBaseServiceCost = isNaN(baseServiceCost) ? 0 : Number(baseServiceCost) const safeAdditionalCost = isNaN(additionalCost) ? 0 : Number(additionalCost) @@ -646,7 +663,6 @@ this.getShowTotalPrice() }, calculatePetCost(pet) { - // 宠物额外费用 不计算大型犬 let petExtra = this.price_config.petExtra || {} let petCost = 0; if (pet.petType === 'cat' && petExtra.cat) { @@ -665,12 +681,16 @@ console.log('pet.customServices',pet.customServices) // 确保customServices存在且为数组 if (!pet.customServices || !Array.isArray(pet.customServices)) { - return '0.00' + return 0 } const customServiceCost = pet.customServices.reduce((acc, item) => { - const price = isNaN(item.price) ? 0 : Number(item.price) - const quantity = isNaN(item.quantity) ? 0 : Number(item.quantity) - return acc + price * quantity + if (isNaN(item.price) || isNaN(item.quantity)) { + console.log('customServiceCost item price or quantity is not a number', item); + throw new Error('customServiceCost item price or quantity is not a number') + } + const price = Number(item.price) + const quantity = Number(item.quantity) + return Number(acc) + price * quantity }, 0) console.log('customServiceCost',customServiceCost) return parseFloat(customServiceCost).toFixed(2) diff --git a/pages/newOrder/serviceNew2.vue b/pages/newOrder/serviceNew2.vue index 3e62d42..852deb2 100644 --- a/pages/newOrder/serviceNew2.vue +++ b/pages/newOrder/serviceNew2.vue @@ -953,15 +953,28 @@ export default { calculatePetCost(pet) { // 宠物额外费用 不计算大型犬 - let petExtra = this.price_config.petExtra + // let petExtra = this.price_config.petExtra + // let petCost = 0; + // if (pet.petType === 'cat') { + // petCost += Number(petExtra.cat.price); // 猫额外费用 + // } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) { + // petCost += Number(petExtra.smallDog.price); // 小型犬额外费用 + // } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) { + // petCost += Number(petExtra.mediumDog.price); // 中型犬额外费用 + // } + // console.log('calculatePetCost', pet, petCost, petExtra); + let petExtra = this.price_config.petExtra || {} let petCost = 0; - if (pet.petType === 'cat') { - petCost += Number(petExtra.cat.price); // 猫额外费用 - } else if (pet.petType === 'dog' && pet.bodyType.includes('小型')) { - petCost += Number(petExtra.smallDog.price); // 小型犬额外费用 - } else if (pet.petType === 'dog' && pet.bodyType.includes('中型')) { - petCost += Number(petExtra.mediumDog.price); // 中型犬额外费用 + if (pet.petType === 'cat' && petExtra.cat) { + petCost += Number(petExtra.cat.price || 0); // 猫额外费用 + } else if (pet.petType === 'dog' && pet.bodyType.includes('小型') && petExtra.smallDog) { + petCost += Number(petExtra.smallDog.price || 0); // 小型犬额外费用 + } else if (pet.petType === 'dog' && pet.bodyType.includes('中型') && petExtra.mediumDog) { + petCost += Number(petExtra.mediumDog.price || 0); // 中型犬额外费用 + } else if (pet.petType === 'dog' && pet.bodyType.includes('大型') && petExtra.largeDog) { + petCost += Number(petExtra.largeDog.price || 0); // 大型犬额外费用 } + // console.log('calculatePetCost', pet, petCost, petExtra); return petCost; }, diff --git a/utils/getUrl.js b/utils/getUrl.js index fa9c188..7f40537 100644 --- a/utils/getUrl.js +++ b/utils/getUrl.js @@ -1,4 +1,4 @@ -let current ="trial"; +let current ="release"; const accountInfo = wx.getAccountInfoSync(); // current = accountInfo.miniProgram.envVersion;