Skip to content

Commit b98149f

Browse files
author
puhui999
committed
fix: mall SeckillActivity
1 parent a533095 commit b98149f

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/api/mall/product/spu.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export const getSpu = (id: number) => {
8686
return request.get({ url: `/product/spu/get-detail?id=${id}` })
8787
}
8888

89+
// 获得商品 Spu 详情列表
90+
export const getSpuDetailList = (ids: number[]) => {
91+
return request.get({ url: `/product/spu/list?spuIds=${ids}` })
92+
}
93+
8994
// 删除商品 Spu
9095
export const deleteSpu = (id: number) => {
9196
return request.delete({ url: `/product/spu/delete?id=${id}` })

src/views/mall/promotion/components/SpuAndSkuList.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@
4747
</el-table>
4848
</template>
4949
<script generic="T extends Spu" lang="ts" setup>
50-
// TODO 后续计划重新封装作为活动商品配置通用组件;可以等其他活动做到的时候,在统一处理 SPU 选择组件哈
5150
import { formatToFraction } from '@/utils'
5251
import { createImageViewer } from '@/components/ImageViewer'
5352
import { Spu } from '@/api/mall/product/spu'
5453
import { RuleConfig, SkuList } from '@/views/mall/product/spu/components'
55-
import { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
5654
import { SpuProperty } from '@/views/mall/promotion/components/index'
5755
5856
defineOptions({ name: 'PromotionSpuAndSkuList' })
5957
60-
// TODO @puhui999:是不是改成传递一个 spu 就好啦? 因为活动商品可以多选所以展示编辑的时候需要展示多个
6158
const props = defineProps<{
6259
spuList: T[]
6360
ruleConfig: RuleConfig[]
@@ -70,12 +67,12 @@ const skuListRef = ref() // 商品属性列表Ref
7067
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId 对应的 sku 的属性列表
7168
7269
/**
73-
* 获取所有 sku 秒杀配置
70+
* 获取所有 sku 活动配置
7471
* @param extendedAttribute 在 sku 上扩展的属性,例:秒杀活动 sku 扩展属性 productConfig 请参考 seckillActivity.ts
7572
*/
76-
const getSkuConfigs: <V>(extendedAttribute: string) => V[] = (extendedAttribute: string) => {
73+
const getSkuConfigs = (extendedAttribute: string) => {
7774
skuListRef.value.validateSku()
78-
const seckillProducts: SeckillProductVO[] = []
75+
const seckillProducts = []
7976
spuPropertyList.value.forEach((item) => {
8077
item.spuDetail.skus.forEach((sku) => {
8178
seckillProducts.push(sku[extendedAttribute])

src/views/mall/promotion/seckill/activity/SeckillActivityForm.vue

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components'
3030
import { allSchemas, rules } from './seckillActivity.data'
3131
3232
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
33-
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
3433
import * as ProductSpuApi from '@/api/mall/product/spu'
34+
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
3535
3636
defineOptions({ name: 'PromotionSeckillActivityForm' })
3737
@@ -62,7 +62,7 @@ const open = async (type: string, id?: number) => {
6262
dialogVisible.value = true
6363
dialogTitle.value = t('action.' + type)
6464
formType.value = type
65-
resetForm()
65+
await resetForm()
6666
// 修改时,设置数据 TODO 没测试估计有问题
6767
if (id) {
6868
formLoading.value = true
@@ -89,34 +89,30 @@ const selectSpu = (spuIds: number[]) => {
8989
*/
9090
const getSpuDetails = async (spuIds: number[]) => {
9191
const spuProperties: SpuProperty<SeckillActivityApi.SpuExtension>[] = []
92+
const res = (await ProductSpuApi.getSpuDetailList(spuIds)) as SeckillActivityApi.SpuExtension[]
9293
spuList.value = []
93-
// TODO puhui999: 考虑后端添加通过 spuIds 批量获取
94-
for (const spuId of spuIds) {
95-
// 获取 SPU 详情
96-
const res = (await ProductSpuApi.getSpu(spuId)) as SeckillActivityApi.SpuExtension
97-
if (!res) {
98-
continue
99-
}
100-
spuList.value.push(res)
94+
res?.forEach((spu) => {
10195
// 初始化每个 sku 秒杀配置
102-
res.skus?.forEach((sku) => {
96+
spu.skus?.forEach((sku) => {
10397
const config: SeckillActivityApi.SeckillProductVO = {
104-
spuId,
98+
spuId: spu.id!,
10599
skuId: sku.id!,
106100
stock: 0,
107101
seckillPrice: 0
108102
}
109103
sku.productConfig = config
110104
})
111-
spuProperties.push({ spuId, spuDetail: res, propertyList: getPropertyList(res) })
112-
}
105+
spuProperties.push({ spuId: spu.id!, spuDetail: spu, propertyList: getPropertyList(spu) })
106+
})
107+
spuList.value.push(...res)
113108
spuPropertyList.value = spuProperties
114109
}
115110
116111
/** 重置表单 */
117-
const resetForm = () => {
112+
const resetForm = async () => {
118113
spuList.value = []
119114
spuPropertyList.value = []
115+
await nextTick()
120116
formRef.value.getElFormRef().resetFields()
121117
}
122118
/** 提交表单 */

0 commit comments

Comments
 (0)