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