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.

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