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

227 行
5.3 KiB

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