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.

756 lines
19 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. let ifStoreApp = extConfig.attr.ifStoreApp;
  3. const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px'
  4. const Http = require("../utils/HttpBasics");
  5. const imgurl = require("../utils/imgurl");
  6. const config = require("../config/config");
  7. const QR = require("../utils/memberqrcode.js");
  8. const util = require("../utils/util");
  9. const bgColor = require("../utils/bgColor.js")
  10. let app = getApp();
  11. Page({
  12. data: {
  13. showLocationIf: true,
  14. ifStoreApp: ifStoreApp,
  15. navigationBarTitle: '首页',
  16. navigationBarHeight,
  17. chengzhangBox: bgColor.colorFirst.main.chengzhangBox,
  18. activeColor: bgColor.colorFirst.main.activeColor,
  19. qg: bgColor.colorFirst.main.qg,
  20. newUrl: "",
  21. cover: "",
  22. kanjia: imgurl.kanjia.url,
  23. pintuan: imgurl.pintuan.url,
  24. xiaofeika: imgurl.xiaofeika.url,
  25. xingyun: imgurl.xingyun.url,
  26. jfshangcheng: imgurl.jfshangcheng.url,
  27. toutiao: imgurl.toutiao.url,
  28. more: imgurl.more.url,
  29. giftHr: imgurl.giftHr.url,
  30. giftHr: imgurl.giftHr.url,
  31. next: imgurl.next.url,
  32. usergift: imgurl.usergift.url,
  33. guanbi1: imgurl.guanbi1.url,
  34. icon0001: imgurl.icon0001.url,
  35. icon0002: imgurl.icon0002.url,
  36. icon0003: imgurl.icon0003.url,
  37. icon0004: imgurl.icon0004.url,
  38. icon0005: imgurl.icon0005.url,
  39. icon0006: imgurl.icon0006.url,
  40. icon0007: imgurl.icon0007.url,
  41. icon0008: imgurl.icon0008.url,
  42. barcode: imgurl.barcode.url,
  43. leftarrows: imgurl.leftarrows.url,
  44. newcard: imgurl.newcard.url,
  45. newseckill: imgurl.newseckill.url,
  46. newbargain: imgurl.newbargain.url,
  47. newgroup: imgurl.newgroup.url,
  48. product: imgurl.product.url,
  49. barginicon: imgurl.barginicon.url,
  50. pintuan: imgurl.pintuan.url,
  51. live: imgurl.live.url,
  52. duihuan: imgurl.duihuan.url,
  53. market: app.globalData.market,
  54. list: [],
  55. xslist: [],
  56. loading: true,
  57. fistLogin: null,
  58. alphaData: null,
  59. alphaData1: null,
  60. swiperCurrent: 0,
  61. title: null,
  62. weappShareTitle: '', //分享标题
  63. weappShareCoverImg: '', //分享图片
  64. desc: null,
  65. scrollTop: 0,
  66. showGame: false,
  67. showTopic: false,
  68. showQg: false,
  69. gamedata: {},
  70. couponId: '', //游戏返回时传回的字段
  71. played: false, //从游戏页面跳回首页返回true
  72. havePlayEd: app.globalData.havePlayEd,
  73. havePlayEd1: app.globalData.havePlayEd1,
  74. staticGamedata: {},
  75. showIf: false,
  76. showPages: false,
  77. display: 'none',
  78. display1: 'none',
  79. optionsData: null,
  80. page: 1, // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  81. openId: '',
  82. showGg: false,
  83. ggdata: {}
  84. },
  85. goLive(){
  86. wx.navigateTo({
  87. url: '/pages2/live/livelist/index',
  88. })
  89. },
  90. alphaClick1: function(even) {
  91. var animation = wx.createAnimation({})
  92. animation.opacity(0).step({
  93. duration: 2000
  94. })
  95. this.setData({
  96. alphaData: animation.export()
  97. })
  98. },
  99. alphaClick: function(even) {
  100. var animation = wx.createAnimation({})
  101. animation.opacity(0).step({
  102. duration: 2000
  103. })
  104. this.setData({
  105. alphaData1: animation.export()
  106. })
  107. },
  108. // 我的卡包
  109. mycard: function() {
  110. wx.navigateTo({
  111. url: '/pages/cardorder/index/index',
  112. })
  113. },
  114. //我的券包
  115. mycoupon: function() {
  116. wx.navigateTo({
  117. url: '/pages/couponorder/index/index',
  118. })
  119. },
  120. gotoSpellGroup: function() {
  121. wx.navigateTo({
  122. url: '/pages/spellGroup/spellGroup',
  123. })
  124. },
  125. qrcode: function() {
  126. var that = this;
  127. let memberId = that.data.memberId;
  128. if (memberId) {
  129. wx.navigateTo({
  130. url: '/pages/specialcourtesy/specialcourtesy'
  131. })
  132. }
  133. },
  134. //跳往限时秒杀
  135. gotoRushBuy: function() {
  136. wx.navigateTo({
  137. url: '/pages/rushToBuy/index',
  138. })
  139. },
  140. swiperChange: function(e) {
  141. this.setData({
  142. swiperCurrent: e.detail.current
  143. });
  144. },
  145. gotogame: function() {
  146. let that = this;
  147. if (!that.data.showIf) {
  148. wx.showToast({
  149. title: '暂无游戏频道',
  150. icon: "none",
  151. duration: 3000
  152. })
  153. } else {
  154. Http.get({
  155. url: config.api.checkPhoneStatus,
  156. data: {}
  157. })
  158. .then(res => {
  159. var data = {
  160. couponChannelId: "" + that.data.couponChannelId,
  161. couponId: "" + that.data.couponId
  162. };
  163. if (that.data.couponChannelId == null) {
  164. var data = {
  165. couponId: "" + that.data.couponId
  166. };
  167. }
  168. wx.redirectTo({
  169. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  170. })
  171. })
  172. .catch(err => {
  173. if (err.code == 11005) {
  174. // 用户手机未授权
  175. /**
  176. * 将值传到用户手机号授权的页面
  177. *
  178. */
  179. wx.redirectTo({
  180. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  181. });
  182. } else if (err.code == 11006) {
  183. // 用户手机已加密
  184. wx.redirectTo({
  185. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  186. });
  187. } else {
  188. wx.showToast({
  189. title: err.message,
  190. icon: 'none',
  191. duration: 2000,
  192. mask: false
  193. });
  194. }
  195. })
  196. }
  197. },
  198. mySpecial: function() {
  199. console.log("special");
  200. wx.navigateTo({
  201. url: '/pages/specialcourtesy/specialcourtesy',
  202. })
  203. },
  204. /**
  205. * 生命周期函数--监听页面初次渲染完成
  206. */
  207. onLoad: function(options) {
  208. this.getLocation();
  209. let that = this;
  210. let optionss;
  211. let openId = wx.getStorageSync('openId')
  212. if (openId) {
  213. that.setData({
  214. openId: openId
  215. })
  216. }
  217. if (wx.getStorageSync('options')) {
  218. optionss = JSON.parse(wx.getStorageSync('options'));
  219. }
  220. if (options.played == "true") {
  221. that.setData({
  222. played: true
  223. })
  224. }
  225. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  226. that.setData({
  227. optionsData: optionss
  228. })
  229. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  230. } else {
  231. that.getWeapNote()
  232. }
  233. //获取条形码
  234. // util.barcode("barcode", optionss.quancode, 510, 100);
  235. },
  236. /**
  237. * 获得经纬度
  238. */
  239. getLocation() {
  240. let that = this;
  241. wx.getLocation({
  242. type: "wgs84",
  243. success: function(res) {
  244. console.log(res, 9999)
  245. if (res && res.longitude && res.latitude) {
  246. Http.post({
  247. url: config.api.updateLBS,
  248. data: {
  249. latitude: res.latitude,
  250. longitude: res.longitude
  251. }
  252. }).then(res => {
  253. console.log(res, 9999)
  254. })
  255. }
  256. },
  257. fail: error => {
  258. console.log(error);
  259. }
  260. })
  261. },
  262. onShow: function() {
  263. if (typeof this.getTabBar === 'function' &&
  264. this.getTabBar()) {
  265. this.getTabBar().setData({
  266. selected: 0
  267. })
  268. }
  269. let that = this;
  270. that.setData({
  271. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  272. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  273. })
  274. /**
  275. * couponNum 是否有普通的优惠券购买
  276. * couponNum2 是否有新买的消费卡
  277. */
  278. let num = wx.getStorageSync('couponNum');
  279. let num1 = wx.getStorageSync('couponNum2');
  280. if (num == 'couponNum' || num1 == 'couponNum2') {
  281. wx.showTabBarRedDot({
  282. index: 3
  283. })
  284. } else {
  285. wx.hideTabBarRedDot({
  286. index: 3
  287. })
  288. }
  289. if (app.globalData.score) {
  290. that.setData({
  291. fistLogin: app.globalData.score
  292. })
  293. }
  294. // 如果有游戏
  295. setTimeout(function() {
  296. that.alphaClick();
  297. }, 8000)
  298. // 如果有广告
  299. setTimeout(function() {
  300. // debugger
  301. that.alphaClick1();
  302. }, 8000)
  303. },
  304. getmemberId: function(token) {
  305. let that = this;
  306. Http.get({
  307. url: config.api.getScore,
  308. data: {
  309. token: token
  310. }
  311. }).then(res => {
  312. that.setData({
  313. levelName: res.data.levelName,
  314. upgradePercent: res.data.upgradePercent,
  315. upgradeScore: res.data.upgradeScore,
  316. memberId: res.data.id,
  317. })
  318. })
  319. .catch(err => {
  320. wx.showModal({
  321. title: '提示',
  322. content: err.message,
  323. showCancel: false
  324. })
  325. })
  326. },
  327. gotoChengzhangzhi: function() {
  328. wx.navigateTo({
  329. url: '/pages/czdetail/czdetail',
  330. })
  331. },
  332. gotoBargain: function() {
  333. wx.navigateTo({
  334. url: '/pages/bargain/bargain',
  335. })
  336. },
  337. gotoSpellGroup: function() {
  338. wx.navigateTo({
  339. url: '/pages/spellGroup/spellGroup',
  340. })
  341. },
  342. gotoCard: function() {
  343. wx.navigateTo({
  344. url: '/pages/discountCardList/discountCardList',
  345. })
  346. },
  347. // gotoGame: function () {
  348. // wx.navigateTo({
  349. // url: '/pages/game/index',
  350. // })
  351. // },
  352. gotoJfsc: function() {
  353. wx.navigateTo({
  354. url: '/pages/integralmall/index',
  355. })
  356. },
  357. /**
  358. *
  359. * @param {code,page}
  360. * 子组件向父组件传值
  361. */
  362. onGetCode: function(e) {
  363. this.setData({
  364. code: e.detail.val,
  365. page: e.detail.pageNum,
  366. });
  367. console.log(e.detail.val)
  368. console.log(e.detail.pageNum)
  369. },
  370. getWeapNote: function(couponChannelId, couponId, orderId) {
  371. var that = this;
  372. // 登录
  373. that.getmemberId(app.globalData.token);
  374. that.getBannerlist();
  375. that.topicShow();
  376. that.getxsList();
  377. that.getMallInfo(app.globalData.token);
  378. if (app.couponChannelListCallback) {
  379. app.couponChannelListCallback(app.globalData.token);
  380. }
  381. if (app.couponListCallback) {
  382. app.couponListCallback(app.globalData.token);
  383. }
  384. if (app.businessListCallback) {
  385. app.businessListCallback(app.globalData.token);
  386. }
  387. Http.get({
  388. url: config.api.getWeapNote,
  389. data: {
  390. appId: config.weapp.AppId,
  391. }
  392. })
  393. .then(res => {
  394. console.log(res)
  395. // that.getGameOne(app.globalData.token)
  396. that.getStaticGame(app.globalData.token)
  397. that.getGg(app.globalData.token)
  398. let weapNote = JSON.parse(res.data.weapNote);
  399. that.setData({
  400. desc: weapNote.firstpage.desc,
  401. title: weapNote.firstpage.title
  402. })
  403. })
  404. .catch(err => {
  405. // that.getGameOne(app.globalData.token)
  406. that.getStaticGame(app.globalData.token)
  407. that.getGg(app.globalData.token)
  408. wx.showModal({
  409. title: "提示",
  410. content: err.errMsg,
  411. showCancel: false
  412. });
  413. });
  414. },
  415. getStaticGame(token) {
  416. let _this = this;
  417. Http.get({
  418. url: config.api.getGame,
  419. data: {
  420. triggleAction: 2, // 固定入口
  421. token: token
  422. }
  423. }).then(res => {
  424. if (res.data.id) {
  425. _this.setData({
  426. showIf: true,
  427. newUrl: res.data.imgUrl
  428. })
  429. } else {
  430. _this.setData({
  431. showIf: false
  432. })
  433. }
  434. _this.setData({
  435. staticGamedata: res.data
  436. })
  437. })
  438. .catch(err => {
  439. _this.setData({
  440. showIf: false
  441. })
  442. console.log(err)
  443. })
  444. },
  445. getGameOne: function(token) {
  446. let _this = this;
  447. Http.get({
  448. url: config.api.getGame,
  449. data: {
  450. triggleAction: 1, // 登录触发
  451. token: token
  452. }
  453. }).then(res => {
  454. if (res.data.id) {
  455. _this.setData({
  456. showGame: true,
  457. })
  458. } else {
  459. _this.setData({
  460. showGame: false
  461. })
  462. }
  463. _this.setData({
  464. gamedata: res.data
  465. })
  466. })
  467. .catch(err => {
  468. _this.setData({
  469. showGame: false
  470. })
  471. this.alphaClick();
  472. })
  473. },
  474. /**
  475. * mallinfo
  476. */
  477. getMallInfo: function(token) {
  478. let that = this;
  479. Http.get({
  480. url: config.api.getMallInfo,
  481. data: {
  482. token: token,
  483. }
  484. }).then(res => {
  485. that.setData({
  486. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  487. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  488. });
  489. })
  490. .catch(err => {
  491. // 不需要错误提示
  492. });
  493. },
  494. //获取限时抢购列表
  495. getxsList() {
  496. let that = this;
  497. Http.get({
  498. url: config.api.couponChannelList,
  499. data: {
  500. pageNum: 1,
  501. pageSize: 3,
  502. targetAd: 2
  503. }
  504. }).then(res => {
  505. if (res && res.data.total > 0) {
  506. that.setData({
  507. xslist: res.data.list,
  508. showQg: true
  509. });
  510. } else {
  511. that.setData({
  512. showQg: false
  513. })
  514. }
  515. })
  516. .catch(err => {
  517. console.log(err)
  518. wx.showToast({
  519. title: err.errMsg,
  520. icon: 'none',
  521. duration: 2000,
  522. mask: false
  523. });
  524. })
  525. },
  526. /**
  527. * banner
  528. */
  529. getBannerlist: function() {
  530. let that = this;
  531. Http.get({
  532. url: config.api.bannerlist,
  533. data: {
  534. pageNum: 1,
  535. pageSize: 7
  536. }
  537. }).then(res => {
  538. that.getmemberId(app.globalData.token);
  539. // that.checkUserCarStatus();
  540. that.setData({
  541. list: res.data.list
  542. });
  543. })
  544. .catch(err => {
  545. that.getmemberId(app.globalData.token);
  546. // that.checkUserCarStatus();
  547. });
  548. },
  549. // 专题显示
  550. topicShow: function() {
  551. let that = this;
  552. Http.get({
  553. url: config.api.topicShow,
  554. data: {
  555. token: app.globalData.token
  556. }
  557. }).then(res => {
  558. if (res && res.data) {
  559. that.setData({
  560. name: res.data.name,
  561. cover: res.data.cover,
  562. id: res.data.id,
  563. showTopic: true
  564. })
  565. } else {
  566. that.setData({
  567. showTopic: false
  568. })
  569. }
  570. })
  571. .catch(err => {
  572. console.log(err);
  573. })
  574. },
  575. gotoTopic() {
  576. wx.navigateTo({
  577. url: `/pages/topicDetail/index?id=${this.data.id}`
  578. })
  579. },
  580. /**
  581. * 检查用户是否有车
  582. */
  583. // checkUserCarStatus: function() {
  584. // var that = this;
  585. // Http.get({
  586. // url: config.api.userCarCount,
  587. // data: {}
  588. // }).then(res => {
  589. // if (res.data > 0) {
  590. // // 用户名下有车
  591. // app.globalData.phone = res.data.phone;
  592. // app.globalData.supportCar = true;
  593. // // 共同登录
  594. // that.userCarLogin();
  595. // }
  596. // });
  597. // },
  598. /**
  599. * car共同登录
  600. */
  601. // userCarLogin: function() {
  602. // var that = this;
  603. // if (!app.globalData.carLogin) {
  604. // // 共同登录
  605. // Http.post({
  606. // url: config.api.carInit,
  607. // data: {
  608. // phone: app.globalData.phone
  609. // }
  610. // }).then(res => {
  611. // app.globalData.carLogin = true;
  612. // app.globalData.parkVendor = res.data.vendor;
  613. // if (res.data.token != "undefined") {
  614. // app.globalData.etcpToken = res.data.token;
  615. // }
  616. // });
  617. // }
  618. // },
  619. /**
  620. * 获取用户信息
  621. */
  622. // getUserInfo: function() {
  623. // // 获取用户信息
  624. // wx.getSetting({
  625. // success: res => {
  626. // if (res.authSetting["scope.userInfo"]) {
  627. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  628. // wx.getUserInfo({
  629. // success: res => {
  630. // // 可以将 res 发送给后台解码出 unionId
  631. // }
  632. // });
  633. // }
  634. // }
  635. // });
  636. // },
  637. gotoBargain: function() {
  638. wx.navigateTo({
  639. url: '/pages/bargain/bargain'
  640. })
  641. },
  642. //限时抢购的详情页面
  643. gotodetail: function(e) {
  644. wx.navigateTo({
  645. url: `/pages/coupon/detail/index?couponChannelId=${
  646. e.currentTarget.dataset.couponchannelid
  647. }&couponId=${e.currentTarget.dataset.couponid}`
  648. });
  649. },
  650. //浮层广告
  651. getGg: function(token) {
  652. let that = this
  653. Http.get({
  654. url: config.api.getGg,
  655. data: {
  656. token: token,
  657. appId: config.weapp.AppId,
  658. openId: that.data.openId
  659. }
  660. }).then(res => {
  661. console.log(res)
  662. if (res.data.id) {
  663. that.setData({
  664. showGg: true,
  665. })
  666. console.log(that.data.showGg, 1111111111111)
  667. } else {
  668. that.setData({
  669. showGg: false
  670. })
  671. that.getGameOne(app.globalData.token)
  672. console.log(that.data.showGg, 222222222222222222)
  673. }
  674. that.setData({
  675. ggdata: res.data
  676. })
  677. })
  678. .catch(err => {
  679. this.setData({
  680. showGg: false
  681. })
  682. that.getGameOne(app.globalData.token)
  683. that.alphaClick1();
  684. })
  685. },
  686. /**
  687. * 刷新
  688. */
  689. onPullDownRefresh: function(e) {
  690. let that = this;
  691. that.getWeapNote();
  692. that.setData({
  693. page: 1
  694. })
  695. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  696. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  697. } else {
  698. this.getWeapNote()
  699. }
  700. if (that.data.code == 0 || that.data.code == undefined) {
  701. that.selectComponent("#lists").getList(0, 1, "refresh");
  702. wx.stopPullDownRefresh();
  703. } else {
  704. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  705. wx.stopPullDownRefresh();
  706. };
  707. // 砍价下拉刷新
  708. // that.selectComponent("#bargain").getList();
  709. // that.selectComponent("#spellGroup").getList();
  710. // that.selectComponent("#rushtobyCard").getList();
  711. wx.stopPullDownRefresh();
  712. //爆款专区下拉刷新
  713. that.selectComponent("#hot").getList();
  714. that.getxsList();
  715. that.topicShow();
  716. },
  717. //加载更多
  718. onReachBottom: function() {
  719. let that = this;
  720. that.data.page++;
  721. that.setData({
  722. page: that.data.page
  723. });
  724. console.log("加载更多页数" + that.data.page);
  725. console.log("加载更多key" + that.data.code);
  726. //父组件获得子组件的方法
  727. //如果code == 0
  728. if (that.data.code == 0 || that.data.code == undefined) {
  729. that.selectComponent("#lists").getList(0, that.data.page);
  730. } else {
  731. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  732. }
  733. },
  734. // 用户点击右上角分享
  735. onShareAppMessage: function() {
  736. return {
  737. title: this.data.weappShareTitle,
  738. imageUrl: this.data.weappShareCoverImg,
  739. // desc: this.data.desc,
  740. success: function(res) {
  741. wx.showToast({
  742. title: "分享成功",
  743. duration: 1000,
  744. icon: "success"
  745. });
  746. }
  747. };
  748. }
  749. });