C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

228 linhas
5.4 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. wx.getScreenBrightness({
  90. success: function (res) {
  91. console.log(res)
  92. that.setData({
  93. ScreenBrightness: res.value
  94. })
  95. }
  96. })
  97. let num = wx.getStorageSync('couponNum');
  98. wx.hideTabBarRedDot({
  99. index: 2
  100. });
  101. if (num == 'couponNum1') {
  102. wx.setStorage({
  103. key: 'couponNum',
  104. data: "couponNum1",
  105. })
  106. that.setData({
  107. couponNum: "couponNum1"
  108. })
  109. } else if (num == 'couponNum') {
  110. that.setData({
  111. couponNum: "couponNum"
  112. })
  113. };
  114. Http.get({
  115. url: config.api.getScore,
  116. data: {}
  117. }).then(res=>{
  118. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  119. that.setData({
  120. showEdit:true
  121. })
  122. }
  123. that.setData({
  124. score: res.data.score,
  125. levelName: res.data.levelName,
  126. })
  127. if (res.data.nickName || res.data.phone){
  128. that.setData({
  129. ismember:true,
  130. memberId: res.data.id
  131. })
  132. var size = this.setCanvasSize();
  133. var initUrl = res.data.id;
  134. console.log(initUrl)
  135. this.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  136. }
  137. })
  138. .catch(err => {
  139. wx.showToast({
  140. title: err.errMsg,
  141. icon: 'none',
  142. duration: 2000,
  143. mask: false
  144. });
  145. })
  146. // that.getrun();
  147. },
  148. hideQrcode:function(){
  149. let that = this;
  150. that.setData({
  151. showQrcode: false
  152. }),
  153. wx.setScreenBrightness({
  154. value: that.data.ScreenBrightness
  155. })
  156. },
  157. //适配不同屏幕大小的canvas
  158. setCanvasSize: function () {
  159. var size = {};
  160. try {
  161. var res = wx.getSystemInfoSync();
  162. var scale = 750 / 500;//不同屏幕下canvas的适配比例;设计稿是750宽
  163. var width = res.windowWidth / scale;
  164. var height = width;//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. // setTimeout(() => { this.canvasToTempImage(); }, 1000);
  177. },
  178. //点击图片进行预览,长按保存分享图片
  179. previewImg: function (e) {
  180. var img = this.data.imagePath;
  181. console.log(img);
  182. wx.previewImage({
  183. current: img, // 当前显示图片的http链接
  184. urls: [img] // 需要预览的图片http链接列表
  185. })
  186. },
  187. qrcode: function (e) {
  188. var that = this;
  189. // if (that.data.ScreenBrightness>0.8){
  190. // wx.setScreenBrightness({
  191. // value: that.data.ScreenBrightness
  192. // })
  193. // }else{
  194. // wx.setScreenBrightness({
  195. // value: 0.8
  196. // })
  197. // }
  198. that.setData({
  199. showQrcode:true
  200. })
  201. wx.showToast({
  202. title: '生成中...',
  203. icon: 'loading',
  204. duration: 2000
  205. });
  206. var st = setTimeout(function () {
  207. wx.hideToast()
  208. var size = that.setCanvasSize();
  209. var url = that.data.memberId;
  210. that.createQrCode(url, "mycanvas1", size.w, size.h);
  211. that.setData({
  212. maskHidden: true
  213. });
  214. clearTimeout(st);
  215. }, 1000)
  216. },
  217. // onUnload:function(){
  218. // wx.setScreenBrightness({
  219. // value: that.data.ScreenBrightness
  220. // })
  221. // },
  222. // onHide:function(){
  223. // wx.setScreenBrightness({
  224. // value: that.data.ScreenBrightness
  225. // })
  226. // }
  227. });