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.

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