From 275e8a278f33f1cc505448110a3219bf16e606ef Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 16 Dec 2023 19:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=EF=BC=9A=E4=BC=98=E6=83=A0=E5=8A=B5=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/coupon/detail.vue | 19 ++++++---- pages/coupon/list.vue | 2 +- pages/goods/index.vue | 38 +++++++++---------- .../components/s-coupon-get/s-coupon-get.vue | 19 +++++----- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/pages/coupon/detail.vue b/pages/coupon/detail.vue index 1bb102d0..0a760d27 100644 --- a/pages/coupon/detail.vue +++ b/pages/coupon/detail.vue @@ -209,18 +209,21 @@ } } + // 领取优惠劵 async function getCoupon() { - const { error, msg } = await sheep.$api.coupon.get(state.id); - if (error === 0) { - uni.showToast({ - title: msg, - }); - setTimeout(() => { - getCouponContent(state.id, state.couponId); - }, 1000); + const { code } = await CouponApi.takeCoupon(state.id); + if (code !== 0) { + return; } + uni.showToast({ + title: '领取成功', + }); + setTimeout(() => { + getCouponContent(); + }, 1000); } + // 加载优惠劵信息 async function getCouponContent() { const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id) : await CouponApi.getCoupon(state.couponId); diff --git a/pages/coupon/list.vue b/pages/coupon/list.vue index acd658e2..5c01f294 100644 --- a/pages/coupon/list.vue +++ b/pages/coupon/list.vue @@ -111,7 +111,7 @@ state.currentTab = e.index; state.type = e.value; resetPagination(state.pagination) - if (state.currentTab == 0) { + if (state.currentTab === 0) { getData(); } else { getCoupon(); diff --git a/pages/goods/index.vue b/pages/goods/index.vue index fa481c9a..a0d3de22 100644 --- a/pages/goods/index.vue +++ b/pages/goods/index.vue @@ -186,18 +186,16 @@ // 立即领取 TODO 芋艿:待测试 async function onGet(id) { - const { - error, - msg - } = await sheep.$api.coupon.get(id); - if (error === 0) { - uni.showToast({ - title: msg, - }); - setTimeout(() => { - getCoupon(); - }, 1000); - } + const { code } = await CouponApi.takeCoupon(id); + if (code !== 0) { + return; + } + uni.showToast({ + title: '领取成功', + }); + setTimeout(() => { + getCoupon(); + }, 1000); } // TODO 芋艿:待测试 @@ -221,7 +219,14 @@ }, ); }); - onLoad(async (options) => { + async function getCoupon() { + const { code, data } = await CouponApi.getCouponTemplateList(state.goodsId, 2, 10); + if (code === 0) { + state.couponInfo = data; + } + } + + onLoad((options) => { // 非法参数 if (!options.id) { state.goodsInfo = null; @@ -249,12 +254,7 @@ }); // 2. 加载优惠劵信息 - CouponApi.getCouponTemplateList(state.goodsId, 2, 10).then((res) => { - if (res.code !== 0) { - return; - } - state.couponInfo = res.data; - }); + getCoupon(); // 3. 加载营销活动信息 ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => { diff --git a/sheep/components/s-coupon-get/s-coupon-get.vue b/sheep/components/s-coupon-get/s-coupon-get.vue index bfa9b9bb..6df6b558 100644 --- a/sheep/components/s-coupon-get/s-coupon-get.vue +++ b/sheep/components/s-coupon-get/s-coupon-get.vue @@ -1,3 +1,4 @@ + @@ -38,6 +37,7 @@