C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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