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.

276 linhas
6.5 KiB

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