【代码优化】商城:拼团装修重构

pull/539/head
YunaiV 2024-09-06 20:55:08 +08:00
parent a2091df2df
commit 7d60b5a619
6 changed files with 11 additions and 28 deletions

View File

@ -17,9 +17,6 @@ export interface CombinationActivityVO {
status?: number
limitDuration?: number
products: CombinationProductVO[]
spuName?: string
picUrl?: string
marketPrice?: number
}
// 拼团活动所需属性
@ -39,7 +36,7 @@ export interface SpuExtension extends Spu {
}
// 查询拼团活动列表
export const getCombinationActivityPage = async (params) => {
export const getCombinationActivityPage = async (params: any) => {
return await request.get({ url: '/promotion/combination-activity/page', params })
}
@ -48,8 +45,8 @@ export const getCombinationActivity = async (id: number) => {
return await request.get({ url: '/promotion/combination-activity/get?id=' + id })
}
// 查询拼团活动详情列表
export const getCombinationActivityDetailList = (ids: number[]) => {
// 获得拼团活动列表,基于活动编号数组
export const getCombinationActivityListByIds = (ids: number[]) => {
return request.get({ url: `/promotion/combination-activity/list-by-ids?ids=${ids}` })
}

View File

@ -136,30 +136,20 @@ watch(
// ID
const activityIds = props.property.activityIds
// ID
if (
Array.isArray(activityIds) &&
activityIds.length > 0 &&
activityIds.every((item) => item != null)
) {
if (Array.isArray(activityIds) && activityIds.length > 0) {
//
combinationActivityList.value =
await CombinationActivityApi.getCombinationActivityDetailList(activityIds)
await CombinationActivityApi.getCombinationActivityListByIds(activityIds)
//
spuIdList.value = []
// SPU
spuList.value = []
// spuId
spuIdList.value = combinationActivityList.value
.map((activity) => activity.spuId)
.filter((spuId): spuId is number => typeof spuId === 'number')
// spuId API
if (spuIdList.value.length > 0) {
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value)
} else {
console.warn('没有用于获取详细信息的有效 spuId。')
}
// SPU
combinationActivityList.value.forEach((activity) => {
activity.products.forEach((product) => {

View File

@ -158,7 +158,6 @@ onMounted(async () => {
status: CommonStatusEnum.ENABLE
})
activityList.value = list
console.log('formDa', props)
})
</script>

View File

@ -151,13 +151,8 @@
class="m-[calc(0px-var(--el-card-padding))]"
view-class="p-[var(--el-card-padding)] p-b-[calc(var(--el-card-padding)+var(--el-card-padding))] property"
>
<!--这里的 key 使用时间戳是为了保证每次点击组件都进行刷新-->
<component
:key="
selectedComponent?.uid ||
selectedComponent?.id + new Date().getTime() ||
new Date().getTime().toString()
"
:key="selectedComponent?.uid || selectedComponent?.id"
:is="selectedComponent?.id + 'Property'"
v-model="selectedComponent.property"
/>

View File

@ -85,6 +85,7 @@ const openSpuTableSelect = () => {
/**
* 选择商品后触发
*
* @param spus 选中的商品列表
*/
const handleSpuSelected = (spus: ProductSpuApi.Spu | ProductSpuApi.Spu[]) => {
@ -94,6 +95,7 @@ const handleSpuSelected = (spus: ProductSpuApi.Spu | ProductSpuApi.Spu[]) => {
/**
* 删除商品
*
* @param index 商品索引
*/
const handleRemoveSpu = (index: number) => {

View File

@ -81,7 +81,7 @@ watch(
Activitys.value.length === 0 ||
Activitys.value.some((combinationActivity) => !ids.includes(combinationActivity.id!))
) {
Activitys.value = await CombinationActivityApi.getCombinationActivityDetailList(ids)
Activitys.value = await CombinationActivityApi.getCombinationActivityListByIds(ids)
}
},
{ immediate: true }