【代码优化】拼团活动逻辑优化
parent
85441704cb
commit
b6dd2ae1eb
|
@ -37,7 +37,7 @@ const CombinationApi = {
|
||||||
url: '/promotion/combination-activity/detail-list',
|
url: '/promotion/combination-activity/detail-list',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: {
|
params: {
|
||||||
ids,
|
ids
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -58,9 +58,9 @@ const CombinationApi = {
|
||||||
// 获得我的拼团记录分页
|
// 获得我的拼团记录分页
|
||||||
getCombinationRecordPage: (params) => {
|
getCombinationRecordPage: (params) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/promotion/combination-record/page',
|
url: "/promotion/combination-record/page",
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,7 @@
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import CombinationApi from '@/sheep/api/promotion/combination';
|
import CombinationApi from '@/sheep/api/promotion/combination';
|
||||||
import SpuApi from '@/sheep/api/product/spu';
|
import SpuApi from '@/sheep/api/product/spu';
|
||||||
|
import spu from '@/sheep/api/product/spu';
|
||||||
|
|
||||||
// 布局类型
|
// 布局类型
|
||||||
const LayoutTypeEnum = {
|
const LayoutTypeEnum = {
|
||||||
|
@ -241,21 +242,35 @@
|
||||||
* @param ids 商品编号列表
|
* @param ids 商品编号列表
|
||||||
* @return {Promise<undefined>} 商品列表
|
* @return {Promise<undefined>} 商品列表
|
||||||
*/
|
*/
|
||||||
async function getSpuDetail(spuId) {
|
async function getSpuDetail(ids) {
|
||||||
const { data: spu } = await SpuApi.getSpuDetail(spuId)
|
const { data: spu } = await SpuApi.getSpuDetail(ids);
|
||||||
return spu;
|
return spu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 加载商品列表
|
// 加载活动列表
|
||||||
const activityList = await getCombinationActivityDetailList(activityIds.join(','));
|
const activityList = await getCombinationActivityDetailList(activityIds.join(','));
|
||||||
// 创建 SPU 请求的 Promise 数组
|
// 循环获取活动商品SPU详情并添加到spuList
|
||||||
const spuPromises = activityList.map(activity => getSpuDetail(activity.spuId));
|
for (const activity of activityList) {
|
||||||
// 等待所有 SPU 请求完成
|
state.spuList.push(await getSpuDetail(activity.spuId));
|
||||||
// 处理 spuList
|
}
|
||||||
state.spuList = await Promise.all(spuPromises);
|
|
||||||
|
|
||||||
|
// 循环活动列表
|
||||||
|
activityList.forEach(activity => {
|
||||||
|
// 获取活动商品的最低价格
|
||||||
|
activity.products.forEach(product => {
|
||||||
|
const combinationPrice = product.combinationPrice || Infinity;
|
||||||
|
|
||||||
|
// 找到对应的 spu 并更新价格
|
||||||
|
const spu = state.spuList.find(spu => activity.spuId === spu.id);
|
||||||
|
if (spu) {
|
||||||
|
spu.price = Math.min(combinationPrice, spu.price || Infinity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 只有双列布局时需要
|
// 只有双列布局时需要
|
||||||
if (layoutType === LayoutTypeEnum.TWO_COL) {
|
if (layoutType === LayoutTypeEnum.TWO_COL) {
|
||||||
|
@ -273,11 +288,13 @@
|
||||||
.goods-list-box {
|
.goods-list-box {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
.left-list {
|
.left-list {
|
||||||
&:nth-last-child(1) {
|
&:nth-last-child(1) {
|
||||||
margin-bottom: 0 !important;
|
margin-bottom: 0 !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-list {
|
.right-list {
|
||||||
&:nth-last-child(1) {
|
&:nth-last-child(1) {
|
||||||
margin-bottom: 0 !important;
|
margin-bottom: 0 !important;
|
||||||
|
|
Loading…
Reference in New Issue