From 139b7e003e53e485acdf17174f2749d536288acf Mon Sep 17 00:00:00 2001 From: WUSIJIAN <13825895+wsj0228@user.noreply.gitee.com> Date: Wed, 14 Jan 2026 17:36:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98=E7=94=9F?= =?UTF-8?q?=E6=88=90=E8=A1=A8=E5=8D=95=E7=9A=84=E6=95=B0=E5=AD=97=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=A4=84=E7=90=86=E5=92=8C=E9=AA=8C=E8=AF=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/asset/component/skuDialog.vue | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/views/assets/asset/component/skuDialog.vue b/src/views/assets/asset/component/skuDialog.vue index 964744a..394c28a 100644 --- a/src/views/assets/asset/component/skuDialog.vue +++ b/src/views/assets/asset/component/skuDialog.vue @@ -178,6 +178,7 @@ v-model="stockForm[field.name]" :min="field.min" :max="field.max" + :controls="!field.maxLength" controls-position="right" style="width: 200px" /> @@ -558,10 +559,15 @@ const onGenerateStock = async (row: any) => { const res = await getStockFormFields(row.id); stockFormFields.value = res.data.fields || []; - // 设置默认值 + // 设置默认值,根据字段类型转换 stockFormFields.value.forEach((field) => { if (field.default !== undefined) { - stockForm[field.name] = field.default; + // 如果是数字类型,确保默认值也是数字 + if (field.type === 'number') { + stockForm[field.name] = Number(field.default); + } else { + stockForm[field.name] = field.default; + } } else if (field.type === 'number') { stockForm[field.name] = field.min || 0; } else { @@ -586,10 +592,20 @@ const onSubmitStock = async () => { if (valid) { stockSubmitLoading.value = true; try { - await stockOperation({ + // 根据字段类型转换数据 + const submitData: Record = { assetSkuId: currentSkuId.value, - ...stockForm, + }; + stockFormFields.value.forEach((field) => { + const value = stockForm[field.name]; + if (field.type === 'number' && value !== undefined && value !== '') { + submitData[field.name] = Number(value); + } else if (value !== undefined && value !== '') { + submitData[field.name] = value; + } }); + + await stockOperation(submitData as any); ElMessage.success('库存生成成功'); stockFormVisible.value = false; getSkuList(); @@ -610,10 +626,34 @@ const getStockFormRules = () => { if (field.required) { fieldRules.push({ required: true, message: `${field.label}不能为空`, trigger: 'blur' }); } - if (field.type === 'number' && field.min !== undefined) { - fieldRules.push({ type: 'number', min: field.min, message: `${field.label}最小值为${field.min}`, trigger: 'blur' }); - } - if (field.maxLength) { + if (field.type === 'number') { + // 数字类型的最小值和最大值验证 + if (field.min !== undefined) { + fieldRules.push({ type: 'number', min: field.min, message: `${field.label}最小值为${field.min}`, trigger: 'blur' }); + } + if (field.max !== undefined) { + fieldRules.push({ type: 'number', max: field.max, message: `${field.label}最大值为${field.max}`, trigger: 'blur' }); + } + // 数字位数验证 + if (field.maxLength) { + fieldRules.push({ + validator: (_rule: any, value: any, callback: any) => { + if (value !== undefined && value !== null && value !== '') { + const strValue = String(value); + if (strValue.length > field.maxLength!) { + callback(new Error(`${field.label}不能超过${field.maxLength}位`)); + } else { + callback(); + } + } else { + callback(); + } + }, + trigger: 'blur', + }); + } + } else if (field.maxLength) { + // 字符串类型的最大长度验证 fieldRules.push({ max: field.maxLength, message: `${field.label}最大长度为${field.maxLength}`, trigger: 'blur' }); } if (fieldRules.length > 0) {