C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

245 rader
5.7 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. Http.get({
  168. url: config.api.scoreLevelInfo,
  169. data: {}
  170. })
  171. .then(res=>{
  172. // if true 则开启特享礼遇
  173. if (res.data.discountEnable){
  174. that.setData({
  175. discountEnable:true
  176. })
  177. }
  178. else{
  179. that.setData({
  180. discountEnable: false
  181. })
  182. }
  183. })
  184. },
  185. hideQrcode:function(){
  186. let that = this;
  187. that.setData({
  188. showQrcode: false
  189. })
  190. },
  191. //适配不同屏幕大小的canvas
  192. setCanvasSize: function () {
  193. var size = {};
  194. try {
  195. var res = wx.getSystemInfoSync();
  196. var scale = 750 / 500;
  197. //不同屏幕下canvas的适配比例;设计稿是750宽
  198. var width = res.windowWidth / scale;
  199. var height = width;
  200. //canvas画布为正方形
  201. size.w = width;
  202. size.h = height;
  203. } catch (e) {
  204. // Do something when catch error
  205. console.log("获取设备信息失败" + e);
  206. }
  207. return size;
  208. },
  209. createQrCode: function (url, canvasId, cavW, cavH) {
  210. //调用插件中的draw方法,绘制二维码图片
  211. QR.api.draw(url, canvasId, cavW, cavH);
  212. },
  213. qrcode: function (e) {
  214. var that = this;
  215. that.setData({
  216. showQrcode:true
  217. })
  218. wx.showToast({
  219. title: '生成中...',
  220. icon: 'loading',
  221. duration: 2000
  222. });
  223. var st = setTimeout(function () {
  224. wx.hideToast()
  225. var size = that.setCanvasSize();
  226. var url = JSON.stringify({
  227. END:"C",
  228. TYPE:"memberCode",
  229. ID: that.data.memberId,
  230. })
  231. that.createQrCode(url, "mycanvas1", size.w, size.h);
  232. that.setData({
  233. maskHidden: true
  234. });
  235. clearTimeout(st);
  236. }, 1000)
  237. },
  238. close: function () {
  239. this.setData({
  240. showmemberqrcode: false,
  241. })
  242. }
  243. });