const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} var config = require("../../config/config.js"); var app = getApp(); const Http = require("../../utils/HttpBasics"); const QR = require("../../utils/memberqrcode.js"); const imgurl = require("../../utils/imgurl"); Page({ /** * 页面的初始数据 */ data: { bannerUrl: imgurl.banner.url, redirectUrl: imgurl.redirect.url, qrcodeUrl: imgurl.qrcode.url, editUrl: imgurl.edit.url, activeUrl: imgurl.active.url, dingUrl: imgurl.ding.url, quansUrl: imgurl.quans.url, wmintegral: imgurl.wmintegral.url, cardiconUrl: imgurl.cardicon.url, cheUrl: imgurl.che.url, giftUrl: imgurl.gift.url, wmbarginicon: imgurl.wmbarginicon.url, wmspellgroup: imgurl.wmspellgroup.url, canIUse: wx.canIUse('official-account'), flag: 'hidden', score: '0', name: "", birthdate: "", sex: "", showEdit: false, ismember: false, showQrcode: false, canvasHidden: false, maskHidden: true, imagePath: '', appVersion: "", showmemberqrcode: false, placeholder: '' }, /** * 跳转到成长值的页面 */ gotograde: function() { wx.navigateTo({ url: '/pages/czdetail/czdetail', }) }, navigateTo() { wx.navigateTo({ url: `/pages/main/index` }); }, showVersion: function() { /** * 长按显示版本号 */ let that = this; if (that.data.flag == 'hidden') { that.setData({ flag: 'show' }); } }, gotoedit: function() { wx.navigateTo({ url: '/pages/edit/edit', }) }, onLoad() { this.getLocation(); this.updateUserInfo(); }, /** * 获得经纬度 */ getLocation() { let that = this; wx.getLocation({ type: "wgs84", success: function(res) { console.log(res) if (res && res.longitude && res.latitude) { Http.post({ url: config.api.updateLBS, data: { latitude: res.latitude, longitude: res.longitude } }).then(res => { console.log(res) }) } }, fail: error => { console.log(error); } }) }, /** * 获取手机信息 */ updateUserInfo() { wx.getSystemInfo({ success: function(res) { Http.post({ url: config.api.updateUserInfo, data: { systemInfo: JSON.stringify(res) } }).then(res => { console.log(res) }) } }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { let that = this; that.setData({ appVersion: extConfig.appVersion }) /** * couponNum * couponNum2 */ let num = wx.getStorageSync('couponNum'); let num1 = wx.getStorageSync('couponNum2'); wx.hideTabBarRedDot({ index: 3 }); wx.hideTabBarRedDot({ index: 3 }); if (num == 'couponNum1') { wx.setStorage({ key: 'couponNum', data: "couponNum1", }) that.setData({ couponNum: "couponNum1" }) } else if (num == 'couponNum') { that.setData({ couponNum: "couponNum" }) }; if (num1 == 'couponNum3') { wx.setStorage({ key: 'couponNum2', data: "couponNum3", }) that.setData({ couponNum2: "couponNum3" }) } else if (num1 == 'couponNum2') { that.setData({ couponNum2: "couponNum2" }) }; Http.get({ url: config.api.getScore, data: {} }).then(res => { if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) { that.setData({ showEdit: true }) } that.setData({ score: res.data.score, levelName: res.data.levelName, }) 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.errMsg, showCancel: false }) }) //暂时注释 // that.getrun(); }, 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); }, qrcode: function(e) { var that = this; that.setData({ showQrcode: true }) wx.showToast({ title: '生成中...', icon: 'loading', duration: 2000 }); var st = setTimeout(function() { wx.hideToast() var size = that.setCanvasSize(); var url = JSON.stringify({ END: "C", TYPE: "memberCode", ID: that.data.memberId, }) that.createQrCode(url, "mycanvas1", size.w, size.h); that.setData({ maskHidden: true }); clearTimeout(st); }, 1000) }, close: function() { this.setData({ showmemberqrcode: false, }) } });