fix: 前端优惠金额不能为负数

This commit is contained in:
Agent
2026-03-28 02:44:31 +00:00
parent 031b8ccc25
commit 53326f3a48

View File

@@ -278,8 +278,12 @@ export default {
return sum + (item.price * item.quantity) return sum + (item.price * item.quantity)
}, 0) }, 0)
// 2. 优惠金额直接使用用户输入的值 // 2. 优惠金额直接使用用户输入的值,不能为负
this.discountAmount = parseFloat(this.discountMoney) || 0 let discountVal = parseFloat(this.discountMoney)
if (isNaN(discountVal) || discountVal < 0) {
discountVal = 0
}
this.discountAmount = discountVal
// 3. 计算实付金额 = 原价 - 优惠金额 // 3. 计算实付金额 = 原价 - 优惠金额
this.actualAmount = this.totalAmount - this.discountAmount this.actualAmount = this.totalAmount - this.discountAmount
@@ -302,6 +306,13 @@ export default {
return return
} }
// 校验:优惠金额不能为负
const discountVal = parseFloat(this.discountMoney) || 0
if (discountVal < 0) {
uni.showToast({ title: '优惠金额不能为负', icon: 'none' })
return
}
const data = { const data = {
customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null, customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null,
items: this.orderItems.map(item => ({ items: this.orderItems.map(item => ({