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.

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