diff --git a/api/promotion/activity.js b/api/promotion/activity.js new file mode 100644 index 00000000..23818b2d --- /dev/null +++ b/api/promotion/activity.js @@ -0,0 +1,15 @@ +import request from "@/utils/request.js"; + +// 获得单个商品,近期参与的每个活动 +export function getActivityListBySpuId(spuId) { + return request.get("app-api/promotion/activity/list-by-spu-id", { + spuId + }); +} + +// 获得多个商品,近期参与的每个活动 +export function getActivityListBySpuIds(spuIds) { + return request.get("app-api/promotion/activity/list-by-spu-id", { + spuIds + }); +} diff --git a/pages/goods_details/index.vue b/pages/goods_details/index.vue index 85eb7c60..715016e3 100644 --- a/pages/goods_details/index.vue +++ b/pages/goods_details/index.vue @@ -56,27 +56,22 @@ - + 活   动: - - + 参与秒杀 - + 参与砍价 - - + + 参与拼团 @@ -301,6 +296,7 @@ import * as ProductFavoriteApi from '@/api/product/favorite.js'; import * as ProductCommentApi from '@/api/product/comment.js'; import * as CouponTemplateApi from '@/api/promotion/couponTemplate.js'; + import * as PromotionActivityApi from '@/api/promotion/activity.js'; import * as TradeCartApi from '@/api/trade/cart.js'; import * as Util from '@/utils/util.js'; import * as ProductUtil from '@/utils/product.js'; @@ -356,8 +352,8 @@ list: [], // 优惠劵列表 }, - // ========== 营销活动相关的变量 ③ TODO ========== - activityH5: [], // TODO 芋艿:活动? + // ========== 营销活动相关的变量 ========== + activityH5: [], // 活动列表 // ========== 商品推荐相关的变量 ④ TODO ========== circular: false, // TODO 芋艿:没搞懂 @@ -512,17 +508,22 @@ */ getGoodsDetails: function() { ProductSpuApi.getSpuDetail(this.id).then(res => { - let productInfo = res.data; let spu = res.data; let skus = res.data.skus; this.$set(this, 'spu', spu); this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus)); this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus)); + // 设置分销相关变量 // TODO 芋艿:待接入 this.$set(this.sharePacket, 'priceName', res.data.priceName); this.$set(this.sharePacket, 'isState', Math.floor(res.data.priceName) === 0); + // 设置营销活动 - this.$set(this, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []); + PromotionActivityApi.getActivityListBySpuId(this.id).then(res => { + let activityList = res.data; + activityList = ProductUtil.sortActivityList(activityList); + this.$set(this, 'activityH5', activityList); + }); // 设置标题 uni.setNavigationBarTitle({ @@ -853,27 +854,33 @@ this.getCouponList(this.coupon.type); }, + // ========== 营销相关方法 ========== + /** + * 前往活动页面 + * + * @param activity 活动 + */ + goActivity: function(activity) { + if (activity.type === 1) { + uni.navigateTo({ + url: `/pages/activity/goods_seckill_details/index?id=${activity.id}` + }); + } else if (activity.type === 2) { + uni.navigateTo({ + url: `/pages/activity/goods_bargain_details/index?id=${activity.id}&startBargainUid=${this.uid}` + }); + } else { + uni.navigateTo({ + url: `/pages/activity/goods_combination_details/index?id=${activity.id}` + }); + } + }, + // === TODO 芋艿:未处理 ==== kefuClick() { location.href = this.chatUrl; }, - goActivity: function(e) { - let item = e; - if (item.type === "1") { - uni.navigateTo({ - url: `/pages/activity/goods_seckill_details/index?id=${item.id}` - }); - } else if (item.type === "2") { - uni.navigateTo({ - url: `/pages/activity/goods_bargain_details/index?id=${item.id}&startBargainUid=${this.uid}` - }); - } else { - uni.navigateTo({ - url: `/pages/activity/goods_combination_details/index?id=${item.id}` - }); - } - }, /** * 去商品详情页 */ diff --git a/utils/product.js b/utils/product.js index 61ac9cca..d311214b 100644 --- a/utils/product.js +++ b/utils/product.js @@ -68,3 +68,25 @@ export function convertProductSkuMap(skus) { } return result } + +/** + * 根据 SPU 的活动展示顺序,排序活动列表 + * + * @param activityList 原始的活动列表 + * @param spu + * @return 新的活动列表 + */ +export function sortActivityList(activityList, spu) { + if (!spu || !spu.activityOrders) { + return activityList; + } + const result = []; + for (const activityOrder of spu.activityOrders) { + for (const activity of activityList) { + if (activity.type === activityOrder) { + result.push(activity) + } + } + } + return result; +}