From c656f8757585e11baa44b146bb9850305115c0c1 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 28 Jan 2026 11:06:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(mall):=20=E4=BF=AE=E5=A4=8D=E5=95=86?= =?UTF-8?q?=E5=93=81=20SKU=20=E5=90=8D=E7=A7=B0=E6=A0=A1=E9=AA=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mall/product/spu/components/SkuList.vue | 3 +++ src/views/mall/product/spu/form/SkuForm.vue | 1 + src/views/mall/product/spu/form/index.vue | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/views/mall/product/spu/components/SkuList.vue b/src/views/mall/product/spu/components/SkuList.vue index c41da4b2..10d82319 100644 --- a/src/views/mall/product/spu/components/SkuList.vue +++ b/src/views/mall/product/spu/components/SkuList.vue @@ -318,6 +318,7 @@ const props = defineProps({ const formData: Ref = ref() // 表单数据 const skuList = ref([ { + name: '', // SKU 名称 price: 0, // 商品价格 marketPrice: 0, // 市场价 costPrice: 0, // 成本价 @@ -449,6 +450,7 @@ const generateTableData = (propertyList: any[]) => { } for (const item of buildSkuList) { const row = { + name: '', // SKU 名称,提交时会自动使用 SPU 名称 properties: Array.isArray(item) ? item : [item], // 如果只有一个属性的话返回的是一个 property 对象 price: 0, marketPrice: 0, @@ -525,6 +527,7 @@ watch( if (props.isBatch) { skuList.value = [ { + name: '', // SKU 名称 price: 0, marketPrice: 0, costPrice: 0, diff --git a/src/views/mall/product/spu/form/SkuForm.vue b/src/views/mall/product/spu/form/SkuForm.vue index 18cd0296..782d8ed4 100644 --- a/src/views/mall/product/spu/form/SkuForm.vue +++ b/src/views/mall/product/spu/form/SkuForm.vue @@ -173,6 +173,7 @@ const onChangeSpec = () => { // 重置sku列表 formData.skus = [ { + name: '', // SKU 名称,提交时会自动使用 SPU 名称 price: 0, marketPrice: 0, costPrice: 0, diff --git a/src/views/mall/product/spu/form/index.vue b/src/views/mall/product/spu/form/index.vue index c4e4b7b2..bf4aa934 100644 --- a/src/views/mall/product/spu/form/index.vue +++ b/src/views/mall/product/spu/form/index.vue @@ -62,6 +62,7 @@ import OtherForm from './OtherForm.vue' import SkuForm from './SkuForm.vue' import DeliveryForm from './DeliveryForm.vue' import { convertToInteger, floatToFixed2, formatToFraction } from '@/utils' +import { isEmpty } from '@/utils/is' defineOptions({ name: 'ProductSpuAdd' }) @@ -94,6 +95,7 @@ const formData = ref({ subCommissionType: false, // 分销类型 skus: [ { + name: '', // SKU 名称,提交时会自动使用 SPU 名称 price: 0, // 商品价格 marketPrice: 0, // 市场价 costPrice: 0, // 成本价 @@ -158,8 +160,13 @@ const submitForm = async () => { await unref(otherRef)?.validate() // 深拷贝一份, 这样最终 server 端不满足,不需要影响原始数据 const deepCopyFormData = cloneDeep(unref(formData.value)) as ProductSpuApi.Spu + // 校验商品名称不能为空(用于 SKU name) + if (isEmpty(deepCopyFormData.name)) { + message.error('商品名称不能为空') + return + } deepCopyFormData.skus!.forEach((item) => { - // 给sku name赋值 + // 给sku name赋值(使用商品名称作为 SKU 名称) item.name = deepCopyFormData.name // sku相关价格元转分 item.price = convertToInteger(item.price)