瀏覽代碼

fix(ticketManagement): 更新优惠券表单验证逻辑

- 修改有效期标签为"有效期(天)"
- 添加最低消费金额前导零检查
- 注释掉最低消费金额监听逻辑
- 优化表单验证规则
congxuesong 3 周之前
父節點
當前提交
bd7c193d00
共有 1 個文件被更改,包括 19 次插入13 次删除
  1. 19 13
      src/views/ticketManagement/newCoupon.vue

+ 19 - 13
src/views/ticketManagement/newCoupon.vue

@@ -38,7 +38,7 @@
             />
           </el-form-item>
           <!-- 有效期 -->
-          <el-form-item label="有效期" prop="specifiedDay">
+          <el-form-item label="有效期(天)" prop="specifiedDay">
             <el-input v-model="couponModel.specifiedDay" maxlength="15" placeholder="请输入" clearable />
           </el-form-item>
           <!-- 库存 -->
@@ -180,6 +180,12 @@ const rules = reactive({
             callback(new Error("请输入最低消费金额"));
             return;
           }
+          const strValue = value.toString().trim();
+          // 检查是否有前导零(除了单独的"0"或"0."开头的小数)
+          if (strValue.length > 1 && strValue.startsWith("0") && strValue !== "0" && !strValue.startsWith("0.")) {
+            callback(new Error("最低消费金额必须为正数"));
+            return;
+          }
           validatePositiveNumber("最低消费金额必须为正数")(rule, value, callback);
         } else {
           callback();
@@ -288,18 +294,18 @@ watch(
  * 监听最低消费金额变化
  * 当最低消费金额大于0时,自动设置为"是",否则设置为"否"
  */
-watch(
-  () => couponModel.value.minimumSpendingAmount,
-  newVal => {
-    if (isInitializing.value) return;
-    const amount = Number(newVal);
-    if (!isNaN(amount) && amount > 0) {
-      couponModel.value.hasMinimumSpend = 1;
-    } else {
-      couponModel.value.hasMinimumSpend = 0;
-    }
-  }
-);
+// watch(
+//   () => couponModel.value.minimumSpendingAmount,
+//   newVal => {
+//     if (isInitializing.value) return;
+//     const amount = Number(newVal);
+//     if (!isNaN(amount) && amount > 0) {
+//       couponModel.value.hasMinimumSpend = 1;
+//     } else {
+//       couponModel.value.hasMinimumSpend = 0;
+//     }
+//   }
+// );
 
 // ==================== 事件处理函数 ====================
 /**