C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

238 řádky
5.7 KiB

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