|
- const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
- let appVersion;
- if (Object.keys(extConfig).length == 0) {
- appVersion = 'C.3.3.8';
- }
- 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,
- cardiconUrl: imgurl.cardicon.url,
- cheUrl: imgurl.che.url,
- giftUrl: imgurl.gift.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',
- })
- },
- // getrun:function(){
- // let that = this;
- // wx.getWeRunData({
- // success: function (res) {
- // Http.post({
- // url: config.api.getWeRunData,
- // data: {
- // encryptedData: res.encryptedData,
- // iv: res.iv
- // }
- // }).then(res => {
- // that.setData({
- // step: res.data.stepInfoList[30].step
- // })
- // })
- // }
- // })
- // },
- /**
- *
- */
- // getxinghao:function(){
- // wx.getSystemInfo({
- // success:function(res){
- // wx.showModal({
- // content: res.brand,
- // })
- // }
- // })
- // },
- 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',
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- let that = this;
- that.setData({
- appVersion: extConfig.appVersion ? extConfig.appVersion : appVersion
- })
- let num = wx.getStorageSync('couponNum');
- let num1 = wx.getStorageSync('couponNum2');
- wx.hideTabBarRedDot({
- index: 2
- });
- 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,
- })
- }
- });
|