From 44be35b5ce3159b525d17ab7abbd931c114867e8 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 17 Aug 2023 10:52:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E7=A0=8D=E4=BB=B7?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E7=AE=A1=E7=90=86=E5=AF=B9=E9=BD=90=E5=90=8E?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/promotion/bargain/bargainActivity.ts | 10 +++--- .../mall/product/spu/components/SkuList.vue | 9 ++--- .../bargain/activity/BargainActivityForm.vue | 27 +++++++++++---- .../promotion/combination/record/index.vue | 5 +++ .../mall/promotion/components/SpuSelect.vue | 33 +++++++++++++++---- 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/api/mall/promotion/bargain/bargainActivity.ts b/src/api/mall/promotion/bargain/bargainActivity.ts index a23477d9..9e2dfba5 100644 --- a/src/api/mall/promotion/bargain/bargainActivity.ts +++ b/src/api/mall/promotion/bargain/bargainActivity.ts @@ -7,18 +7,20 @@ export interface BargainActivityVO { startTime?: Date endTime?: Date status?: number - spuId?: number userSize?: number // 达到该人数,才能砍到低价 bargainCount?: number // 最大帮砍次数 totalLimitCount?: number // 最大购买次数 - stock?: number // 活动总库存 + spuId: number + skuId: number + bargainFirstPrice: number // 砍价起始价格,单位分 + bargainPrice: number // 砍价底价 + stock: number // 活动库存 randomMinPrice?: number // 用户每次砍价的最小金额,单位:分 randomMaxPrice?: number // 用户每次砍价的最大金额,单位:分 successCount?: number // 砍价成功数量 - products?: BargainProductVO[] } -// 砍价活动所需属性 +// 砍价活动所需属性。 选择的商品和属性的时候使用方便使用活动的通用封装 export interface BargainProductVO { spuId: number skuId: number diff --git a/src/views/mall/product/spu/components/SkuList.vue b/src/views/mall/product/spu/components/SkuList.vue index 7fbb9011..1cc70298 100644 --- a/src/views/mall/product/spu/components/SkuList.vue +++ b/src/views/mall/product/spu/components/SkuList.vue @@ -334,7 +334,7 @@ const validateSku = () => { for (const sku of formData.value!.skus!) { // 作为活动组件的校验 if (props.isActivityComponent) { - for (const rule of props.ruleConfig) { + for (const rule of props?.ruleConfig) { const arg = getValue(sku, rule.name) if (!rule.rule(arg)) { validate = false // 只要有一个不通过则直接不通过 @@ -534,9 +534,10 @@ watch( } ) const activitySkuListRef = ref>() -const clearSelection = () => { - activitySkuListRef.value.clearSelection() + +const getSkuTableRef = () => { + return activitySkuListRef.value } // 暴露出生成 sku 方法,给添加属性成功时调用 -defineExpose({ generateTableData, validateSku, clearSelection }) +defineExpose({ generateTableData, validateSku, getSkuTableRef }) diff --git a/src/views/mall/promotion/bargain/activity/BargainActivityForm.vue b/src/views/mall/promotion/bargain/activity/BargainActivityForm.vue index 5384d6a1..3bef4956 100644 --- a/src/views/mall/promotion/bargain/activity/BargainActivityForm.vue +++ b/src/views/mall/promotion/bargain/activity/BargainActivityForm.vue @@ -51,7 +51,7 @@ 取 消 - + diff --git a/src/views/mall/promotion/components/SpuSelect.vue b/src/views/mall/promotion/components/SpuSelect.vue index c62e419c..166cf5ff 100644 --- a/src/views/mall/promotion/components/SpuSelect.vue +++ b/src/views/mall/promotion/components/SpuSelect.vue @@ -127,7 +127,8 @@ defineOptions({ name: 'PromotionSpuSelect' }) const props = defineProps({ // 默认不需要(不需要的情况下只返回 spu,需要的情况下返回 选中的 spu 和 sku 列表) // 其它活动需要选择商品和商品属性导入此组件即可,需添加组件属性 :isSelectSku='true' - isSelectSku: propTypes.bool.def(false) // 是否需要选择 sku 属性 + isSelectSku: propTypes.bool.def(false), // 是否需要选择 sku 属性 + radio: propTypes.bool.def(false) // 是否单选 sku }) const message = useMessage() // 消息弹窗 @@ -146,7 +147,7 @@ const queryParams = ref({ }) // 查询参数 const propertyList = ref([]) // 商品属性列表 const spuListRef = ref>() -const skuListRef = ref() // 商品属性选择 Ref +const skuListRef = ref>() // 商品属性选择 Ref const spuData = ref() // 商品详情 const isExpand = ref(false) // 控制 SKU 列表显示 const expandRowKeys = ref() // 控制展开行需要设置 row-key 属性才能使用,该属性为展开行的 keys 数组。 @@ -155,12 +156,30 @@ const expandRowKeys = ref() // 控制展开行需要设置 row-key 属 const selectedSpuId = ref(0) // 选中的商品 spuId const selectedSkuIds = ref([]) // 选中的商品 skuIds const selectSku = (val: ProductSpuApi.Sku[]) => { + const skuTable = skuListRef.value?.getSkuTableRef() if (selectedSpuId.value === 0) { message.warning('请先选择商品再选择相应的规格!!!') - skuListRef.value.clearSelection() + skuTable?.clearSelection() return } - selectedSkuIds.value = val.map((sku) => sku.id!) + if (val.length === 0) { + selectedSkuIds.value = [] + return + } + if (props.radio) { + // 只选择一个 + selectedSkuIds.value = [val.map((sku) => sku.id!)[0]] + // 如果大于1个 + if (val.length > 1) { + // 清空选择 + skuTable?.clearSelection() + // 变更为最后一次选择的 + skuTable?.toggleRowSelection(val.pop(), true) + return + } + } else { + selectedSkuIds.value = val.map((sku) => sku.id!) + } } const selectSpu = (val: ProductSpuApi.Spu[]) => { if (val.length === 0) { @@ -176,9 +195,9 @@ const selectSpu = (val: ProductSpuApi.Spu[]) => { // 如果大于1个 if (val.length > 1) { // 清空选择 - spuListRef.value.clearSelection() + spuListRef.value?.clearSelection() // 变更为最后一次选择的 - spuListRef.value.toggleRowSelection(val.pop(), true) + spuListRef.value?.toggleRowSelection(val.pop(), true) return } expandChange(val[0], val) @@ -194,7 +213,7 @@ const expandChange = async (row: ProductSpuApi.Spu, expandedRows?: ProductSpuApi expandRowKeys.value = [selectedSpuId.value] return } - // 如果以展开 skuList 则选择此对应的 spu 不需要重新获取渲染 skuList + // 如果已展开 skuList 则选择此对应的 spu 不需要重新获取渲染 skuList if (isExpand.value && spuData.value?.id === row.id) { return }