|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- const app = getApp()
- const navigationBarHeight = (getApp().statusBarHeight + 50) + "px"
- const Http = require("../../utils/HttpBasics");
- const config = require("../../config/config");
- const QR = require("../../utils/memberqrcode.js");
- Page({
- data: {
- navigationBarHeight,
- memberId:"",
- level:""
- },
- getUserData(){
- Http.get({
- url:config.api.getDiscountInfo
- }).then(res=>{
- console.log(res.data);
- this.setData({
- memberId:res.data.id,
- level:res.data.level
- })
- this.qrcode(res.data.id);
- }).catch(err => {
- tt.showToast({
- title: err.errMsg,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- onLoad: function (options) {
- this.getUserData()
- },
-
- qrcode: function (memberId){
- let that = this;
- var size = that.setCanvasSize();
- let url = JSON.stringify({
- END: "C",
- TYPE: "memberCode",
- ID: memberId,
- });
- that.createQrCode(url, "mycanvas2", 250, 250);
- },
- createQrCode: function (url, canvasId, cavW, cavH) {
- //调用插件中的draw方法,绘制二维码图片
- let that = this;
- QR.api.draw(url, canvasId, cavW, cavH,function(res){
- that.setData({
- tempFilePath: res
- })
- });
- },
- //适配不同屏幕大小的canvas
- setCanvasSize: function () {
- var size = {};
- try {
- var res = tt.getSystemInfoSync();
- var scale = 750 / 400;
- //不同屏幕下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;
- },
- })
|