C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 regels
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. bannerUrl: wx.getStorageSync('imgurl').banner.url,
  11. redirectUrl: wx.getStorageSync('imgurl').redirect.url,
  12. qrcodeUrl: wx.getStorageSync('imgurl').qrcode.url,
  13. editUrl: wx.getStorageSync('imgurl').edit.url,
  14. activeUrl: wx.getStorageSync('imgurl').active.url,
  15. dingUrl: wx.getStorageSync('imgurl').ding.url,
  16. quansUrl: wx.getStorageSync('imgurl').quans.url,
  17. cardiconUrl: wx.getStorageSync('imgurl').cardicon.url,
  18. cheUrl: wx.getStorageSync('imgurl').che.url,
  19. giftUrl: wx.getStorageSync('imgurl').gift.url,
  20. canIUse: wx.canIUse('official-account'),
  21. flag: 'hidden',
  22. score:'0',
  23. name:"",
  24. birthdate:"",
  25. sex:"",
  26. showEdit:false,
  27. ismember:false,
  28. showQrcode:false,
  29. canvasHidden: false,
  30. maskHidden: true,
  31. imagePath: '',
  32. showmemberqrcode: false,
  33. placeholder: ''//默认二维码生成文本
  34. },
  35. /**
  36. * 跳转到成长值的页面
  37. */
  38. gotograde:function(){
  39. wx.navigateTo({
  40. url: '/pages/grade/grade',
  41. })
  42. },
  43. // getrun:function(){
  44. // let that = this;
  45. // wx.getWeRunData({
  46. // success: function (res) {
  47. // Http.post({
  48. // url: config.api.getWeRunData,
  49. // data: {
  50. // encryptedData: res.encryptedData,
  51. // iv: res.iv
  52. // }
  53. // }).then(res => {
  54. // that.setData({
  55. // step: res.data.stepInfoList[30].step
  56. // })
  57. // })
  58. // }
  59. // })
  60. // },
  61. /**
  62. *
  63. */
  64. // getxinghao:function(){
  65. // wx.getSystemInfo({
  66. // success:function(res){
  67. // wx.showModal({
  68. // content: res.brand,
  69. // })
  70. // }
  71. // })
  72. // },
  73. navigateTo() {
  74. wx.navigateTo({
  75. url: `/pages/login/index`
  76. });
  77. },
  78. showVersion: function() {
  79. /**
  80. * 长按显示版本号
  81. */
  82. let that = this;
  83. if (that.data.flag == 'hidden') {
  84. that.setData({
  85. flag: 'show'
  86. });
  87. }
  88. },
  89. gotoedit:function(){
  90. wx.navigateTo({
  91. url: '/pages/edit/edit',
  92. })
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function() {
  98. let that = this;
  99. let num = wx.getStorageSync('couponNum');
  100. wx.hideTabBarRedDot({
  101. index: 2
  102. });
  103. if (num == 'couponNum1') {
  104. wx.setStorage({
  105. key: 'couponNum',
  106. data: "couponNum1",
  107. })
  108. that.setData({
  109. couponNum: "couponNum1"
  110. })
  111. } else if (num == 'couponNum') {
  112. that.setData({
  113. couponNum: "couponNum"
  114. })
  115. };
  116. Http.get({
  117. url: config.api.getScore,
  118. data: {}
  119. }).then(res=>{
  120. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  121. that.setData({
  122. showEdit:true
  123. })
  124. }
  125. that.setData({
  126. score: res.data.score,
  127. levelName: res.data.levelName,
  128. })
  129. if (res.data.nickName || res.data.phone){
  130. that.setData({
  131. ismember:true,
  132. memberId: res.data.id
  133. })
  134. var size = this.setCanvasSize();
  135. var initUrl = JSON.stringify({flagid:res.data.id});
  136. this.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  137. }
  138. })
  139. .catch(err => {
  140. wx.showModal({
  141. title: '提示',
  142. content: err.errMsg,
  143. showCancel:false
  144. })
  145. })
  146. //暂时注释
  147. // that.getrun();
  148. // 判断是否显示特享礼遇
  149. Http.get({
  150. url: config.api.scoreLevelInfo,
  151. data: {}
  152. })
  153. .then(res=>{
  154. // if true 则开启特享礼遇
  155. if (res.data.discountEnable){
  156. that.setData({
  157. discountEnable:true
  158. })
  159. }
  160. else{
  161. that.setData({
  162. discountEnable: false
  163. })
  164. }
  165. })
  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({ flagid:that.data.memberId});
  209. that.createQrCode(url, "mycanvas1", size.w, size.h);
  210. that.setData({
  211. maskHidden: true
  212. });
  213. clearTimeout(st);
  214. }, 1000)
  215. },
  216. close: function () {
  217. this.setData({
  218. showmemberqrcode: false,
  219. })
  220. }
  221. });