C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

240 linhas
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. navigateTo() {
  50. wx.navigateTo({
  51. url: `/pages/main/index`
  52. });
  53. },
  54. showVersion: function() {
  55. /**
  56. * 长按显示版本号
  57. */
  58. let that = this;
  59. if (that.data.flag == 'hidden') {
  60. that.setData({
  61. flag: 'show'
  62. });
  63. }
  64. },
  65. gotoedit: function() {
  66. wx.navigateTo({
  67. url: '/pages/edit/edit',
  68. })
  69. },
  70. onLoad() {
  71. this.getLocation();
  72. },
  73. /**
  74. * 获得经纬度
  75. */
  76. getLocation() {
  77. let that = this;
  78. wx.getLocation({
  79. type: "wgs84",
  80. success: function(res) {
  81. console.log(res)
  82. if (res && res.longitude && res.latitude) {
  83. Http.post({
  84. url: config.api.updateLBS,
  85. data: {
  86. latitude: res.latitude,
  87. longitude: res.longitude
  88. }
  89. }).then(res => {
  90. console.log(res)
  91. })
  92. }
  93. },
  94. fail: error => {
  95. console.log(error);
  96. }
  97. })
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function() {
  103. let that = this;
  104. that.setData({
  105. appVersion: extConfig.appVersion
  106. })
  107. /**
  108. * couponNum
  109. * couponNum2
  110. */
  111. let num = wx.getStorageSync('couponNum');
  112. let num1 = wx.getStorageSync('couponNum2');
  113. wx.hideTabBarRedDot({
  114. index: 3
  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({
  165. flagid: res.data.id
  166. });
  167. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  168. }
  169. })
  170. .catch(err => {
  171. wx.showModal({
  172. title: '提示',
  173. content: err.errMsg,
  174. showCancel: false
  175. })
  176. })
  177. //暂时注释
  178. // that.getrun();
  179. },
  180. hideQrcode: function() {
  181. let that = this;
  182. that.setData({
  183. showQrcode: false
  184. })
  185. },
  186. //适配不同屏幕大小的canvas
  187. setCanvasSize: function() {
  188. var size = {};
  189. try {
  190. var res = wx.getSystemInfoSync();
  191. var scale = 750 / 500;
  192. //不同屏幕下canvas的适配比例;设计稿是750宽
  193. var width = res.windowWidth / scale;
  194. var height = width;
  195. //canvas画布为正方形
  196. size.w = width;
  197. size.h = height;
  198. } catch (e) {
  199. // Do something when catch error
  200. console.log("获取设备信息失败" + e);
  201. }
  202. return size;
  203. },
  204. createQrCode: function(url, canvasId, cavW, cavH) {
  205. //调用插件中的draw方法,绘制二维码图片
  206. QR.api.draw(url, canvasId, cavW, cavH);
  207. },
  208. qrcode: function(e) {
  209. var that = this;
  210. that.setData({
  211. showQrcode: true
  212. })
  213. wx.showToast({
  214. title: '生成中...',
  215. icon: 'loading',
  216. duration: 2000
  217. });
  218. var st = setTimeout(function() {
  219. wx.hideToast()
  220. var size = that.setCanvasSize();
  221. var url = JSON.stringify({
  222. END: "C",
  223. TYPE: "memberCode",
  224. ID: that.data.memberId,
  225. })
  226. that.createQrCode(url, "mycanvas1", size.w, size.h);
  227. that.setData({
  228. maskHidden: true
  229. });
  230. clearTimeout(st);
  231. }, 1000)
  232. },
  233. close: function() {
  234. this.setData({
  235. showmemberqrcode: false,
  236. })
  237. }
  238. });