C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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