Commit 99701907 by cen

feat(CreateOrder): 添加必填校验和价格计算优化

- 在 CreateOrder 组件中添加必填项校验,确保用户输入完整信息
- 优化价格计算逻辑,确保在计算总价时正确处理商品数量和价格
- 统一处理商品和套餐商品的价格计算,提升代码可读性和维护性
1 parent 5e422139
...@@ -906,6 +906,11 @@ export default { ...@@ -906,6 +906,11 @@ export default {
// 提交 // 提交
async submit() { async submit() {
// 必填校验
if (!this.checkRequired()) {
return
}
// VIN车架号-动态校验 // VIN车架号-动态校验
const carVin = this.orderObj.standNo const carVin = this.orderObj.standNo
console.log('validateState', this.validateState) console.log('validateState', this.validateState)
...@@ -1064,32 +1069,37 @@ export default { ...@@ -1064,32 +1069,37 @@ export default {
if (Array.isArray(productList) && productList.length > 0) { if (Array.isArray(productList) && productList.length > 0) {
// 计算每个产品的价格 * 数量,并累加到总价 // 计算每个产品的价格 * 数量,并累加到总价
productList.forEach(item => { productList.forEach(item => {
if (item.goods && item.goods.sellPrice && item.goods.number) { if (item.goods && item.goods.sellPrice) {
if (useFinalPrice && item.goods.finalPrice !== undefined) { const number = parseInt(item.goods.number || 1)
if (useFinalPrice && item.goods.finalPrice !== undefined && item.goods.finalPrice !== null) {
// 使用优惠后的价格(已经是总价:单价优惠后 × 数量) // 使用优惠后的价格(已经是总价:单价优惠后 × 数量)
total += parseFloat(item.goods.finalPrice || 0) total += parseFloat(item.goods.finalPrice || 0)
} else { } else {
// 使用原始价格 // 使用原始价格
total += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number) total += parseFloat(item.goods.sellPrice) * number
} }
} else if (item.packageGoods && item.packageGoods.upgradePrice && item.packageGoods.number) { } else if (item.packageGoods && item.packageGoods.goodsList && item.packageGoods.goodsList.length > 0) {
const packageNumber = parseInt(item.packageGoods.number || 1)
item.packageGoods.goodsList.forEach(i => { item.packageGoods.goodsList.forEach(i => {
if (useFinalPrice && i.finalPrice !== undefined) { if (i.sellPrice) {
// 使用优惠后的价格 if (useFinalPrice && i.finalPrice !== undefined && i.finalPrice !== null) {
total += parseFloat(i.finalPrice || 0) // 使用优惠后的价格
} else { total += parseFloat(i.finalPrice || 0)
// 使用原始价格 } else {
total += parseFloat(i.sellPrice) * parseInt(item.packageGoods.number) // 使用原始价格
total += parseFloat(i.sellPrice) * packageNumber
}
} }
}) })
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice) { } else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice) {
const goods = item.multipleSpecificationsGoods.goods const goods = item.multipleSpecificationsGoods.goods
if (useFinalPrice && goods.finalPrice !== undefined) { const number = parseInt(item.multipleSpecificationsGoods.number || 1)
if (useFinalPrice && goods.finalPrice !== undefined && goods.finalPrice !== null) {
// 使用优惠后的价格 // 使用优惠后的价格
total += parseFloat(goods.finalPrice || 0) total += parseFloat(goods.finalPrice || 0)
} else { } else {
// 使用原始价格 // 使用原始价格
total += parseFloat(goods.sellPrice) * parseInt(item.multipleSpecificationsGoods.number || 1) total += parseFloat(goods.sellPrice) * number
} }
} }
}) })
......
...@@ -1096,28 +1096,31 @@ export default { ...@@ -1096,28 +1096,31 @@ export default {
// 计算每个产品的价格 * 数量,并累加到总价 // 计算每个产品的价格 * 数量,并累加到总价
productList.forEach(item => { productList.forEach(item => {
// 单个商品(goodsFlag == 1) // 单个商品(goodsFlag == 1)
if (item.goods && item.goods.sellPrice && item.goods.number) { if (item.goods && item.goods.sellPrice) {
const goods = item.goods const goods = item.goods
const number = parseInt(goods.number || 1)
console.log(goods, '---单商品') console.log(goods, '---单商品')
if (useFinalPrice && goods.finalPrice !== undefined && goods.finalPrice !== null) { if (useFinalPrice && goods.finalPrice !== undefined && goods.finalPrice !== null) {
// 使用优惠后的总价(单位:元) // 使用优惠后的总价(单位:元)
total = NP.plus(total, parseFloat(goods.finalPrice || 0)) total = NP.plus(total, parseFloat(goods.finalPrice || 0))
} else { } else {
// 使用原始价格(单价 * 数量,单位:元) // 使用原始价格(单价 * 数量,单位:元)
total = NP.plus(total, NP.times(goods.sellPrice, goods.number)) total = NP.plus(total, NP.times(goods.sellPrice, number))
} }
} }
// 奷餐商品(goodsFlag == 3) // 套餐商品(goodsFlag == 3)
else if (item.packageGoods && item.packageGoods.goodsList) { else if (item.packageGoods && item.packageGoods.goodsList && item.packageGoods.goodsList.length > 0) {
console.log(item.packageGoods, '套餐') console.log(item.packageGoods, '套餐')
const packageNumber = parseInt(item.packageGoods.number || 1) const packageNumber = parseInt(item.packageGoods.number || 1)
item.packageGoods.goodsList.forEach(goods => { item.packageGoods.goodsList.forEach(goods => {
if (useFinalPrice && goods.finalPrice !== undefined && goods.finalPrice !== null) { if (goods.sellPrice) {
// 使用优惠后的总价(finalPrice 已经是按数量计算后的总价,单位:元) if (useFinalPrice && goods.finalPrice !== undefined && goods.finalPrice !== null) {
total = NP.plus(total, parseFloat(goods.finalPrice || 0)) // 使用优惠后的总价(finalPrice 已经是按数量计算后的总价,单位:元)
} else { total = NP.plus(total, parseFloat(goods.finalPrice || 0))
// 使用原始价格(单价 * 套餐数量) } else {
total = NP.plus(total, NP.times(goods.sellPrice, packageNumber)) // 使用原始价格(单价 * 套餐数量)
total = NP.plus(total, NP.times(goods.sellPrice, packageNumber))
}
} }
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!