From b95e711f80098e965202fa962e1b7c2a74519305 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 6 Jan 2024 20:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=8C=87=E5=AE=9A=E6=BB=A1?= =?UTF-8?q?=E5=87=8F=E9=80=81=E7=9A=84=E6=B4=BB=E5=8A=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=9A100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/activity/index.vue | 105 ++++++++++-------- sheep/api/goods.js | 11 -- sheep/api/promotion/rewardActivity.js | 14 +++ .../s-activity-pop/s-activity-pop.vue | 34 ++++-- sheep/hooks/useGoods.js | 17 +++ 5 files changed, 116 insertions(+), 65 deletions(-) create mode 100644 sheep/api/promotion/rewardActivity.js diff --git a/pages/activity/index.vue b/pages/activity/index.vue index 0a33581c..f36a0e5a 100644 --- a/pages/activity/index.vue +++ b/pages/activity/index.vue @@ -1,11 +1,13 @@ + @@ -61,27 +64,32 @@ import { onLoad, onReachBottom } from '@dcloudio/uni-app'; import sheep from '@/sheep'; import _ from 'lodash'; + import RewardActivityApi from '@/sheep/api/promotion/rewardActivity'; + import { formatRewardActivityRule } from '@/sheep/hooks/useGoods'; + import SpuApi from '@/sheep/api/product/spu'; const state = reactive({ + activityId: 0, // 获得编号 + activityInfo: {}, // 获得信息 + pagination: { - data: [], - current_page: 1, + list: [], total: 1, - last_page: 1, + pageNo: 1, + pageSize: 8, }, loadStatus: '', leftGoodsList: [], rightGoodsList: [], - activityId: 0, - activityInfo: {}, }); + // 加载瀑布流 let count = 0; let leftHeight = 0; let rightHeight = 0; function mountMasonry(height = 0, where = 'left') { - if (!state.pagination.data[count]) return; + if (!state.pagination.list[count]) return; if (where === 'left') { leftHeight += height; @@ -89,57 +97,64 @@ rightHeight += height; } if (leftHeight <= rightHeight) { - state.leftGoodsList.push(state.pagination.data[count]); + state.leftGoodsList.push(state.pagination.list[count]); } else { - state.rightGoodsList.push(state.pagination.data[count]); + state.rightGoodsList.push(state.pagination.list[count]); } count++; } - async function getList(activityId, page = 1, list_rows = 6) { - state.loadStatus = 'loading'; - const res = await sheep.$api.goods.activityList({ - list_rows, - activity_id: activityId, - page, - }); - if (res.error === 0) { - if (page >= 2) { - let couponList = _.concat(state.pagination.data, res.data.data); - state.pagination = { - ...res.data, - data: couponList, - }; - } else { - state.pagination = res.data; - } - mountMasonry(); - if (state.pagination.current_page < state.pagination.last_page) { - state.loadStatus = 'more'; - } else { - state.loadStatus = 'noMore'; - } + + // 加载商品信息 + async function getList() { + // 处理拓展参数 + const params = {}; + if (state.activityInfo.productScope === 2) { + params.ids = state.activityInfo.productSpuIds.join(','); + } else if (state.activityInfo.productScope === 3) { + params.categoryIds = state.activityInfo.productSpuIds.join(','); } + // 请求数据 + state.loadStatus = 'loading'; + const { code, data } = await SpuApi.getSpuPage({ + pageNo: state.pagination.pageNo, + pageSize: state.pagination.pageSize, + ...params + }); + if (code !== 0) { + return; + } + state.pagination.list = _.concat(state.pagination.list, data.list); + state.pagination.total = data.total; + state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore'; + mountMasonry(); } + + // 加载活动信息 async function getActivity(id) { - const { error, data } = await sheep.$api.activity.activity(id); - if (error === 0) { + const { code, data } = await RewardActivityApi.getRewardActivity(id); + if (code === 0) { state.activityInfo = data; } } + // 加载更多 - function loadmore() { - if (state.loadStatus !== 'noMore') { - getList(state.activityId, state.pagination.current_page + 1); + function loadMore() { + if (state.loadStatus === 'noMore') { + return; } + state.pagination.pageNo++; + getList(); } + // 上拉加载更多 onReachBottom(() => { - loadmore(); + loadMore(); }); - onLoad((options) => { + + onLoad(async (options) => { state.activityId = options.activityId; - getList(state.activityId); - getActivity(state.activityId); + await getActivity(state.activityId); + await getList(state.activityId); });