C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

274 satır
6.3 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. myactivitygift: imgurl.myactivitygift.url,
  22. myactivity: imgurl.myactivity.url,
  23. cheUrl: imgurl.che.url,
  24. giftUrl: imgurl.gift.url,
  25. wmbarginicon: imgurl.wmbarginicon.url,
  26. wmspellgroup: imgurl.wmspellgroup.url,
  27. canIUse: wx.canIUse('official-account'),
  28. flag: 'hidden',
  29. score: '0',
  30. name: "",
  31. birthdate: "",
  32. sex: "",
  33. showEdit: false,
  34. ismember: false,
  35. showQrcode: false,
  36. canvasHidden: false,
  37. maskHidden: true,
  38. imagePath: '',
  39. appVersion: "",
  40. showmemberqrcode: false,
  41. placeholder: ''
  42. },
  43. /**
  44. * 跳转到成长值的页面
  45. */
  46. gotograde: function() {
  47. wx.navigateTo({
  48. url: '/pages/czdetail/czdetail',
  49. })
  50. },
  51. navigateTo() {
  52. wx.navigateTo({
  53. url: `/pages/main/index`
  54. });
  55. },
  56. showVersion: function() {
  57. /**
  58. * 长按显示版本号
  59. */
  60. let that = this;
  61. if (that.data.flag == 'hidden') {
  62. that.setData({
  63. flag: 'show'
  64. });
  65. }
  66. },
  67. gotoedit: function() {
  68. wx.navigateTo({
  69. url: '/pages/edit/edit',
  70. })
  71. },
  72. onLoad() {
  73. this.getLocation();
  74. this.updateUserInfo();
  75. this.updateScene();
  76. },
  77. /**
  78. * 获得经纬度
  79. */
  80. getLocation() {
  81. let that = this;
  82. wx.getLocation({
  83. type: "wgs84",
  84. success: function(res) {
  85. console.log(res)
  86. if (res && res.longitude && res.latitude) {
  87. Http.post({
  88. url: config.api.updateLBS,
  89. data: {
  90. latitude: res.latitude,
  91. longitude: res.longitude
  92. }
  93. }).then(res => {
  94. console.log(res)
  95. })
  96. }
  97. },
  98. fail: error => {
  99. console.log(error);
  100. }
  101. })
  102. },
  103. /**
  104. * 获取手机信息
  105. */
  106. updateUserInfo() {
  107. wx.getSystemInfo({
  108. success: function(res) {
  109. Http.post({
  110. url: config.api.updateUserInfo,
  111. data: {
  112. systemInfo: JSON.stringify(res)
  113. }
  114. }).then(res => {
  115. console.log(res)
  116. })
  117. }
  118. })
  119. },
  120. /**
  121. * 用户更新scene
  122. */
  123. updateScene(){
  124. Http.post({
  125. url: config.api.updateScene,
  126. data: {
  127. scene: app.globalData.scene
  128. }
  129. }).then(res => {
  130. console.log(res)
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面显示
  135. */
  136. onShow: function() {
  137. let that = this;
  138. that.setData({
  139. appVersion: extConfig.appVersion
  140. })
  141. /**
  142. * couponNum
  143. * couponNum2
  144. */
  145. let num = wx.getStorageSync('couponNum');
  146. let num1 = wx.getStorageSync('couponNum2');
  147. wx.hideTabBarRedDot({
  148. index: 3
  149. });
  150. wx.hideTabBarRedDot({
  151. index: 3
  152. });
  153. if (num == 'couponNum1') {
  154. wx.setStorage({
  155. key: 'couponNum',
  156. data: "couponNum1",
  157. })
  158. that.setData({
  159. couponNum: "couponNum1"
  160. })
  161. } else if (num == 'couponNum') {
  162. that.setData({
  163. couponNum: "couponNum"
  164. })
  165. };
  166. if (num1 == 'couponNum3') {
  167. wx.setStorage({
  168. key: 'couponNum2',
  169. data: "couponNum3",
  170. })
  171. that.setData({
  172. couponNum2: "couponNum3"
  173. })
  174. } else if (num1 == 'couponNum2') {
  175. that.setData({
  176. couponNum2: "couponNum2"
  177. })
  178. };
  179. Http.get({
  180. url: config.api.getScore,
  181. data: {}
  182. }).then(res => {
  183. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  184. that.setData({
  185. showEdit: true
  186. })
  187. }
  188. that.setData({
  189. score: res.data.score,
  190. levelName: res.data.levelName,
  191. })
  192. if (res.data.nickName) {
  193. that.setData({
  194. ismember: true,
  195. memberId: res.data.id
  196. })
  197. var size = this.setCanvasSize();
  198. var initUrl = JSON.stringify({
  199. flagid: res.data.id
  200. });
  201. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  202. }
  203. })
  204. .catch(err => {
  205. wx.showModal({
  206. title: '提示',
  207. content: err.errMsg,
  208. showCancel: false
  209. })
  210. })
  211. //暂时注释
  212. // that.getrun();
  213. },
  214. hideQrcode: function() {
  215. let that = this;
  216. that.setData({
  217. showQrcode: false
  218. })
  219. },
  220. //适配不同屏幕大小的canvas
  221. setCanvasSize: function() {
  222. var size = {};
  223. try {
  224. var res = wx.getSystemInfoSync();
  225. var scale = 750 / 500;
  226. //不同屏幕下canvas的适配比例;设计稿是750宽
  227. var width = res.windowWidth / scale;
  228. var height = width;
  229. //canvas画布为正方形
  230. size.w = width;
  231. size.h = height;
  232. } catch (e) {
  233. // Do something when catch error
  234. console.log("获取设备信息失败" + e);
  235. }
  236. return size;
  237. },
  238. createQrCode: function(url, canvasId, cavW, cavH) {
  239. //调用插件中的draw方法,绘制二维码图片
  240. QR.api.draw(url, canvasId, cavW, cavH);
  241. },
  242. qrcode: function(e) {
  243. var that = this;
  244. that.setData({
  245. showQrcode: true
  246. })
  247. wx.showToast({
  248. title: '生成中...',
  249. icon: 'loading',
  250. duration: 2000
  251. });
  252. var st = setTimeout(function() {
  253. wx.hideToast()
  254. var size = that.setCanvasSize();
  255. var url = JSON.stringify({
  256. END: "C",
  257. TYPE: "memberCode",
  258. ID: that.data.memberId,
  259. })
  260. that.createQrCode(url, "mycanvas1", size.w, size.h);
  261. that.setData({
  262. maskHidden: true
  263. });
  264. clearTimeout(st);
  265. }, 1000)
  266. },
  267. close: function() {
  268. this.setData({
  269. showmemberqrcode: false,
  270. })
  271. }
  272. });