Browse Source

fix(订单计算): 修复宠物费用计算中的数值处理问题

修复宠物额外费用计算中未处理price_config为空的情况,增加大型犬费用计算
修复定制服务费用计算中的数值转换问题,增加NaN检查和错误处理
将环境变量从trial改为release
master
主管理员 1 day ago
parent
commit
f19223fcda
3 changed files with 48 additions and 15 deletions
  1. +27
    -7
      pages/newOrder/confirmOrder.vue
  2. +20
    -7
      pages/newOrder/serviceNew2.vue
  3. +1
    -1
      utils/getUrl.js

+ 27
- 7
pages/newOrder/confirmOrder.vue View File

@ -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)


+ 20
- 7
pages/newOrder/serviceNew2.vue View File

@ -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;
},


+ 1
- 1
utils/getUrl.js View File

@ -1,4 +1,4 @@
let current ="trial";
let current ="release";
const accountInfo = wx.getAccountInfoSync();
// current = accountInfo.miniProgram.envVersion;


Loading…
Cancel
Save