C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.0 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
  2. var config = require("../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../utils/HttpBasics");
  5. const QR = require("../../utils/memberqrcode.js");
  6. const imgurl = require("../../utils/imgurl");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navigationBarHeight,
  13. myspeacialUrl: imgurl.myspeacial.url,
  14. teliconUrl: imgurl.telicon.url,
  15. wmhome: imgurl.wmhome.url,
  16. memberId: "000000",
  17. goHomeUrl: "",
  18. showCode: true,
  19. showTimeLine: true,
  20. expiredSeconds: 30
  21. },
  22. phone: function (e) {
  23. console.log(e)
  24. let that = this;
  25. wx.makePhoneCall({
  26. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  27. });
  28. },
  29. //是否授权手机号
  30. ifPhoneInfo() {
  31. let that = this;
  32. Http.get({
  33. url: config.api.checkPhoneStatus,
  34. data: {}
  35. }).then(res => {
  36. return
  37. }).catch(err => {
  38. wx.navigateTo({
  39. url: `/pages/getphoneInfo/index?mineFlag=index`,
  40. })
  41. })
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. this.ifPhoneInfo()
  48. let that = this;
  49. that.setData({
  50. goHomeUrl: app.globalData.goHomeUrl,
  51. })
  52. console.log("渲染开始")
  53. Http.get({
  54. url: config.api.getDiscountInfo,
  55. data: {}
  56. })
  57. .then(res => {
  58. that.setData({
  59. level: res.data.level ? res.data.level : ''
  60. })
  61. that.qrcode(res.data.id);
  62. that.setData({
  63. memberId: res.data.id
  64. })
  65. console.log(res.data.levelMerchantList)
  66. let discountMerchantList = [];
  67. res.data.levelMerchantList.map(file => {
  68. if (file.discount != 100) {
  69. discountMerchantList.push(file);
  70. }
  71. })
  72. that.setData({
  73. discountMerchantList: discountMerchantList,
  74. })
  75. })
  76. },
  77. goback: function () {
  78. let this_ = this
  79. wx.switchTab({
  80. url: this_.data.goHomeUrl,
  81. })
  82. },
  83. /**
  84. * 二维码
  85. */
  86. qrcode: function (memberId) {
  87. let that = this;
  88. var size = that.setCanvasSize();
  89. let url = JSON.stringify({
  90. END: "C",
  91. TYPE: "memberCode",
  92. ID: memberId,
  93. });
  94. that.createQrCode(url, "mycanvas2", size.w, size.h);
  95. },
  96. createQrCode: function (url, canvasId, cavW, cavH) {
  97. //调用插件中的draw方法,绘制二维码图片
  98. let that = this;
  99. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  100. that.setData({
  101. tempFilePath: res
  102. })
  103. });
  104. },
  105. //适配不同屏幕大小的canvas
  106. setCanvasSize: function () {
  107. var size = {};
  108. try {
  109. var res = wx.getSystemInfoSync();
  110. var scale = 750 / 400;
  111. //不同屏幕下canvas的适配比例;设计稿是750宽
  112. var width = res.windowWidth / scale;
  113. var height = width;
  114. //canvas画布为正方形
  115. size.w = width;
  116. size.h = height;
  117. } catch (e) {
  118. // Do something when catch error
  119. console.log("获取设备信息失败" + e);
  120. }
  121. return size;
  122. },
  123. })