From ddf9aa6d8a6374402f73303cd25592a2ad592ff9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 11 Jun 2023 22:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A7=92=E6=9D=80=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E3=80=91=201.=20=E6=8E=A5=E5=85=A5=E6=94=B6?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/goods_seckill_details/index.vue | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/pages/activity/goods_seckill_details/index.vue b/pages/activity/goods_seckill_details/index.vue index d333c2fa..8f0a0c84 100644 --- a/pages/activity/goods_seckill_details/index.vue +++ b/pages/activity/goods_seckill_details/index.vue @@ -430,14 +430,14 @@ // 获得商品详情 this.getGoodsDetails(); - // TODO 收藏 - // this.isFavoriteExists(); + // 获得商品收藏 + this.isFavoriteExists(); // 获得商品评价列表 this.getProductReplyList(); this.getProductReplyCount(); - app.globalData.openPages = '/pages/activity/goods_seckill_details/index?id=' + this.id - + '&spread=' + this.uid; + app.globalData.openPages = '/pages/activity/goods_seckill_details/index?id=' + + this.id + '&spread=' + this.uid; }).catch(err => { that.$util.Tips({ title:err @@ -684,6 +684,41 @@ }); }, + // ========== 收藏相关方法 ========== + /** + * 获得是否收藏 + */ + isFavoriteExists: function() { + if (!this.isLogin) { + return; + } + + ProductFavoriteApi.isFavoriteExists(this.activity.spuId).then(res => { + this.userCollect = res.data; + }); + }, + /** + * 收藏 / 取消商品 + */ + setCollect: function() { + if (!this.isLogin) { + toLogin(); + return; + } + + // 情况一:取消收藏 + if (this.userCollect) { + ProductFavoriteApi.deleteFavorite(this.activity.spuId).then(res => { + this.$set(this, 'userCollect', false); + }) + // 情况二:添加收藏 + } else { + ProductFavoriteApi.createFavorite(this.activity.spuId).then(res => { + this.$set(this, 'userCollect', true); + }) + } + }, + // TODO 芋艿:暂未整理 @@ -766,21 +801,7 @@ }); } }, - /** - * 收藏商品 - */ - setCollect: function() { - var that = this; - if (this.userCollect) { - collectDel(this.storeInfo.productId).then(res => { - that.userCollect = !that.userCollect - }) - } else { - collectAdd(this.storeInfo.productId).then(res => { - that.userCollect = !that.userCollect - }) - } - }, + /** * 分享打开 *