From c4f7aa760b07850fefa69ff8da750ed017960dcb Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 26 Aug 2024 22:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9A=E9=99=90=E6=97=B6=E6=8A=98?= =?UTF-8?q?=E6=89=A3=E6=B4=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/components/SpuAndSkuList.vue | 25 +++++---- .../discountActivity/DiscountActivityForm.vue | 53 ++++++++++++------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/views/mall/promotion/components/SpuAndSkuList.vue b/src/views/mall/promotion/components/SpuAndSkuList.vue index 3e03bb19..5a96ddc3 100644 --- a/src/views/mall/promotion/components/SpuAndSkuList.vue +++ b/src/views/mall/promotion/components/SpuAndSkuList.vue @@ -29,15 +29,14 @@ - + @@ -57,7 +56,7 @@ const props = defineProps<{ spuList: T[] ruleConfig: RuleConfig[] spuPropertyListP: SpuProperty[] - isDelete?: boolean //spu是否可以多选 + isDelete?: boolean // SPU 是否可删除;TODO deletable 换成这个名字好点。 }>() const spuData = ref([]) // spu 详情数据列表 @@ -96,12 +95,12 @@ const emits = defineEmits<{ (e: 'delete', spuId: number): void }>() -/** 多选时可以删除spu **/ +/** 多选时可以删除 SPU **/ const deleteSpu = async (spuId: number) => { await message.confirm('是否删除商品编号为' + spuId + '的数据?') - let index = spuData.value.findIndex((item) => item.id == spuId) - spuData.value.splice(index,1); - emits('delete',spuId) + const index = spuData.value.findIndex((item) => item.id == spuId) + spuData.value.splice(index, 1) + emits('delete', spuId) } /** diff --git a/src/views/mall/promotion/discountActivity/DiscountActivityForm.vue b/src/views/mall/promotion/discountActivity/DiscountActivityForm.vue index a90771cc..915af43c 100644 --- a/src/views/mall/promotion/discountActivity/DiscountActivityForm.vue +++ b/src/views/mall/promotion/discountActivity/DiscountActivityForm.vue @@ -49,7 +49,7 @@ import { cloneDeep } from 'lodash-es' import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity' import * as ProductSpuApi from '@/api/mall/product/spu' import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components' -import {formatToFraction} from "@/utils"; +import { formatToFraction } from '@/utils' defineOptions({ name: 'PromotionDiscountActivityForm' }) @@ -68,7 +68,7 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref const ruleConfig: RuleConfig[] = [] const spuList = ref([]) // 选择的 spu const spuPropertyList = ref[]>([]) -const spuIds = ref([]); +const spuIds = ref([]) const selectSpu = (spuId: number, skuIds: number[]) => { getSpuDetails(spuId, skuIds) } @@ -81,12 +81,12 @@ const getSpuDetails = async ( products?: DiscountActivityApi.DiscountProductVO[], type?: string ) => { - //如果已经包含spu则跳过 - if(spuIds.value.includes(spuId)){ - if(type !== "load"){ - message.error("数据重复选择!") + // 如果已经包含 SPU 则跳过 + if (spuIds.value.includes(spuId)) { + if (type !== 'load') { + message.error('数据重复选择!') } - return; + return } spuIds.value.push(spuId) const res = (await ProductSpuApi.getSpuDetailList([spuId])) as DiscountActivityApi.SpuExtension[] @@ -143,7 +143,12 @@ const open = async (type: string, id?: number) => { )) as DiscountActivityApi.DiscountActivityVO for (let productsKey in data.products) { const supId = data.products[productsKey].spuId - await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products,"load") + await getSpuDetails( + supId!, + data.products?.map((sku) => sku.skuId), + data.products, + 'load' + ) } formRef.value.setValues(data) } finally { @@ -164,21 +169,23 @@ const submitForm = async () => { formLoading.value = true try { const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO - // 获取 折扣商品配置 + // 获取折扣商品配置 const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig')) - let timp = false; + // 校验优惠金额、折扣百分比,是否正确 + // TODO @puhui999:这个交互,可以参考下 youzan 的 + let discountInvalid = false products.forEach((item: DiscountActivityApi.DiscountProductVO) => { - if(item.discountPrice != null && item.discountPrice > 0){ + if (item.discountPrice != null && item.discountPrice > 0) { item.discountType = 1 - }else if(item.discountPercent != null && item.discountPercent > 0){ + } else if (item.discountPercent != null && item.discountPercent > 0) { item.discountType = 2 - }else{ - timp = true + } else { + discountInvalid = true } }) - if(timp){ - message.error("优惠金额和折扣百分比需要填写一个"); - return; + if (discountInvalid) { + message.error('优惠金额和折扣百分比需要填写一个') + return } data.products = products // 真正提交 @@ -207,10 +214,16 @@ const resetForm = async () => { } /** - * 删除spu + * 删除 SPU */ const deleteSpu = (spuId: number) => { - spuIds.value.splice(spuIds.value.findIndex((item) => item == spuId), 1) - spuPropertyList.value.splice(spuPropertyList.value.findIndex((item) => item.spuId == spuId), 1) + spuIds.value.splice( + spuIds.value.findIndex((item) => item == spuId), + 1 + ) + spuPropertyList.value.splice( + spuPropertyList.value.findIndex((item) => item.spuId == spuId), + 1 + ) }