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.

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