From b293e112c669e6069994668e4d544415ed461893 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 May 2026 20:23:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20MALL=20=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BF=9D=E5=AD=98=E6=97=B6=20SKU=20=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E8=A2=AB=E5=8F=8D=E5=A4=8D=20*100=20=E7=9A=84=E6=BC=82?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/mall/product/spu/form/index.vue | 52 +++++++++---------- .../src/views/mall/product/spu/form/index.vue | 52 +++++++++---------- 2 files changed, 50 insertions(+), 54 deletions(-) diff --git a/apps/web-antd/src/views/mall/product/spu/form/index.vue b/apps/web-antd/src/views/mall/product/spu/form/index.vue index e8aa3ea3a..8e9e4bd52 100644 --- a/apps/web-antd/src/views/mall/product/spu/form/index.vue +++ b/apps/web-antd/src/views/mall/product/spu/form/index.vue @@ -181,31 +181,28 @@ async function handleSubmit() { .merge(descriptionFormApi) .merge(otherFormApi) .submitAllForm(true); - values.skus = formData.value.skus; // 校验商品名称不能为空(用于 SKU name) if (!values.name || values.name.trim() === '') { message.error('商品名称不能为空'); return; } - if (values.skus) { - try { - // 校验 sku - skuListRef.value.validateSku(); - } catch { - message.error('【库存价格】不完善,请填写相关信息'); - return; - } - values.skus.forEach((item) => { - // 给 sku name 赋值(使用商品名称作为 SKU 名称) - item.name = values.name; - // 金额转换:元转分 - item.price = convertToInteger(item.price); - item.marketPrice = convertToInteger(item.marketPrice); - item.costPrice = convertToInteger(item.costPrice); - item.firstBrokeragePrice = convertToInteger(item.firstBrokeragePrice); - item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice); - }); + try { + // 校验 sku + skuListRef.value.validateSku(); + } catch { + message.error('【库存价格】不完善,请填写相关信息'); + return; } + // 金额转换:元转分 + values.skus = formData.value.skus!.map((item) => ({ + ...item, + name: values.name, + price: convertToInteger(item.price), + marketPrice: convertToInteger(item.marketPrice), + costPrice: convertToInteger(item.costPrice), + firstBrokeragePrice: convertToInteger(item.firstBrokeragePrice), + secondBrokeragePrice: convertToInteger(item.secondBrokeragePrice), + })); // 处理轮播图列表:上传组件可能返回对象或字符串,统一处理成字符串数组 const newSliderPicUrls: any[] = []; values.sliderPicUrls!.forEach((item: any) => { @@ -235,14 +232,15 @@ async function getDetail() { formLoading.value = true; try { const res = await getSpu(spuId.value!); - // 金额转换:元转分 - res.skus?.forEach((item) => { - item.price = formatToFraction(item.price); - item.marketPrice = formatToFraction(item.marketPrice); - item.costPrice = formatToFraction(item.costPrice); - item.firstBrokeragePrice = formatToFraction(item.firstBrokeragePrice); - item.secondBrokeragePrice = formatToFraction(item.secondBrokeragePrice); - }); + // 金额转换:分转元 + res.skus = res.skus?.map((item) => ({ + ...item, + price: formatToFraction(item.price), + marketPrice: formatToFraction(item.marketPrice), + costPrice: formatToFraction(item.costPrice), + firstBrokeragePrice: formatToFraction(item.firstBrokeragePrice), + secondBrokeragePrice: formatToFraction(item.secondBrokeragePrice), + })); formData.value = res; // 初始化各表单值 infoFormApi.setValues(res).then(); diff --git a/apps/web-ele/src/views/mall/product/spu/form/index.vue b/apps/web-ele/src/views/mall/product/spu/form/index.vue index b2d65e30e..720a90321 100644 --- a/apps/web-ele/src/views/mall/product/spu/form/index.vue +++ b/apps/web-ele/src/views/mall/product/spu/form/index.vue @@ -181,31 +181,28 @@ async function handleSubmit() { .merge(descriptionFormApi) .merge(otherFormApi) .submitAllForm(true); - values.skus = formData.value.skus; // 校验商品名称不能为空(用于 SKU name) if (!values.name || values.name.trim() === '') { ElMessage.error('商品名称不能为空'); return; } - if (values.skus) { - try { - // 校验 sku - skuListRef.value.validateSku(); - } catch { - ElMessage.error('【库存价格】不完善,请填写相关信息'); - return; - } - values.skus.forEach((item) => { - // 给 sku name 赋值(使用商品名称作为 SKU 名称) - item.name = values.name; - // 金额转换:元转分 - item.price = convertToInteger(item.price); - item.marketPrice = convertToInteger(item.marketPrice); - item.costPrice = convertToInteger(item.costPrice); - item.firstBrokeragePrice = convertToInteger(item.firstBrokeragePrice); - item.secondBrokeragePrice = convertToInteger(item.secondBrokeragePrice); - }); + try { + // 校验 sku + skuListRef.value.validateSku(); + } catch { + ElMessage.error('【库存价格】不完善,请填写相关信息'); + return; } + // 金额转换:元转分 + values.skus = formData.value.skus!.map((item) => ({ + ...item, + name: values.name, + price: convertToInteger(item.price), + marketPrice: convertToInteger(item.marketPrice), + costPrice: convertToInteger(item.costPrice), + firstBrokeragePrice: convertToInteger(item.firstBrokeragePrice), + secondBrokeragePrice: convertToInteger(item.secondBrokeragePrice), + })); // 处理轮播图列表:上传组件可能返回对象或字符串,统一处理成字符串数组 const newSliderPicUrls: any[] = []; values.sliderPicUrls!.forEach((item: any) => { @@ -235,14 +232,15 @@ async function getDetail() { formLoading.value = true; try { const res = await getSpu(spuId.value!); - // 金额转换:元转分 - res.skus?.forEach((item) => { - item.price = formatToFraction(item.price); - item.marketPrice = formatToFraction(item.marketPrice); - item.costPrice = formatToFraction(item.costPrice); - item.firstBrokeragePrice = formatToFraction(item.firstBrokeragePrice); - item.secondBrokeragePrice = formatToFraction(item.secondBrokeragePrice); - }); + // 金额转换:分转元 + res.skus = res.skus?.map((item) => ({ + ...item, + price: formatToFraction(item.price), + marketPrice: formatToFraction(item.marketPrice), + costPrice: formatToFraction(item.costPrice), + firstBrokeragePrice: formatToFraction(item.firstBrokeragePrice), + secondBrokeragePrice: formatToFraction(item.secondBrokeragePrice), + })); formData.value = res; // 初始化各表单值 infoFormApi.setValues(res).then();