C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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