From 7af73df8040427da23d0ad37ff72aa21de3ae991 Mon Sep 17 00:00:00 2001 From: XiaoXinPro 14 IAH5R <568170040@qq.com> Date: Thu, 23 Mar 2023 10:53:18 +0800 Subject: [PATCH] upload --- pages/specialcourtesy/specialcourtesy.js | 47 ++++++++++++++++++---- pages/specialcourtesy/specialcourtesy.wxml | 4 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/pages/specialcourtesy/specialcourtesy.js b/pages/specialcourtesy/specialcourtesy.js index e7771f5..63838ad 100644 --- a/pages/specialcourtesy/specialcourtesy.js +++ b/pages/specialcourtesy/specialcourtesy.js @@ -17,7 +17,7 @@ Page({ goHomeUrl: "", showCode: true, showTimeLine: true, - expiredSeconds: 30 + expiredSeconds: 0 }, phone: function (e) { console.log(e) @@ -44,26 +44,36 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - - this.ifPhoneInfo() let that = this; + that.ifPhoneInfo() that.setData({ goHomeUrl: app.globalData.goHomeUrl, }) console.log("渲染开始") + that.getDiscountInfo() + }, + + refreshCode() { + this.setData({ + showCode: true + }) + this.getDiscountInfo() + }, + + getDiscountInfo() { + let that = this; Http.get({ url: config.api.getDiscountInfo, - data: {} }) .then(res => { that.setData({ level: res.data.level ? res.data.level : '' }) - that.qrcode(res.data.id); + that.qrcode(res.data.dynamicId); that.setData({ - memberId: res.data.id + memberId: res.data.id, + expiredSeconds: res.data.expiredSeconds, }) - console.log(res.data.levelMerchantList) let discountMerchantList = []; res.data.levelMerchantList.map(file => { if (file.discount != 100) { @@ -73,6 +83,27 @@ Page({ that.setData({ discountMerchantList: discountMerchantList, }) + if (that.data.expiredSeconds * 1) { + const timer = setInterval(() => { + const expiredSeconds = that.data.expiredSeconds + if (expiredSeconds) { + that.setData({ + expiredSeconds: expiredSeconds - 1, + }) + } else { + clearInterval(timer) + that.setData({ + showCode: false, + }) + } + + }, 1000); + } + }).catch(err => { + console.log(err, 'err'); + wx.showToast({ + title: err.message, + }) }) }, @@ -85,7 +116,7 @@ Page({ /** * 二维码 */ - qrcode: function (memberId) { + qrcode(memberId) { let that = this; var size = that.setCanvasSize(); let url = JSON.stringify({ diff --git a/pages/specialcourtesy/specialcourtesy.wxml b/pages/specialcourtesy/specialcourtesy.wxml index 4a4d3c4..c9b0576 100644 --- a/pages/specialcourtesy/specialcourtesy.wxml +++ b/pages/specialcourtesy/specialcourtesy.wxml @@ -11,7 +11,7 @@ - + @@ -19,7 +19,7 @@ - 二维码将在 + 二维码将在 {{expiredSeconds}}s 后失效