C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

214 行
4.9 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 = JSON.stringify({flagid:res.data.id});
  126. this.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  127. }
  128. })
  129. .catch(err => {
  130. wx.showToast({
  131. title: err.errMsg,
  132. icon: 'none',
  133. duration: 2000,
  134. mask: false
  135. });
  136. })
  137. //暂时注释
  138. // that.getrun();
  139. // 判断是否显示特享礼遇
  140. Http.get({
  141. url: config.api.scoreLevelInfo,
  142. data: {}
  143. })
  144. .then(res=>{
  145. // if true 则开启特享礼遇
  146. if (res.data.discountEnable){
  147. that.setData({
  148. discountEnable:true
  149. })
  150. }
  151. else{
  152. that.setData({
  153. discountEnable: false
  154. })
  155. }
  156. })
  157. },
  158. hideQrcode:function(){
  159. let that = this;
  160. that.setData({
  161. showQrcode: false
  162. })
  163. },
  164. //适配不同屏幕大小的canvas
  165. setCanvasSize: function () {
  166. var size = {};
  167. try {
  168. var res = wx.getSystemInfoSync();
  169. var scale = 750 / 500;
  170. //不同屏幕下canvas的适配比例;设计稿是750宽
  171. var width = res.windowWidth / scale;
  172. var height = width;
  173. //canvas画布为正方形
  174. size.w = width;
  175. size.h = height;
  176. } catch (e) {
  177. // Do something when catch error
  178. console.log("获取设备信息失败" + e);
  179. }
  180. return size;
  181. },
  182. createQrCode: function (url, canvasId, cavW, cavH) {
  183. //调用插件中的draw方法,绘制二维码图片
  184. QR.api.draw(url, canvasId, cavW, cavH);
  185. },
  186. qrcode: function (e) {
  187. var that = this;
  188. that.setData({
  189. showQrcode:true
  190. })
  191. wx.showToast({
  192. title: '生成中...',
  193. icon: 'loading',
  194. duration: 2000
  195. });
  196. var st = setTimeout(function () {
  197. wx.hideToast()
  198. var size = that.setCanvasSize();
  199. var url = JSON.stringify({ flagid:that.data.memberId});
  200. that.createQrCode(url, "mycanvas1", size.w, size.h);
  201. that.setData({
  202. maskHidden: true
  203. });
  204. clearTimeout(st);
  205. }, 1000)
  206. },
  207. close: function () {
  208. this.setData({
  209. showmemberqrcode: false,
  210. })
  211. }
  212. });