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); });