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.

209 regels
4.9 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  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. bannerUrl: imgurl.banner.url,
  13. redirectUrl: imgurl.redirect.url,
  14. qrcodeUrl: imgurl.qrcode.url,
  15. editUrl: imgurl.edit.url,
  16. activeUrl: imgurl.active.url,
  17. dingUrl: imgurl.ding.url,
  18. quansUrl: imgurl.quans.url,
  19. wmintegral: imgurl.wmintegral.url,
  20. cardiconUrl: imgurl.cardicon.url,
  21. cheUrl: imgurl.che.url,
  22. giftUrl: imgurl.gift.url,
  23. wmbarginicon: imgurl.wmbarginicon.url,
  24. wmspellgroup: imgurl.wmspellgroup.url,
  25. canIUse: wx.canIUse('official-account'),
  26. flag: 'hidden',
  27. score:'0',
  28. name:"",
  29. birthdate:"",
  30. sex:"",
  31. showEdit:false,
  32. ismember:false,
  33. showQrcode:false,
  34. canvasHidden: false,
  35. maskHidden: true,
  36. imagePath: '',
  37. appVersion:"",
  38. showmemberqrcode: false,
  39. placeholder: ''
  40. },
  41. /**
  42. * 跳转到成长值的页面
  43. */
  44. gotograde:function(){
  45. wx.navigateTo({
  46. url: '/pages/czdetail/czdetail',
  47. })
  48. },
  49. navigateTo() {
  50. wx.navigateTo({
  51. url: `/pages/main/index`
  52. });
  53. },
  54. showVersion: function() {
  55. /**
  56. * 长按显示版本号
  57. */
  58. let that = this;
  59. if (that.data.flag == 'hidden') {
  60. that.setData({
  61. flag: 'show'
  62. });
  63. }
  64. },
  65. gotoedit:function(){
  66. wx.navigateTo({
  67. url: '/pages/edit/edit',
  68. })
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function() {
  74. let that = this;
  75. that.setData({
  76. appVersion: extConfig.appVersion
  77. })
  78. /**
  79. * couponNum
  80. * couponNum2
  81. */
  82. let num = wx.getStorageSync('couponNum');
  83. let num1 = wx.getStorageSync('couponNum2');
  84. wx.hideTabBarRedDot({
  85. index: 3
  86. });
  87. wx.hideTabBarRedDot({
  88. index: 3
  89. });
  90. if (num == 'couponNum1') {
  91. wx.setStorage({
  92. key: 'couponNum',
  93. data: "couponNum1",
  94. })
  95. that.setData({
  96. couponNum: "couponNum1"
  97. })
  98. } else if (num == 'couponNum') {
  99. that.setData({
  100. couponNum: "couponNum"
  101. })
  102. };
  103. if (num1 == 'couponNum3') {
  104. wx.setStorage({
  105. key: 'couponNum2',
  106. data: "couponNum3",
  107. })
  108. that.setData({
  109. couponNum2: "couponNum3"
  110. })
  111. } else if (num1 == 'couponNum2') {
  112. that.setData({
  113. couponNum2: "couponNum2"
  114. })
  115. };
  116. Http.get({
  117. url: config.api.getScore,
  118. data: {}
  119. }).then(res=>{
  120. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  121. that.setData({
  122. showEdit:true
  123. })
  124. }
  125. that.setData({
  126. score: res.data.score,
  127. levelName: res.data.levelName,
  128. })
  129. if (res.data.nickName){
  130. that.setData({
  131. ismember:true,
  132. memberId: res.data.id
  133. })
  134. var size = this.setCanvasSize();
  135. var initUrl = JSON.stringify({flagid:res.data.id});
  136. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  137. }
  138. })
  139. .catch(err => {
  140. wx.showModal({
  141. title: '提示',
  142. content: err.errMsg,
  143. showCancel:false
  144. })
  145. })
  146. //暂时注释
  147. // that.getrun();
  148. },
  149. hideQrcode:function(){
  150. let that = this;
  151. that.setData({
  152. showQrcode: false
  153. })
  154. },
  155. //适配不同屏幕大小的canvas
  156. setCanvasSize: function () {
  157. var size = {};
  158. try {
  159. var res = wx.getSystemInfoSync();
  160. var scale = 750 / 500;
  161. //不同屏幕下canvas的适配比例;设计稿是750宽
  162. var width = res.windowWidth / scale;
  163. var height = width;
  164. //canvas画布为正方形
  165. size.w = width;
  166. size.h = height;
  167. } catch (e) {
  168. // Do something when catch error
  169. console.log("获取设备信息失败" + e);
  170. }
  171. return size;
  172. },
  173. createQrCode: function (url, canvasId, cavW, cavH) {
  174. //调用插件中的draw方法,绘制二维码图片
  175. QR.api.draw(url, canvasId, cavW, cavH);
  176. },
  177. qrcode: function (e) {
  178. var that = this;
  179. that.setData({
  180. showQrcode:true
  181. })
  182. wx.showToast({
  183. title: '生成中...',
  184. icon: 'loading',
  185. duration: 2000
  186. });
  187. var st = setTimeout(function () {
  188. wx.hideToast()
  189. var size = that.setCanvasSize();
  190. var url = JSON.stringify({
  191. END:"C",
  192. TYPE:"memberCode",
  193. ID: that.data.memberId,
  194. })
  195. that.createQrCode(url, "mycanvas1", size.w, size.h);
  196. that.setData({
  197. maskHidden: true
  198. });
  199. clearTimeout(st);
  200. }, 1000)
  201. },
  202. close: function () {
  203. this.setData({
  204. showmemberqrcode: false,
  205. })
  206. }
  207. });