From f0d0eccd72893d1012a1600d4e74c97731a1db58 Mon Sep 17 00:00:00 2001 From: meo <18801474720@163.com> Date: Wed, 26 Dec 2018 15:08:45 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=A6=96=E9=A1=B5=E4=BC=9A=E5=91=98=E6=9D=83?= =?UTF-8?q?=E7=9B=8A]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 90 ++++++++++++++++++++++++++++++++++++++++++ pages/index/index.wxml | 16 +++++--- pages/index/index.wxss | 70 +++++++++++++++++++++++++++++--- pages/user/index.js | 4 +- 4 files changed, 166 insertions(+), 14 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index d10b867..a5d89a8 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -2,6 +2,7 @@ const Http = require("../../utils/HttpBasics"); const imgurl = require("../../utils/imgurl"); const config = require("../../config/config"); +const QR = require("../../utils/memberqrcode.js"); let app = getApp(); Page({ data: { @@ -22,6 +23,66 @@ Page({ showIf: false, page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载 }, + gotodiscountCardList:function(){ + wx.navigateTo({ + url: '/pages/discountCardList/discountCardList' + }) + }, + gotoRushBuy:function(){ + wx.navigateTo({ + url: '/pages/rushToBuy/index', + }) + }, + qrcode: function (e) { + var that = this; + that.setData({ + showQrcode: true + }) + wx.showToast({ + title: '生成中...', + icon: 'loading', + duration: 2000 + }); + console.log(e) + var st = setTimeout(function () { + wx.hideToast() + var size = that.setCanvasSize(); + var url = JSON.stringify({ flagid: that.data.memberId }); + that.createQrCode(url, "mycanvas2", size.w, size.h); + that.setData({ + maskHidden: true + }); + clearTimeout(st); + }, 1000) + }, + hideQrcode: function () { + let that = this; + that.setData({ + showQrcode: false + }) + }, + //适配不同屏幕大小的canvas + setCanvasSize: function () { + var size = {}; + try { + var res = wx.getSystemInfoSync(); + var scale = 750 / 500; + //不同屏幕下canvas的适配比例;设计稿是750宽 + var width = res.windowWidth / scale; + var height = width; + //canvas画布为正方形 + size.w = width; + size.h = height; + } catch (e) { + // Do something when catch error + console.log("获取设备信息失败" + e); + } + return size; + }, + createQrCode: function (url, canvasId, cavW, cavH) { + //调用插件中的draw方法,绘制二维码图片 + QR.api.draw(url, canvasId, cavW, cavH); + }, swiperChange: function (e) { this.setData({ swiperCurrent: e.detail.current @@ -133,6 +194,34 @@ Page({ }) }; }, + // 会员码获取 + getmemberId: function (token){ + let that = this; + Http.get({ + url: config.api.getScore, + data: { + token: token + } + }).then(res => { + console.log(res) + if (res.data.nickName) { + that.setData({ + ismember: true, + memberId: res.data.id + }) + var size = this.setCanvasSize(); + var initUrl = JSON.stringify({ flagid: res.data.id }); + that.createQrCode(initUrl, "mycanvas1", size.w, size.h); + } + }) + .catch(err => { + wx.showModal({ + title: '提示', + content: err.message, + showCancel: false + }) + }) + }, /** * * @param {code,page} @@ -190,6 +279,7 @@ Page({ if (res.data.token){ that.getGameOne(res.data.token) that.getStaticGame(res.data.token) + that.getmemberId(res.data.token); } Http.setToken(res.data.token); that.checkUserCarStatus(); diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 6acd398..60cae61 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -2,18 +2,16 @@ - - - + 限时抢购 - + 优惠卡 - + 会员权益 @@ -26,4 +24,10 @@ - \ No newline at end of file + + + + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index de885ea..5dc83b4 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -15,28 +15,86 @@ page { width: 100%; - height: auto!important; + height: auto !important; overflow-x: hidden; } .txt { margin-left: 20rpx; } -.game-entry{ + +.game-entry { width: 690rpx; height: 140rpx; - margin: 30rpx auto 0; + margin: 57rpx auto 0; } -.gameimg{ + +.gameimg { display: block; width: 100%; height: 140rpx; } -.section{ + +.section { display: flex; justify-content: space-around; + text-align: center; + margin-top: 40rpx; } -.section >view image{ + +.section >view image { width: 121rpx; display: block; +} + +.section text { + height: 23rpx; + font-size: 24rpx; + font-family: PingFang-SC-Medium; + font-weight: 500; + color: rgba(51, 51, 51, 1); + display: block; + margin-top: 0rpx; +} + +.showQrcode { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 1000; + background: rgba(0, 0, 0, 0.6); +} + +.qrcode image { + width: 70rpx; + margin-right: 20rpx; +} +.showQrcode { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 1000; + background: rgba(0, 0, 0, 0.6); +} +.canvas-box { + position: fixed; + width: 500rpx; + height: 587rpx; + overflow: hidden; + left: 0; + top: 0; + bottom: 0; + right: 0; + margin: auto; + background: #fff; + border-radius: 16rpx; +} +.showQrcode text{ + display: block; + text-align: center; + font-size: 28rpx; } \ No newline at end of file diff --git a/pages/user/index.js b/pages/user/index.js index f150fc5..4e363cf 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -127,14 +127,14 @@ Page({ score: res.data.score, levelName: res.data.levelName, }) - if (res.data.nickName || res.data.phone){ + if (res.data.nickName){ that.setData({ ismember:true, memberId: res.data.id }) var size = this.setCanvasSize(); var initUrl = JSON.stringify({flagid:res.data.id}); - this.createQrCode(initUrl, "mycanvas1", size.w, size.h); + that.createQrCode(initUrl, "mycanvas1", size.w, size.h); } }) .catch(err => {