| | |
| | | const temFutureTickets = ref(0); |
| | | const originalTicketsNum = ref(0); // 保存原始来票数 |
| | | |
| | | // 表单校验规则 |
| | | // 表单校验规则 - 使用简单的 required 规则 |
| | | const rules = { |
| | | ticketsNum: [{ required: true, message: "请输入来票数", trigger: "blur" }], |
| | | ticketsAmount: [ |
| | |
| | | |
| | | // 表单提交 |
| | | const onSubmit = async () => { |
| | | if (!formRef.value) { |
| | | console.log("表单引用不存在"); |
| | | // 在验证前,确保必填字段有值 |
| | | if (!form.value.ticketsNum || form.value.ticketsNum === "" || form.value.ticketsNum === null || form.value.ticketsNum === undefined) { |
| | | uni.showToast({ |
| | | title: "请输入来票数", |
| | | icon: "none", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 先调用 validate 方法 |
| | | const validateResult = formRef.value.validate(); |
| | | |
| | | // 如果 validate 返回 undefined 或 null,直接提交 |
| | | if (validateResult === undefined || validateResult === null) { |
| | | submitForm(); |
| | | return; |
| | | } |
| | | |
| | | // 如果返回 Promise,使用 await 和 catch |
| | | if (validateResult && typeof validateResult.then === 'function') { |
| | | const valid = await validateResult.catch(() => false); |
| | | if (valid) { |
| | | // 表单验证通过,提交表单 |
| | | submitForm(); |
| | | } else { |
| | | // 表单验证失败 |
| | | console.log("表单验证失败"); |
| | | } |
| | | } else { |
| | | // 如果返回布尔值,直接判断 |
| | | if (validateResult) { |
| | | submitForm(); |
| | | } else { |
| | | console.log("表单验证失败"); |
| | | } |
| | | } |
| | | } catch (error) { |
| | | // 如果 validate 方法不存在或抛出错误,直接提交 |
| | | console.log("表单验证失败", error); |
| | | submitForm(); |
| | | if (!form.value.ticketsAmount || form.value.ticketsAmount === "" || form.value.ticketsAmount === null || form.value.ticketsAmount === undefined) { |
| | | uni.showToast({ |
| | | title: "请输入本次来票金额", |
| | | icon: "none", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 确保字段是数字类型,并转换为字符串(因为表单可能需要字符串类型) |
| | | const ticketsNum = Number(form.value.ticketsNum); |
| | | const ticketsAmount = Number(form.value.ticketsAmount); |
| | | |
| | | // 如果来票数为0或来票金额为0,提示用户 |
| | | if (isNaN(ticketsNum) || ticketsNum <= 0) { |
| | | uni.showToast({ |
| | | title: "来票数必须大于0", |
| | | icon: "none", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | if (isNaN(ticketsAmount) || ticketsAmount <= 0) { |
| | | uni.showToast({ |
| | | title: "本次来票金额必须大于0", |
| | | icon: "none", |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 更新表单值,确保是有效的数字字符串 |
| | | form.value.ticketsNum = ticketsNum.toString(); |
| | | form.value.ticketsAmount = ticketsAmount.toString(); |
| | | |
| | | // 手动验证通过后,直接提交,跳过表单验证(避免真机上的验证问题) |
| | | submitForm(); |
| | | }; |
| | | const purchaseLedgerId = ref(""); |
| | | const productModelId = ref({}); |