C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

157 Zeilen
3.7 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: 0
  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. let that = this;
  48. that.ifPhoneInfo()
  49. that.setData({
  50. goHomeUrl: app.globalData.goHomeUrl,
  51. })
  52. console.log("渲染开始")
  53. that.getDiscountInfo()
  54. },
  55. refreshCode() {
  56. this.setData({
  57. showCode: true
  58. })
  59. this.getDiscountInfo()
  60. },
  61. getDiscountInfo() {
  62. let that = this;
  63. Http.get({
  64. url: config.api.getDiscountInfo,
  65. })
  66. .then(res => {
  67. that.setData({
  68. level: res.data.level ? res.data.level : ''
  69. })
  70. that.qrcode(res.data.dynamicId);
  71. that.setData({
  72. memberId: res.data.id,
  73. expiredSeconds: res.data.expiredSeconds,
  74. })
  75. let discountMerchantList = [];
  76. res.data.levelMerchantList.map(file => {
  77. if (file.discount != 100) {
  78. discountMerchantList.push(file);
  79. }
  80. })
  81. that.setData({
  82. discountMerchantList: discountMerchantList,
  83. })
  84. if (that.data.expiredSeconds * 1) {
  85. const timer = setInterval(() => {
  86. const expiredSeconds = that.data.expiredSeconds
  87. if (expiredSeconds) {
  88. that.setData({
  89. expiredSeconds: expiredSeconds - 1,
  90. })
  91. } else {
  92. clearInterval(timer)
  93. that.setData({
  94. showCode: false,
  95. })
  96. }
  97. }, 1000);
  98. }
  99. }).catch(err => {
  100. console.log(err, 'err');
  101. wx.showToast({
  102. title: err.message,
  103. })
  104. })
  105. },
  106. goback: function () {
  107. let this_ = this
  108. wx.switchTab({
  109. url: this_.data.goHomeUrl,
  110. })
  111. },
  112. /**
  113. * 二维码
  114. */
  115. qrcode(memberId) {
  116. let that = this;
  117. var size = that.setCanvasSize();
  118. let url = JSON.stringify({
  119. END: "C",
  120. TYPE: "memberCode",
  121. ID: memberId,
  122. });
  123. that.createQrCode(url, "mycanvas2", size.w, size.h);
  124. },
  125. createQrCode: function (url, canvasId, cavW, cavH) {
  126. //调用插件中的draw方法,绘制二维码图片
  127. let that = this;
  128. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  129. that.setData({
  130. tempFilePath: res
  131. })
  132. });
  133. },
  134. //适配不同屏幕大小的canvas
  135. setCanvasSize: function () {
  136. var size = {};
  137. try {
  138. var res = wx.getSystemInfoSync();
  139. var scale = 750 / 400;
  140. //不同屏幕下canvas的适配比例;设计稿是750宽
  141. var width = res.windowWidth / scale;
  142. var height = width;
  143. //canvas画布为正方形
  144. size.w = width;
  145. size.h = height;
  146. } catch (e) {
  147. // Do something when catch error
  148. console.log("获取设备信息失败" + e);
  149. }
  150. return size;
  151. },
  152. })