From fd7777e4f404f580969b0153cd26ea756ae5ab31 Mon Sep 17 00:00:00 2001 From: qiaomu <3520484422@qq.com> Date: Mon, 9 Dec 2024 10:36:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/discountCoupon/index.js | 15 ++++++++++++--- components/discountCoupon/index.wxml | 1 + pages/discountCoupon/index.js | 27 +++++++++++++++++++++++++-- pages/discountCoupon/index.json | 3 ++- pages/discountCoupon/index.wxml | 8 ++++++-- service/system.js | 4 ++-- 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/components/discountCoupon/index.js b/components/discountCoupon/index.js index 6ff50f7..4eae670 100644 --- a/components/discountCoupon/index.js +++ b/components/discountCoupon/index.js @@ -25,9 +25,6 @@ Component({ * 组件的方法列表 */ methods: { - handleUse() { - alertInfo("敬请期待") - }, handleChange() { const { data } = this.data; const that = this; @@ -42,6 +39,18 @@ Component({ alertSuccess("兑换成功") this.triggerEvent("change", { id, type: 2 }) }) + }, + handleUseIt() { + alertInfo("敬请期待") + }, + async handleUse(e) { + const { data } = this.data; + const { code, message } = await redeemCoupons({ id: data.id, type: 2 }) + if (code !== OK) { + alertInfo(message) + return; + } + this.triggerEvent("get", { id, type: 1 }) } } }) \ No newline at end of file diff --git a/components/discountCoupon/index.wxml b/components/discountCoupon/index.wxml index c1b1018..8db85d7 100644 --- a/components/discountCoupon/index.wxml +++ b/components/discountCoupon/index.wxml @@ -32,6 +32,7 @@ 去领取 去兑换 + 去使用 \ No newline at end of file diff --git a/pages/discountCoupon/index.js b/pages/discountCoupon/index.js index e74c84c..fee8d76 100644 --- a/pages/discountCoupon/index.js +++ b/pages/discountCoupon/index.js @@ -13,6 +13,7 @@ Page({ data: { currentList: [], canGetList: [], + active: 0, }, /** @@ -21,7 +22,17 @@ Page({ onLoad(options) { }, - + onChange(e) { + console.log('e', e) + this.setData({ + active: e.detail.index, + }, () => { + const { active } = this.data; + this.init(active); + }) + + }, + /** * 生命周期函数--监听页面初次渲染完成 */ @@ -33,8 +44,20 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - + const { active } = this.data; + this.init(active); }, + init(active) { + switch(active) { + case 0: + this.getCurrent() + break; + case 1: + this.getCanGet(); + break; + } + }, + async getCurrent() { const that = this; loadingFunc(async() => { diff --git a/pages/discountCoupon/index.json b/pages/discountCoupon/index.json index 06c8be8..f448c1b 100644 --- a/pages/discountCoupon/index.json +++ b/pages/discountCoupon/index.json @@ -2,7 +2,8 @@ "usingComponents": { "navigator": "/components/navigator/index", "van-tab": "@vant/weapp/tab/index", - "van-tabs": "@vant/weapp/tabs/index" + "van-tabs": "@vant/weapp/tabs/index", + "discount-coupon": "/components/discountCoupon/index" }, "navigationStyle": "custom" } \ No newline at end of file diff --git a/pages/discountCoupon/index.wxml b/pages/discountCoupon/index.wxml index db106bb..6c4ca6f 100644 --- a/pages/discountCoupon/index.wxml +++ b/pages/discountCoupon/index.wxml @@ -3,13 +3,17 @@ - + + + - + + + diff --git a/service/system.js b/service/system.js index fbf4cf9..94a2d5f 100644 --- a/service/system.js +++ b/service/system.js @@ -82,11 +82,11 @@ export const getIntegralRecord = async function({ page, size }) { } // 获取优惠券列表 -export const getRedeemableCoupons = async function({ page, size, type }) { +export const getRedeemableCoupons = async function({ page = '', size = '', type }) { return await GET(`/wx/getRedeemableCoupons?page=${page}&size=${size}&type=${type}`); } -// 获取优惠券列表 +// 兑换/领取优惠券 export const redeemCoupons = async function({ id, type }) { return await POST(`/wx/redeemCoupons`, { id, type }); }