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.

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