From 53326f3a48a54c91f7cc60ded05a68d336d2e153 Mon Sep 17 00:00:00 2001 From: Agent Date: Sat, 28 Mar 2026 02:44:31 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=89=8D=E7=AB=AF=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E4=B8=8D=E8=83=BD=E4=B8=BA=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/order/create.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pages/order/create.vue b/src/pages/order/create.vue index e928280..76f0471 100644 --- a/src/pages/order/create.vue +++ b/src/pages/order/create.vue @@ -278,8 +278,12 @@ export default { return sum + (item.price * item.quantity) }, 0) - // 2. 优惠金额直接使用用户输入的值 - this.discountAmount = parseFloat(this.discountMoney) || 0 + // 2. 优惠金额直接使用用户输入的值,不能为负 + let discountVal = parseFloat(this.discountMoney) + if (isNaN(discountVal) || discountVal < 0) { + discountVal = 0 + } + this.discountAmount = discountVal // 3. 计算实付金额 = 原价 - 优惠金额 this.actualAmount = this.totalAmount - this.discountAmount @@ -302,6 +306,13 @@ export default { return } + // 校验:优惠金额不能为负 + const discountVal = parseFloat(this.discountMoney) || 0 + if (discountVal < 0) { + uni.showToast({ title: '优惠金额不能为负', icon: 'none' }) + return + } + const data = { customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null, items: this.orderItems.map(item => ({