diff --git a/api/product/spu.js b/api/product/spu.js
index 8af9f3d1..394b60d2 100644
--- a/api/product/spu.js
+++ b/api/product/spu.js
@@ -1,5 +1,12 @@
import request from "@/utils/request.js";
+// 获得商品 SPU 列表
+export function getSpuList(recommendType) {
+ return request.get('app-api/product/spu/list', {
+ recommendType
+ });
+}
+
// 获得商品 SPU 分页
export function getSpuPage(data) {
return request.get('app-api/product/spu/page', data);
diff --git a/api/promotion/activity.js b/api/promotion/activity.js
index 23818b2d..15256493 100644
--- a/api/promotion/activity.js
+++ b/api/promotion/activity.js
@@ -9,7 +9,7 @@ export function getActivityListBySpuId(spuId) {
// 获得多个商品,近期参与的每个活动
export function getActivityListBySpuIds(spuIds) {
- return request.get("app-api/promotion/activity/list-by-spu-id", {
+ return request.get("app-api/promotion/activity/list-by-spu-ids", {
spuIds
});
}
diff --git a/pages/goods_details/index.vue b/pages/goods_details/index.vue
index 715016e3..4ce2248e 100644
--- a/pages/goods_details/index.vue
+++ b/pages/goods_details/index.vue
@@ -99,7 +99,7 @@
-
+
@@ -110,21 +110,20 @@
-
+
-
+
-
+
秒杀
+ v-if="val.activityList && val.activityList[0] && val.activityList[0].type === 1">秒杀
砍价
+ v-if="val.activityList && val.activityList[0] && val.activityList[0].type === 2">砍价
拼团
+ v-if="val.activityList && val.activityList[0] && val.activityList[0].type === 3">拼团
- {{val.storeName}}
- ¥{{val.price}}
+ {{val.name}}
+ ¥{{ fen2yuan(val.price) }}
@@ -303,6 +302,8 @@
// #ifdef MP
import { base64src } from '@/utils/base64src.js'
import { getQrcode } from '@/api/api.js';
+ import {getActivityListBySpuIds} from "../../api/promotion/activity";
+ import {setActivityList} from "../../utils/product";
// #endif
const app = getApp();
export default {
@@ -355,12 +356,12 @@
// ========== 营销活动相关的变量 ==========
activityH5: [], // 活动列表
- // ========== 商品推荐相关的变量 ④ TODO ==========
- circular: false, // TODO 芋艿:没搞懂
- autoplay: false, // TODO 芋艿:没搞懂
- duration: 500, // TODO 芋艿:没搞懂
- interval: 3000, // TODO 芋艿:没搞懂
- good_list: [], // TODO 芋艿:优品推荐
+ // ========== 商品推荐相关的变量 ==========
+ good_list: [], // 推荐的商品数组
+ circular: false, // swiper 的 circular 变量
+ autoplay: false, // swiper 的 autoplay 变量
+ duration: 500, // swiper 的 duration 变量
+ interval: 3000, // swiper 的 interval 变量
// ========== 分销相关的变量 ==========
qrcodeSize: 600, // 二维码的大小
@@ -759,6 +760,12 @@
}
});
},
+ /**
+ * 跳转到客服
+ */
+ kefuClick() {
+ location.href = this.chatUrl;
+ },
// ========== 评价相关的方法 ==========
/**
@@ -848,107 +855,106 @@
/**
* 领取完毕后,刷新下优惠劵列表
*/
- ChangCoupons: function(coupon) {
- // let couponList = this.$util.ArrayRemove(this.couponList, 'id', coupon.id);
- // this.$set(this, 'coupon.couponList', couponList);
+ ChangCoupons: function() {
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}`
+ url: `/pages/activity/goods_seckill_details/index?id=${this.id}`
});
} else if (activity.type === 2) {
uni.navigateTo({
- url: `/pages/activity/goods_bargain_details/index?id=${activity.id}&startBargainUid=${this.uid}`
+ url: `/pages/activity/goods_bargain_details/index?id=${this.id}&startBargainUid=${this.uid}`
});
} else {
uni.navigateTo({
- url: `/pages/activity/goods_combination_details/index?id=${activity.id}`
+ url: `/pages/activity/goods_combination_details/index?id=${this.id}`
});
}
},
- // === TODO 芋艿:未处理 ====
+ // ========== 商品推荐相关方法 ==========
+ /**
+ * 优品推荐
+ */
+ getGoods() {
+ ProductSpuApi.getSpuList('good').then(res => {
+ const good_list = res.data || [];
+ if (good_list.length <= 0) {
+ return;
+ }
+ const count = Math.ceil(good_list.length / 6);
+ const goodArray = [];
+ for (let i = 0; i < count; i++) {
+ let list = good_list.slice(i * 6, i * 6 + 6);
+ if (list.length) goodArray.push({
+ list: list
+ });
+ }
+ this.$set(this, 'good_list', goodArray);
- kefuClick() {
- location.href = this.chatUrl;
- },
+ // 设置 nav bar
+ let navList = ['商品', '评价', '详情'];
+ if (goodArray.length) {
+ navList.splice(2, 0, '推荐')
+ }
+ this.$set(this, 'navList', navList);
+ this.$nextTick(() => {
+ if (good_list.length) {
+ this.setClientHeight();
+ }
+ })
+
+ // 设置营销活动
+ const spuIds = good_list.map(item => item.id);
+ PromotionActivityApi.getActivityListBySpuIds(spuIds).then(res => {
+ ProductUtil.setActivityList(good_list, res.data);
+ });
+ })
+ },
/**
* 去商品详情页
+ *
+ * @param spu 点击的商品
*/
- goDetail(item) {
- if (!item.activityH5) {
+ goDetail(spu) {
+ const activity = spu.activityList && spu.activityList[0] ? spu.activityList[0] : undefined;
+ if (!activity) {
uni.redirectTo({
- url: '/pages/goods_details/index?id=' + item.id
+ url: '/pages/goods_details/index?id=' + spu.id
})
- return
- }
- if (item.activityH5.length == 0) {
- uni.redirectTo({
- url: '/pages/goods_details/index?id=' + item.id
- })
- return
+ return;
}
+ // 秒杀
+ if (activity.type === 1) {
+ uni.redirectTo({
+ url: `/pages/activity/goods_seckill_details/index?id=${spu.id}`
+ })
+ return
+ }
// 砍价
- if (item.activityH5 && item.activityH5.type == 2) {
+ if (activity.type === 2) {
uni.redirectTo({
- url: `/pages/activity/goods_bargain_details/index?id=${item.activityH5.id}&bargain=${this.uid}`
+ url: `/pages/activity/goods_bargain_details/index?id=${spu.id}&bargain=${this.uid}`
})
return
}
// 拼团
- if (item.activityH5 && item.activityH5.type == 3) {
+ if (activity.type === 3) {
uni.redirectTo({
- url: `/pages/activity/goods_combination_details/index?id=${item.activityH5.id}`
- })
- return
- }
- // 秒杀
- if (item.activityH5 && item.activityH5.type == 1) {
- uni.redirectTo({
- url: `/pages/activity/goods_seckill_details/index?id=${item.activityH5.id}`
+ url: `/pages/activity/goods_combination_details/index?id=${spu.id}`
})
}
},
- /**
- * 优品推荐
- */
- getGoods() {
- getProductGood().then(res => {
- let good_list = res.data.list || [];
- let count = Math.ceil(good_list.length / 6);
- let goodArray = new Array();
- for (let i = 0; i < count; i++) {
- let list = good_list.slice(i * 6, i * 6 + 6);
- if (list.length) goodArray.push({
- list: list
- });
- }
- this.$set(this, 'good_list', goodArray);
-
- // 设置 nav bar
- let navList = ['商品', '评价', '详情'];
- if (goodArray.length) {
- navList.splice(2, 0, '推荐')
- }
- this.$set(this, 'navList', navList);
- this.$nextTick(() => {
- if (good_list.length) {
- this.setClientHeight();
- }
- })
- });
- },
-
// ========== 分销相关的方法 ==========
/**
* 生成二维码,设置到 promotionCode 变量
diff --git a/utils/product.js b/utils/product.js
index d311214b..a27328ca 100644
--- a/utils/product.js
+++ b/utils/product.js
@@ -90,3 +90,20 @@ export function sortActivityList(activityList, spu) {
}
return result;
}
+
+/**
+ * 将营销活动,设置到 SPU 中
+ *
+ * @param spuList SPU 数组
+ * @param activityListMap 营销活动 Map,key 为 SPU ID,value 为营销活动数组
+ */
+export function setActivityList(spuList, activityListMap) {
+ if (!spuList || spuList.length === 0) {
+ return;
+ }
+ for (const spu of spuList) {
+ spu.activityList = activityListMap[spu.id + ''] || [];
+ spu.activityList = sortActivityList(spu.activityList, spu);
+ }
+ console.log(spuList);
+}