diff --git a/src/views/mall/product/spu/components/SkuList.vue b/src/views/mall/product/spu/components/SkuList.vue index c41da4b2c..10d82319f 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 18cd0296f..782d8ed48 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 c4e4b7b2d..bf4aa9341 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)