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.

637 lines
16 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. const util = require("../../utils/util");
  6. let app = getApp();
  7. Page({
  8. data: {
  9. newUrl: "",
  10. cover: "",
  11. kanjia:imgurl.kanjia.url,
  12. pintuan: imgurl.pintuan.url,
  13. xiaofeika: imgurl.xiaofeika.url,
  14. xingyun: imgurl.xingyun.url,
  15. jfshangcheng: imgurl.jfshangcheng.url,
  16. toutiao: imgurl.toutiao.url,
  17. usergift: imgurl.usergift.url,
  18. guanbi1: imgurl.guanbi1.url,
  19. icon0001: imgurl.icon0001.url,
  20. icon0002: imgurl.icon0002.url,
  21. icon0003: imgurl.icon0003.url,
  22. icon0004: imgurl.icon0004.url,
  23. icon0005: imgurl.icon0005.url,
  24. icon0006: imgurl.icon0006.url,
  25. icon0007: imgurl.icon0007.url,
  26. icon0008: imgurl.icon0008.url,
  27. barcode: imgurl.barcode.url,
  28. leftarrows: imgurl.leftarrows.url,
  29. newcard: imgurl.newcard.url,
  30. newseckill: imgurl.newseckill.url,
  31. newbargain: imgurl.newbargain.url,
  32. newgroup: imgurl.newgroup.url,
  33. product: imgurl.product.url,
  34. barginicon: imgurl.barginicon.url,
  35. pintuan: imgurl.pintuan.url,
  36. duihuan: imgurl.duihuan.url,
  37. market: app.globalData.market,
  38. list: [],
  39. loading: true,
  40. fistLogin: null,
  41. alphaData: null,
  42. swiperCurrent: 0,
  43. title: null,
  44. weappShareTitle: '', //分享标题
  45. weappShareCoverImg: '', //分享图片
  46. desc: null,
  47. scrollTop: 0,
  48. showGame: false,
  49. showTopic: false,
  50. gamedata: {},
  51. couponId: '', //游戏返回时传回的字段
  52. played: false, //从游戏页面跳回首页返回true
  53. havePlayEd: app.globalData.havePlayEd,
  54. staticGamedata: {},
  55. showIf: false,
  56. showPages: false,
  57. display: 'none',
  58. display1: 'none',
  59. optionsData: null,
  60. credit: 0,
  61. score: '0',
  62. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  63. },
  64. close: function() {
  65. this.setData({
  66. showIf: false
  67. })
  68. },
  69. alphaClick: function(even) {
  70. var animation = wx.createAnimation({})
  71. animation.opacity(0).step({
  72. duration: 2000
  73. })
  74. this.setData({
  75. alphaData: animation.export()
  76. })
  77. },
  78. // 我的卡包
  79. mycard: function() {
  80. wx.navigateTo({
  81. url: '/pages/cardorder/index/index',
  82. })
  83. },
  84. //我的券包
  85. mycoupon: function() {
  86. wx.navigateTo({
  87. url: '/pages/couponorder/index/index',
  88. })
  89. },
  90. gotoSpellGroup: function() {
  91. wx.navigateTo({
  92. url: '/pages/spellGroup/spellGroup',
  93. })
  94. },
  95. qrcode: function() {
  96. var that = this;
  97. let memberId = that.data.memberId;
  98. if (memberId) {
  99. wx.navigateTo({
  100. url: '/pages/specialcourtesy/specialcourtesy'
  101. })
  102. }
  103. },
  104. // hideQrcode: function() {
  105. // let that = this;
  106. // that.setData({
  107. // showQrcode: false
  108. // })
  109. // },
  110. //跳往限时秒杀
  111. gotoRushBuy: function() {
  112. wx.navigateTo({
  113. url: '/pages/rushToBuy/index',
  114. })
  115. },
  116. // 跳往卡列表
  117. gotodiscountcard: function() {
  118. wx.navigateTo({
  119. url: '/pages/discountCardList/discountCardList',
  120. })
  121. },
  122. //跳往积分商城
  123. gotouser: function() {
  124. wx.navigateTo({
  125. url: `/pages/integralmall/index`
  126. })
  127. },
  128. //跳往砍价专场
  129. gobargain: function() {
  130. wx.navigateTo({
  131. url: '/pages/bargain/bargain',
  132. })
  133. },
  134. //跳往拼团专场
  135. gogroup: function() {
  136. wx.navigateTo({
  137. url: '/pages/spellGroup/spellGroup',
  138. })
  139. },
  140. //搜索门店
  141. // searchbar:function(){
  142. // wx.switchTab({
  143. // url: '/pages/index/searchbar/index',
  144. // })
  145. // },
  146. // createQrCode: function(url, canvasId, cavW, cavH) {
  147. // //调用插件中的draw方法,绘制二维码图片
  148. // QR.api.draw(url, canvasId, cavW, cavH);
  149. // },
  150. swiperChange: function(e) {
  151. this.setData({
  152. swiperCurrent: e.detail.current
  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;
  212. if (wx.getStorageSync('options')){
  213. optionss = JSON.parse(wx.getStorageSync('options'));
  214. }
  215. if (options.played == "true") {
  216. that.setData({
  217. played: true
  218. })
  219. }
  220. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  221. that.setData({
  222. optionsData: optionss
  223. })
  224. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  225. } else {
  226. that.getWeapNote()
  227. }
  228. //获取条形码
  229. // util.barcode("barcode", optionss.quancode, 510, 100);
  230. },
  231. onShow: function() {
  232. let that = this;
  233. that.setData({
  234. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  235. })
  236. /**
  237. * couponNum 是否有普通的优惠券购买
  238. * couponNum2 是否有新买的消费卡
  239. */
  240. let num = wx.getStorageSync('couponNum');
  241. let num1 = wx.getStorageSync('couponNum2');
  242. if (num == 'couponNum' || num1 == 'couponNum2') {
  243. wx.showTabBarRedDot({
  244. index: 3
  245. })
  246. } else {
  247. wx.hideTabBarRedDot({
  248. index: 3
  249. })
  250. }
  251. if (app.globalData.score) {
  252. that.setData({
  253. fistLogin: app.globalData.score
  254. })
  255. }
  256. // 如果有游戏
  257. setTimeout(function() {
  258. that.alphaClick();
  259. }, 8000)
  260. },
  261. getmemberId: function(token) {
  262. let that = this;
  263. Http.get({
  264. url: config.api.getScore,
  265. data: {
  266. token: token
  267. }
  268. }).then(res => {
  269. that.setData({
  270. levelName: res.data.levelName,
  271. upgradePercent: res.data.upgradePercent,
  272. upgradeScore: res.data.upgradeScore,
  273. credit: res.data.credit ? res.data.credit : 0,
  274. score: res.data.score
  275. })
  276. if (res.data.nickName) {
  277. that.setData({
  278. ismember: true,
  279. memberId: res.data.id
  280. })
  281. var initUrl = JSON.stringify({
  282. flagid: res.data.id
  283. });
  284. }
  285. })
  286. .catch(err => {
  287. wx.showModal({
  288. title: '提示',
  289. content: err.message,
  290. showCancel: false
  291. })
  292. })
  293. },
  294. gotoChengzhangzhi: function() {
  295. wx.navigateTo({
  296. url: '/pages/czdetail/czdetail',
  297. })
  298. },
  299. gotoBargain: function () {
  300. wx.navigateTo({
  301. url: '/pages/bargain/bargain',
  302. })
  303. },
  304. gotoSpellGroup: function () {
  305. wx.navigateTo({
  306. url: '/pages/spellGroup/spellGroup',
  307. })
  308. },
  309. gotoCard: function () {
  310. wx.navigateTo({
  311. url: '/pages/discountCardList/discountCardList',
  312. })
  313. },
  314. gotoGame: function () {
  315. wx.navigateTo({
  316. url: '/pages/game/index',
  317. })
  318. },
  319. gotoJfsc: function () {
  320. wx.navigateTo({
  321. url: '/pages/integralmall/index',
  322. })
  323. },
  324. /**
  325. *
  326. * @param {code,page}
  327. * 子组件向父组件传值
  328. */
  329. onGetCode: function(e) {
  330. this.setData({
  331. code: e.detail.val,
  332. page: e.detail.pageNum,
  333. });
  334. console.log(e.detail.val)
  335. console.log(e.detail.pageNum)
  336. },
  337. getWeapNote: function(couponChannelId, couponId, orderId) {
  338. var that = this;
  339. // 登录
  340. that.getmemberId(app.globalData.token);
  341. that.getBannerlist();
  342. that.topicShow();
  343. that.getMallInfo(app.globalData.token);
  344. if (app.couponChannelListCallback) {
  345. app.couponChannelListCallback(app.globalData.token);
  346. }
  347. if (app.couponListCallback) {
  348. app.couponListCallback(app.globalData.token);
  349. }
  350. if (app.businessListCallback) {
  351. app.businessListCallback(app.globalData.token);
  352. }
  353. Http.get({
  354. url: config.api.getWeapNote,
  355. data: {
  356. appId: config.weapp.AppId,
  357. }
  358. })
  359. .then(res => {
  360. that.getGameOne(app.globalData.token)
  361. that.getStaticGame(app.globalData.token)
  362. let weapNote = JSON.parse(res.data.weapNote);
  363. that.setData({
  364. desc: weapNote.firstpage.desc,
  365. title: weapNote.firstpage.title
  366. })
  367. })
  368. .catch(err => {
  369. that.getGameOne(app.globalData.token)
  370. that.getStaticGame(app.globalData.token)
  371. wx.showModal({
  372. title: "提示",
  373. content: err.errMsg,
  374. showCancel: false
  375. });
  376. });
  377. },
  378. getStaticGame(token) {
  379. let _this = this;
  380. Http.get({
  381. url: config.api.getGame,
  382. data: {
  383. triggleAction: 2, // 固定入口
  384. token: token
  385. }
  386. }).then(res => {
  387. if (res.data.id) {
  388. _this.setData({
  389. showIf: true,
  390. newUrl: res.data.imgUrl
  391. })
  392. } else {
  393. _this.setData({
  394. showIf: false
  395. })
  396. }
  397. _this.setData({
  398. staticGamedata: res.data
  399. })
  400. })
  401. .catch(err => {
  402. _this.setData({
  403. showIf: false
  404. })
  405. console.log(err)
  406. })
  407. },
  408. getGameOne: function(token) {
  409. let _this = this;
  410. Http.get({
  411. url: config.api.getGame,
  412. data: {
  413. triggleAction: 1, // 登录触发
  414. token: token
  415. }
  416. }).then(res => {
  417. if (res.data.id) {
  418. _this.setData({
  419. showGame: true,
  420. })
  421. } else {
  422. _this.setData({
  423. showGame: false
  424. })
  425. }
  426. _this.setData({
  427. gamedata: res.data
  428. })
  429. })
  430. .catch(err => {
  431. _this.setData({
  432. showGame: false
  433. })
  434. this.alphaClick();
  435. })
  436. },
  437. /**
  438. * mallinfo
  439. */
  440. getMallInfo: function(token) {
  441. let that = this;
  442. Http.get({
  443. url: config.api.getMallInfo,
  444. data: {
  445. token: token,
  446. }
  447. }).then(res => {
  448. that.setData({
  449. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  450. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  451. });
  452. })
  453. .catch(err => {
  454. // 不需要错误提示
  455. });
  456. },
  457. /**
  458. * banner
  459. */
  460. getBannerlist: function() {
  461. let that = this;
  462. Http.get({
  463. url: config.api.bannerlist,
  464. data: {
  465. pageNum: 1,
  466. pageSize: 7
  467. }
  468. }).then(res => {
  469. // that.getmemberId(app.globalData.token);
  470. // that.checkUserCarStatus();
  471. that.setData({
  472. list: res.data.list
  473. });
  474. })
  475. .catch(err => {
  476. // that.getmemberId(app.globalData.token);
  477. // that.checkUserCarStatus();
  478. });
  479. },
  480. // 专题显示
  481. topicShow: function() {
  482. let that = this;
  483. Http.get({
  484. url: config.api.topicShow,
  485. data: {
  486. token: app.globalData.token
  487. }
  488. }).then(res => {
  489. if (res && res.data) {
  490. that.setData({
  491. cover: res.data.cover,
  492. id: res.data.id,
  493. showTopic: true
  494. })
  495. } else {
  496. that.setData({
  497. showTopic: false
  498. })
  499. }
  500. })
  501. .catch(err => {
  502. console.log(err);
  503. })
  504. },
  505. gotoTopic() {
  506. wx.navigateTo({
  507. url: `/pages/topicDetail/index?id=${this.data.id}`
  508. })
  509. },
  510. /**
  511. * 检查用户是否有车
  512. */
  513. // checkUserCarStatus: function() {
  514. // var that = this;
  515. // Http.get({
  516. // url: config.api.userCarCount,
  517. // data: {}
  518. // }).then(res => {
  519. // if (res.data > 0) {
  520. // // 用户名下有车
  521. // app.globalData.phone = res.data.phone;
  522. // app.globalData.supportCar = true;
  523. // // 共同登录
  524. // that.userCarLogin();
  525. // }
  526. // });
  527. // },
  528. /**
  529. * car共同登录
  530. */
  531. // userCarLogin: function() {
  532. // var that = this;
  533. // if (!app.globalData.carLogin) {
  534. // // 共同登录
  535. // Http.post({
  536. // url: config.api.carInit,
  537. // data: {
  538. // phone: app.globalData.phone
  539. // }
  540. // }).then(res => {
  541. // app.globalData.carLogin = true;
  542. // app.globalData.parkVendor = res.data.vendor;
  543. // if (res.data.token != "undefined") {
  544. // app.globalData.etcpToken = res.data.token;
  545. // }
  546. // });
  547. // }
  548. // },
  549. /**
  550. * 获取用户信息
  551. */
  552. // getUserInfo: function() {
  553. // // 获取用户信息
  554. // wx.getSetting({
  555. // success: res => {
  556. // if (res.authSetting["scope.userInfo"]) {
  557. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  558. // wx.getUserInfo({
  559. // success: res => {
  560. // // 可以将 res 发送给后台解码出 unionId
  561. // }
  562. // });
  563. // }
  564. // }
  565. // });
  566. // },
  567. gotoBargain: function() {
  568. wx.navigateTo({
  569. url: '/pages/bargain/bargain'
  570. })
  571. },
  572. /**
  573. * 刷新
  574. */
  575. onPullDownRefresh: function(e) {
  576. let that = this;
  577. that.getWeapNote();
  578. that.setData({
  579. page: 1
  580. })
  581. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  582. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  583. } else {
  584. this.getWeapNote()
  585. }
  586. if (that.data.code == 0 || that.data.code == undefined) {
  587. that.selectComponent("#lists").getList(0, 1, "refresh");
  588. wx.stopPullDownRefresh();
  589. } else {
  590. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  591. wx.stopPullDownRefresh();
  592. };
  593. // 砍价下拉刷新
  594. that.selectComponent("#bargain").getList();
  595. that.selectComponent("#spellGroup").getList();
  596. that.selectComponent("#rushtobyCard").getList();
  597. wx.stopPullDownRefresh();
  598. },
  599. //加载更多
  600. onReachBottom: function() {
  601. let that = this;
  602. that.data.page++;
  603. that.setData({
  604. page: that.data.page
  605. });
  606. console.log("加载更多页数" + that.data.page);
  607. console.log("加载更多key" + that.data.code);
  608. //父组件获得子组件的方法
  609. //如果code == 0
  610. if (that.data.code == 0 || that.data.code == undefined) {
  611. that.selectComponent("#lists").getList(0, that.data.page);
  612. } else {
  613. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  614. }
  615. },
  616. // 用户点击右上角分享
  617. onShareAppMessage: function() {
  618. return {
  619. title: this.data.weappShareTitle,
  620. imageUrl: this.data.weappShareCoverImg,
  621. // desc: this.data.desc,
  622. success: function(res) {
  623. wx.showToast({
  624. title: "分享成功",
  625. duration: 1000,
  626. icon: "success"
  627. });
  628. }
  629. };
  630. }
  631. });