diff --git a/src/views/supermarket/mallProduct/form.vue b/src/views/supermarket/mallProduct/form.vue index 6c0ec6b..d92eae7 100644 --- a/src/views/supermarket/mallProduct/form.vue +++ b/src/views/supermarket/mallProduct/form.vue @@ -43,15 +43,6 @@ - - - - 多SKU模式 - 单价SPU模式 - - - - @@ -61,29 +52,6 @@ - - - @@ -117,13 +85,13 @@ - +
添加SKU - 多SKU模式:支持不同规格的商品(如不同颜色、尺寸、配置等) + 单个商品添加一条SKU,多规格商品添加多条SKU(如不同颜色、尺寸等)
@@ -283,11 +251,7 @@ const form = reactive({ title: "", coverImage: "", carouselImages: "", - priceType: 1, // 默认多SKU模式 - spuPrice: 0, - originalPrice: 0, - totalStock: 0, // SPU模式库存 - productNature: "", + productNature: "", status: "0", // 默认上架 saleStartTime: "", saleEndTime: "", @@ -309,19 +273,6 @@ const dataRules = ref({ categoryId: [{ required: true, message: "商品分类不能为空", trigger: "change" }], title: [{ required: true, message: "商品标题不能为空", trigger: "blur" }], coverImage: [{ required: true, message: "主图不能为空", trigger: "blur" }], - priceType: [{ required: true, message: "定价方式不能为空", trigger: "change" }], - spuPrice: [ - { - validator: (rule: any, value: any, callback: any) => { - if (form.priceType === 2 && (!value || value <= 0)) { - callback(new Error("单价SPU模式下,SPU售价不能为空且必须大于0")) - } else { - callback() - } - }, - trigger: "blur", - }, - ], status: [{ required: true, message: "状态不能为空", trigger: "change" }], }) @@ -358,19 +309,6 @@ const removeSku = (index: number) => { } } -// 定价方式改变 -const onPriceTypeChange = (value: number) => { - if (value === 1) { - // 多SKU模式:确保至少有一个SKU - if (form.skuList.length === 0) { - addSku() - } - } else { - // 单价SPU模式:清空SKU列表 - form.skuList = [] - } -} - // SKU字段验证 const validateSkuField = (index: number, field: string) => { const sku = form.skuList[index] @@ -399,11 +337,7 @@ const openDialog = (id: string) => { title: "", coverImage: "", carouselImages: "", - priceType: 1, - spuPrice: 0, - originalPrice: 0, - totalStock: 0, - unit: "", + productNature: "", status: "0", saleStartTime: "", saleEndTime: "", @@ -427,23 +361,21 @@ const onSubmit = async () => { const valid = await dataFormRef.value.validate().catch(() => {}) if (!valid) return false - // 多SKU模式下的额外验证 - if (form.priceType === 1) { - if (!form.skuList || form.skuList.length === 0) { - useMessage().error("多SKU模式下至少需要添加一个SKU") + // SKU验证 + if (!form.skuList || form.skuList.length === 0) { + useMessage().error("至少需要添加一个SKU") + activeTab.value = "sku" + return false + } + + // 验证SKU数据 + for (let i = 0; i < form.skuList.length; i++) { + const sku = form.skuList[i] + if (!sku.skuCode || !sku.skuName || !sku.price || sku.stock === undefined) { + useMessage().error(`第${i + 1}个SKU信息不完整,请检查必填项`) activeTab.value = "sku" return false } - - // 验证SKU数据 - for (let i = 0; i < form.skuList.length; i++) { - const sku = form.skuList[i] - if (!sku.skuCode || !sku.skuName || !sku.price || sku.stock === undefined) { - useMessage().error(`第${i + 1}个SKU信息不完整,请检查必填项`) - activeTab.value = "sku" - return false - } - } } try { @@ -467,18 +399,7 @@ const onSubmit = async () => { submitData.saleEndTime = date.toISOString().slice(0, 19).replace("T", " ") } - // 如果是单价SPU模式,清空SKU列表 - if (form.priceType === 2) { - submitData.skuList = [] - } - // 价格转换:元转分 - if (submitData.spuPrice) { - submitData.spuPrice = Math.round(submitData.spuPrice * 100) - } - if (submitData.originalPrice) { - submitData.originalPrice = Math.round(submitData.originalPrice * 100) - } if (submitData.skuList && submitData.skuList.length > 0) { submitData.skuList = submitData.skuList.map((sku: any) => ({ ...sku, @@ -511,12 +432,6 @@ const getmallProductData = async (id: string) => { } // 价格转换:分转元 - if (form.spuPrice) { - form.spuPrice = form.spuPrice / 100 - } - if (form.originalPrice) { - form.originalPrice = form.originalPrice / 100 - } if (form.skuList && form.skuList.length > 0) { form.skuList = form.skuList.map((sku: any) => ({ ...sku, @@ -529,11 +444,9 @@ const getmallProductData = async (id: string) => { form.categoryId = findCategoryPath(categoryOptions.value, res.data.categoryId) as any } - // 如果没有SKU数据,根据定价方式初始化 + // 如果没有SKU数据,默认添加一个 if (!form.skuList || form.skuList.length === 0) { - if (form.priceType === 1) { - addSku() - } + addSku() } } finally { loading.value = false diff --git a/src/views/supermarket/mallProduct/index.vue b/src/views/supermarket/mallProduct/index.vue index 6c74632..9929398 100644 --- a/src/views/supermarket/mallProduct/index.vue +++ b/src/views/supermarket/mallProduct/index.vue @@ -72,47 +72,28 @@ - - - - @@ -137,7 +118,7 @@