C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
5.9 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. this.updateScene();
  73. },
  74. /**
  75. * 获得经纬度
  76. */
  77. getLocation() {
  78. let that = this;
  79. wx.getLocation({
  80. type: "wgs84",
  81. success: function(res) {
  82. console.log(res)
  83. if (res && res.longitude && res.latitude) {
  84. Http.post({
  85. url: config.api.updateLBS,
  86. data: {
  87. latitude: res.latitude,
  88. longitude: res.longitude
  89. }
  90. }).then(res => {
  91. console.log(res)
  92. })
  93. }
  94. },
  95. fail: error => {
  96. console.log(error);
  97. }
  98. })
  99. },
  100. /**
  101. * 用户更新scene
  102. */
  103. updateScene(){
  104. Http.post({
  105. url: config.api.updateScene,
  106. data: {
  107. scene: app.globalData.scene
  108. }
  109. }).then(res => {
  110. console.log(res)
  111. })
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: function() {
  117. let that = this;
  118. that.setData({
  119. appVersion: extConfig.appVersion
  120. })
  121. /**
  122. * couponNum
  123. * couponNum2
  124. */
  125. let num = wx.getStorageSync('couponNum');
  126. let num1 = wx.getStorageSync('couponNum2');
  127. wx.hideTabBarRedDot({
  128. index: 3
  129. });
  130. wx.hideTabBarRedDot({
  131. index: 3
  132. });
  133. if (num == 'couponNum1') {
  134. wx.setStorage({
  135. key: 'couponNum',
  136. data: "couponNum1",
  137. })
  138. that.setData({
  139. couponNum: "couponNum1"
  140. })
  141. } else if (num == 'couponNum') {
  142. that.setData({
  143. couponNum: "couponNum"
  144. })
  145. };
  146. if (num1 == 'couponNum3') {
  147. wx.setStorage({
  148. key: 'couponNum2',
  149. data: "couponNum3",
  150. })
  151. that.setData({
  152. couponNum2: "couponNum3"
  153. })
  154. } else if (num1 == 'couponNum2') {
  155. that.setData({
  156. couponNum2: "couponNum2"
  157. })
  158. };
  159. Http.get({
  160. url: config.api.getScore,
  161. data: {}
  162. }).then(res => {
  163. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  164. that.setData({
  165. showEdit: true
  166. })
  167. }
  168. that.setData({
  169. score: res.data.score,
  170. levelName: res.data.levelName,
  171. })
  172. if (res.data.nickName) {
  173. that.setData({
  174. ismember: true,
  175. memberId: res.data.id
  176. })
  177. var size = this.setCanvasSize();
  178. var initUrl = JSON.stringify({
  179. flagid: res.data.id
  180. });
  181. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  182. }
  183. })
  184. .catch(err => {
  185. wx.showModal({
  186. title: '提示',
  187. content: err.errMsg,
  188. showCancel: false
  189. })
  190. })
  191. //暂时注释
  192. // that.getrun();
  193. },
  194. hideQrcode: function() {
  195. let that = this;
  196. that.setData({
  197. showQrcode: false
  198. })
  199. },
  200. //适配不同屏幕大小的canvas
  201. setCanvasSize: function() {
  202. var size = {};
  203. try {
  204. var res = wx.getSystemInfoSync();
  205. var scale = 750 / 500;
  206. //不同屏幕下canvas的适配比例;设计稿是750宽
  207. var width = res.windowWidth / scale;
  208. var height = width;
  209. //canvas画布为正方形
  210. size.w = width;
  211. size.h = height;
  212. } catch (e) {
  213. // Do something when catch error
  214. console.log("获取设备信息失败" + e);
  215. }
  216. return size;
  217. },
  218. createQrCode: function(url, canvasId, cavW, cavH) {
  219. //调用插件中的draw方法,绘制二维码图片
  220. QR.api.draw(url, canvasId, cavW, cavH);
  221. },
  222. qrcode: function(e) {
  223. var that = this;
  224. that.setData({
  225. showQrcode: true
  226. })
  227. wx.showToast({
  228. title: '生成中...',
  229. icon: 'loading',
  230. duration: 2000
  231. });
  232. var st = setTimeout(function() {
  233. wx.hideToast()
  234. var size = that.setCanvasSize();
  235. var url = JSON.stringify({
  236. END: "C",
  237. TYPE: "memberCode",
  238. ID: that.data.memberId,
  239. })
  240. that.createQrCode(url, "mycanvas1", size.w, size.h);
  241. that.setData({
  242. maskHidden: true
  243. });
  244. clearTimeout(st);
  245. }, 1000)
  246. },
  247. close: function() {
  248. this.setData({
  249. showmemberqrcode: false,
  250. })
  251. }
  252. });