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

235 行
5.6 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. var config = require("../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../utils/HttpBasics");
  5. const QR = require("../../utils/memberqrcode.js");
  6. const imgurl = require("../../utils/imgurl");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. bannerUrl: imgurl.banner.url,
  13. redirectUrl: imgurl.redirect.url,
  14. qrcodeUrl: imgurl.qrcode.url,
  15. editUrl: imgurl.edit.url,
  16. activeUrl: imgurl.active.url,
  17. dingUrl: imgurl.ding.url,
  18. quansUrl: imgurl.quans.url,
  19. wmintegral: imgurl.wmintegral.url,
  20. cardiconUrl: imgurl.cardicon.url,
  21. cheUrl: imgurl.che.url,
  22. giftUrl: imgurl.gift.url,
  23. wmbarginicon: imgurl.wmbarginicon.url,
  24. wmspellgroup: imgurl.wmspellgroup.url,
  25. canIUse: wx.canIUse('official-account'),
  26. flag: 'hidden',
  27. score:'0',
  28. name:"",
  29. birthdate:"",
  30. sex:"",
  31. showEdit:false,
  32. ismember:false,
  33. showQrcode:false,
  34. canvasHidden: false,
  35. maskHidden: true,
  36. imagePath: '',
  37. appVersion:"",
  38. showmemberqrcode: false,
  39. placeholder: ''//默认二维码生成文本
  40. },
  41. /**
  42. * 跳转到成长值的页面
  43. */
  44. gotograde:function(){
  45. wx.navigateTo({
  46. url: '/pages/czdetail/czdetail',
  47. })
  48. },
  49. // getrun:function(){
  50. // let that = this;
  51. // wx.getWeRunData({
  52. // success: function (res) {
  53. // Http.post({
  54. // url: config.api.getWeRunData,
  55. // data: {
  56. // encryptedData: res.encryptedData,
  57. // iv: res.iv
  58. // }
  59. // }).then(res => {
  60. // that.setData({
  61. // step: res.data.stepInfoList[30].step
  62. // })
  63. // })
  64. // }
  65. // })
  66. // },
  67. /**
  68. *
  69. */
  70. // getxinghao:function(){
  71. // wx.getSystemInfo({
  72. // success:function(res){
  73. // wx.showModal({
  74. // content: res.brand,
  75. // })
  76. // }
  77. // })
  78. // },
  79. navigateTo() {
  80. wx.navigateTo({
  81. url: `/pages/main/index`
  82. });
  83. },
  84. showVersion: function() {
  85. /**
  86. * 长按显示版本号
  87. */
  88. let that = this;
  89. if (that.data.flag == 'hidden') {
  90. that.setData({
  91. flag: 'show'
  92. });
  93. }
  94. },
  95. gotoedit:function(){
  96. wx.navigateTo({
  97. url: '/pages/edit/edit',
  98. })
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow: function() {
  104. let that = this;
  105. that.setData({
  106. appVersion: extConfig.appVersion
  107. })
  108. let num = wx.getStorageSync('couponNum');
  109. let num1 = wx.getStorageSync('couponNum2');
  110. wx.hideTabBarRedDot({
  111. index: 2
  112. });
  113. wx.hideTabBarRedDot({
  114. index: 3
  115. });
  116. if (num == 'couponNum1') {
  117. wx.setStorage({
  118. key: 'couponNum',
  119. data: "couponNum1",
  120. })
  121. that.setData({
  122. couponNum: "couponNum1"
  123. })
  124. } else if (num == 'couponNum') {
  125. that.setData({
  126. couponNum: "couponNum"
  127. })
  128. };
  129. if (num1 == 'couponNum3') {
  130. wx.setStorage({
  131. key: 'couponNum2',
  132. data: "couponNum3",
  133. })
  134. that.setData({
  135. couponNum2: "couponNum3"
  136. })
  137. } else if (num1 == 'couponNum2') {
  138. that.setData({
  139. couponNum2: "couponNum2"
  140. })
  141. };
  142. Http.get({
  143. url: config.api.getScore,
  144. data: {}
  145. }).then(res=>{
  146. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate){
  147. that.setData({
  148. showEdit:true
  149. })
  150. }
  151. that.setData({
  152. score: res.data.score,
  153. levelName: res.data.levelName,
  154. })
  155. if (res.data.nickName){
  156. that.setData({
  157. ismember:true,
  158. memberId: res.data.id
  159. })
  160. var size = this.setCanvasSize();
  161. var initUrl = JSON.stringify({flagid:res.data.id});
  162. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  163. }
  164. })
  165. .catch(err => {
  166. wx.showModal({
  167. title: '提示',
  168. content: err.errMsg,
  169. showCancel:false
  170. })
  171. })
  172. //暂时注释
  173. // that.getrun();
  174. },
  175. hideQrcode:function(){
  176. let that = this;
  177. that.setData({
  178. showQrcode: false
  179. })
  180. },
  181. //适配不同屏幕大小的canvas
  182. setCanvasSize: function () {
  183. var size = {};
  184. try {
  185. var res = wx.getSystemInfoSync();
  186. var scale = 750 / 500;
  187. //不同屏幕下canvas的适配比例;设计稿是750宽
  188. var width = res.windowWidth / scale;
  189. var height = width;
  190. //canvas画布为正方形
  191. size.w = width;
  192. size.h = height;
  193. } catch (e) {
  194. // Do something when catch error
  195. console.log("获取设备信息失败" + e);
  196. }
  197. return size;
  198. },
  199. createQrCode: function (url, canvasId, cavW, cavH) {
  200. //调用插件中的draw方法,绘制二维码图片
  201. QR.api.draw(url, canvasId, cavW, cavH);
  202. },
  203. qrcode: function (e) {
  204. var that = this;
  205. that.setData({
  206. showQrcode:true
  207. })
  208. wx.showToast({
  209. title: '生成中...',
  210. icon: 'loading',
  211. duration: 2000
  212. });
  213. var st = setTimeout(function () {
  214. wx.hideToast()
  215. var size = that.setCanvasSize();
  216. var url = JSON.stringify({
  217. END:"C",
  218. TYPE:"memberCode",
  219. ID: that.data.memberId,
  220. })
  221. that.createQrCode(url, "mycanvas1", size.w, size.h);
  222. that.setData({
  223. maskHidden: true
  224. });
  225. clearTimeout(st);
  226. }, 1000)
  227. },
  228. close: function () {
  229. this.setData({
  230. showmemberqrcode: false,
  231. })
  232. }
  233. });