C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

447 righe
11 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const imgurl = require("../../utils/imgurl");
  3. const config = require("../../config/config");
  4. const QR = require("../../utils/memberqrcode.js");
  5. let app = getApp();
  6. Page({
  7. data: {
  8. newUrl: imgurl.new.url,
  9. icon001: imgurl.icon001.url,
  10. icon002: imgurl.icon002.url,
  11. icon003: imgurl.icon003.url,
  12. icon004: imgurl.icon004.url,
  13. sapellgroup: imgurl.sapellgroup.url,
  14. market: app.globalData.market,
  15. list: [],
  16. loading: true,
  17. swiperCurrent: 0,
  18. title: null,
  19. desc: null,
  20. scrollTop: 0,
  21. showGame: false,
  22. gamedata: {},
  23. couponId: '', //游戏返回时传回的字段
  24. played: false, //从游戏页面跳回首页返回true
  25. havePlayEd: app.globalData.havePlayEd,
  26. staticGamedata: {},
  27. showIf: false,
  28. showPages: false,
  29. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  30. },
  31. gotodiscountCardList: function() {
  32. wx.navigateTo({
  33. url: '/pages/discountCardList/discountCardList'
  34. })
  35. },
  36. gotoRushBuy: function() {
  37. wx.navigateTo({
  38. url: '/pages/rushToBuy/index',
  39. })
  40. },
  41. gotoSpellGroup:function(){
  42. wx.navigateTo({
  43. url: '/pages/spellGroup/spellGroup',
  44. })
  45. },
  46. qrcode: function(e) {
  47. var that = this;
  48. that.setData({
  49. showQrcode: true
  50. })
  51. wx.showToast({
  52. title: '生成中...',
  53. icon: 'loading',
  54. duration: 2000
  55. });
  56. console.log(e)
  57. var st = setTimeout(function() {
  58. wx.hideToast()
  59. var size = that.setCanvasSize();
  60. var url = JSON.stringify({
  61. END: "C",
  62. TYPE: "memberCode",
  63. ID: that.data.memberId,
  64. });
  65. that.createQrCode(url, "mycanvas2", size.w, size.h);
  66. that.setData({
  67. maskHidden: true
  68. });
  69. clearTimeout(st);
  70. }, 1000)
  71. },
  72. hideQrcode: function() {
  73. let that = this;
  74. that.setData({
  75. showQrcode: false
  76. })
  77. },
  78. //适配不同屏幕大小的canvas
  79. setCanvasSize: function() {
  80. var size = {};
  81. try {
  82. var res = wx.getSystemInfoSync();
  83. var scale = 750 / 500;
  84. //不同屏幕下canvas的适配比例;设计稿是750宽
  85. var width = res.windowWidth / scale;
  86. var height = width;
  87. //canvas画布为正方形
  88. size.w = width;
  89. size.h = height;
  90. } catch (e) {
  91. // Do something when catch error
  92. console.log("获取设备信息失败" + e);
  93. }
  94. return size;
  95. },
  96. createQrCode: function(url, canvasId, cavW, cavH) {
  97. //调用插件中的draw方法,绘制二维码图片
  98. QR.api.draw(url, canvasId, cavW, cavH);
  99. },
  100. swiperChange: function(e) {
  101. this.setData({
  102. swiperCurrent: e.detail.current
  103. });
  104. },
  105. gotogame: function() {
  106. let that = this;
  107. Http.post({
  108. url: config.api.checkPhoneStatus,
  109. data: {}
  110. })
  111. .then(res => {
  112. var data = {
  113. couponChannelId: "" + that.data.couponChannelId,
  114. couponId: "" + that.data.couponId
  115. };
  116. if (that.data.couponChannelId == null) {
  117. var data = {
  118. couponId: "" + that.data.couponId
  119. };
  120. }
  121. wx.navigateTo({
  122. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  123. })
  124. })
  125. .catch(err => {
  126. if (err.code == 11005) {
  127. // 用户手机未授权
  128. /**
  129. * 将值传到用户手机号授权的页面
  130. *
  131. */
  132. wx.redirectTo({
  133. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  134. });
  135. } else if (err.code == 11006) {
  136. // 用户手机已加密
  137. wx.redirectTo({
  138. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  139. });
  140. } else {
  141. wx.showToast({
  142. title: err.message,
  143. icon: 'none',
  144. duration: 2000,
  145. mask: false
  146. });
  147. }
  148. })
  149. },
  150. mySpecial: function() {
  151. console.log("special");
  152. wx.navigateTo({
  153. url: '/pages/specialcourtesy/specialcourtesy',
  154. })
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onLoad: function(options) {
  160. let that = this;
  161. let optionss = JSON.parse(wx.getStorageSync('options'));
  162. console.log(optionss);
  163. console.log("-------------------------------------------optionssss------------------------------------")
  164. if (options.played == "true") {
  165. that.setData({
  166. played: true
  167. })
  168. }
  169. if (optionss.couponChannelId|| optionss.orderId) {
  170. that.userLogin(optionss.couponChannelId, optionss.orderId);
  171. } else {
  172. that.userLogin()
  173. }
  174. },
  175. onShow: function() {
  176. this.setData({
  177. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  178. })
  179. let num = wx.getStorageSync('couponNum');
  180. if (num == 'couponNum') {
  181. wx.showTabBarRedDot({
  182. index: 2
  183. })
  184. };
  185. },
  186. // 会员码获取
  187. getmemberId: function(token) {
  188. let that = this;
  189. Http.get({
  190. url: config.api.getScore,
  191. data: {
  192. token: token
  193. }
  194. }).then(res => {
  195. console.log(res)
  196. that.setData({
  197. levelName: res.data.levelName
  198. })
  199. if (res.data.nickName) {
  200. that.setData({
  201. ismember: true,
  202. memberId: res.data.id
  203. })
  204. var size = this.setCanvasSize();
  205. var initUrl = JSON.stringify({
  206. flagid: res.data.id
  207. });
  208. that.createQrCode(initUrl, "mycanvas1", size.w, size.h);
  209. }
  210. })
  211. .catch(err => {
  212. wx.showModal({
  213. title: '提示',
  214. content: err.message,
  215. showCancel: false
  216. })
  217. })
  218. },
  219. /**
  220. *
  221. * @param {code,page}
  222. * 子组件向父组件传值
  223. */
  224. onGetCode: function(e) {
  225. this.setData({
  226. code: e.detail.val,
  227. page: e.detail.pageNum,
  228. });
  229. console.log(e.detail.val)
  230. console.log(e.detail.pageNum)
  231. },
  232. /**
  233. * 用户登录
  234. */
  235. userLogin: function(couponChannelId, couponId, orderId) {
  236. var that = this;
  237. // 登录
  238. that.getGameOne(app.globalData.token)
  239. that.getStaticGame(app.globalData.token)
  240. that.getmemberId(app.globalData.token);
  241. that.checkUserCarStatus();
  242. that.getUserInfo();
  243. that.getBannerlist();
  244. if (app.couponChannelListCallback) {
  245. app.couponChannelListCallback(app.globalData.token);
  246. }
  247. if (app.couponListCallback) {
  248. app.couponListCallback(app.globalData.token);
  249. }
  250. if (app.businessListCallback) {
  251. app.businessListCallback(app.globalData.token);
  252. }
  253. Http.get({
  254. url: config.api.getWeapNote,
  255. data: {
  256. appId: config.weapp.AppId,
  257. }
  258. })
  259. .then(res => {
  260. let weapNote = JSON.parse(res.data.weapNote);
  261. that.setData({
  262. desc: weapNote.firstpage.desc,
  263. title: weapNote.firstpage.title
  264. })
  265. })
  266. .catch(err => {
  267. wx.showModal({
  268. title: "提示",
  269. content: err.errMsg,
  270. showCancel: false
  271. });
  272. });
  273. },
  274. getStaticGame(token) {
  275. let _this = this;
  276. Http.get({
  277. url: config.api.getGame,
  278. data: {
  279. triggleAction: 2,
  280. token: token
  281. }
  282. }).then(res => {
  283. if (res.data.id) {
  284. _this.setData({
  285. showIf: true
  286. })
  287. }
  288. _this.setData({
  289. staticGamedata: res.data
  290. })
  291. })
  292. .catch(err => {
  293. console.log(err)
  294. })
  295. },
  296. getGameOne: function(token) {
  297. let _this = this;
  298. Http.get({
  299. url: config.api.getGame,
  300. data: {
  301. triggleAction: 1,
  302. token: token
  303. }
  304. }).then(res => {
  305. if (res.data.id) {
  306. _this.setData({
  307. showGame: true
  308. })
  309. }
  310. _this.setData({
  311. gamedata: res.data
  312. })
  313. })
  314. .catch(err => {
  315. console.log(err)
  316. })
  317. },
  318. /**
  319. * banner
  320. */
  321. getBannerlist: function() {
  322. let that = this;
  323. Http.get({
  324. url: config.api.bannerlist,
  325. data: {
  326. pageNum: 1,
  327. pageSize: 7
  328. }
  329. }).then(res => {
  330. that.setData({
  331. list: res.data.list
  332. });
  333. });
  334. },
  335. /**
  336. * 检查用户是否有车
  337. */
  338. checkUserCarStatus: function() {
  339. var that = this;
  340. Http.get({
  341. url: config.api.userCarCount,
  342. data: {}
  343. }).then(res => {
  344. if (res.data > 0) {
  345. // 用户名下有车
  346. app.globalData.phone = res.data.phone;
  347. app.globalData.supportCar = true;
  348. // 共同登录
  349. that.userCarLogin();
  350. }
  351. });
  352. },
  353. /**
  354. * car共同登录
  355. */
  356. userCarLogin: function() {
  357. var that = this;
  358. if (!app.globalData.carLogin) {
  359. // 共同登录
  360. Http.post({
  361. url: config.api.carInit,
  362. data: {
  363. phone: app.globalData.phone
  364. }
  365. }).then(res => {
  366. app.globalData.carLogin = true;
  367. app.globalData.parkVendor = res.data.vendor;
  368. if (res.data.token != "undefined") {
  369. app.globalData.etcpToken = res.data.token;
  370. }
  371. });
  372. }
  373. },
  374. /**
  375. * 获取用户信息
  376. */
  377. getUserInfo: function() {
  378. // 获取用户信息
  379. wx.getSetting({
  380. success: res => {
  381. if (res.authSetting["scope.userInfo"]) {
  382. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  383. wx.getUserInfo({
  384. success: res => {
  385. // 可以将 res 发送给后台解码出 unionId
  386. }
  387. });
  388. }
  389. }
  390. });
  391. },
  392. gotoBargain: function() {
  393. wx.navigateTo({
  394. url: '/pages/bargain/bargain'
  395. })
  396. },
  397. /**
  398. * 刷新
  399. */
  400. onPullDownRefresh: function(e) {
  401. let that = this;
  402. that.userLogin();
  403. that.setData({
  404. page: 1
  405. })
  406. if (that.data.code == 0 || that.data.code == undefined) {
  407. that.selectComponent("#lists").getList(0, 1, "refresh");
  408. wx.stopPullDownRefresh();
  409. } else {
  410. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  411. wx.stopPullDownRefresh();
  412. };
  413. },
  414. //加载更多
  415. onReachBottom: function() {
  416. let that = this;
  417. that.data.page++;
  418. that.setData({
  419. page: that.data.page
  420. });
  421. console.log("加载更多页数" + that.data.page);
  422. console.log("加载更多key" + that.data.code);
  423. //父组件获得子组件的方法
  424. //如果code == 0
  425. if (that.data.code == 0 || that.data.code == undefined) {
  426. that.selectComponent("#lists").getList(0, that.data.page);
  427. } else {
  428. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  429. }
  430. },
  431. // 用户点击右上角分享
  432. onShareAppMessage: function() {
  433. return {
  434. title: this.data.title,
  435. desc: this.data.desc,
  436. success: function(res) {
  437. wx.showToast({
  438. title: "分享成功",
  439. duration: 1000,
  440. icon: "success"
  441. });
  442. }
  443. };
  444. }
  445. });