C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

241 Zeilen
5.7 KiB

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