C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

790 rader
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. // console.log(Http.headers.token, "?")
  261. },
  262. /**
  263. * 获得经纬度
  264. */
  265. getLocation() {
  266. let that = this;
  267. wx.getLocation({
  268. type: "wgs84",
  269. success: function(res) {
  270. console.log(res, 9999)
  271. if (res && res.longitude && res.latitude) {
  272. Http.post({
  273. url: config.api.updateLBS,
  274. data: {
  275. latitude: res.latitude,
  276. longitude: res.longitude
  277. }
  278. }).then(res => {
  279. console.log(res, 9999)
  280. })
  281. }
  282. },
  283. fail: error => {
  284. console.log(error);
  285. }
  286. })
  287. },
  288. onUnload(){
  289. wx.removeStorageSync('squareList')
  290. },
  291. onShow: function() {
  292. if (typeof this.getTabBar === 'function' &&
  293. this.getTabBar()) {
  294. this.getTabBar().setData({
  295. selected: 0
  296. })
  297. }
  298. let that = this;
  299. that.setData({
  300. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  301. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  302. })
  303. /**
  304. * couponNum 是否有普通的优惠券购买
  305. * couponNum2 是否有新买的消费卡
  306. */
  307. let num = wx.getStorageSync('couponNum');
  308. let num1 = wx.getStorageSync('couponNum2');
  309. if (num == 'couponNum' || num1 == 'couponNum2') {
  310. wx.showTabBarRedDot({
  311. index: 3
  312. })
  313. } else {
  314. wx.hideTabBarRedDot({
  315. index: 3
  316. })
  317. }
  318. if (app.globalData.score) {
  319. that.setData({
  320. fistLogin: app.globalData.score
  321. })
  322. }
  323. // 如果有游戏
  324. setTimeout(function() {
  325. that.alphaClick();
  326. }, 8000)
  327. // 如果有广告
  328. setTimeout(function() {
  329. // debugger
  330. that.alphaClick1();
  331. }, 8000)
  332. },
  333. getmemberId: function(token) {
  334. let that = this;
  335. Http.get({
  336. url: config.api.getScore,
  337. data: {
  338. token: token
  339. }
  340. }).then(res => {
  341. that.setData({
  342. levelName: res.data.levelName,
  343. upgradePercent: res.data.upgradePercent,
  344. upgradeScore: res.data.upgradeScore,
  345. memberId: res.data.id,
  346. })
  347. })
  348. .catch(err => {
  349. wx.showModal({
  350. title: '提示',
  351. content: err.message,
  352. showCancel: false
  353. })
  354. })
  355. },
  356. gotoChengzhangzhi: function() {
  357. wx.navigateTo({
  358. url: '/pages/czdetail/czdetail',
  359. })
  360. },
  361. gotoBargain: function() {
  362. wx.navigateTo({
  363. url: '/pages/bargain/bargain',
  364. })
  365. },
  366. gotoSpellGroup: function() {
  367. wx.navigateTo({
  368. url: '/pages/spellGroup/spellGroup',
  369. })
  370. },
  371. gotoCard: function() {
  372. wx.navigateTo({
  373. url: '/pages/discountCardList/discountCardList',
  374. })
  375. },
  376. // gotoGame: function () {
  377. // wx.navigateTo({
  378. // url: '/pages/game/index',
  379. // })
  380. // },
  381. gotoJfsc: function() {
  382. wx.navigateTo({
  383. url: '/pages/integralmall/index',
  384. })
  385. },
  386. /**
  387. *
  388. * @param {code,page}
  389. * 子组件向父组件传值
  390. */
  391. onGetCode: function(e) {
  392. this.setData({
  393. code: e.detail.val,
  394. page: e.detail.pageNum,
  395. });
  396. console.log(e.detail.val)
  397. console.log(e.detail.pageNum)
  398. },
  399. getWeapNote: function(couponChannelId, couponId, orderId) {
  400. var that = this;
  401. // 登录
  402. that.getmemberId(app.globalData.token);
  403. that.getBannerlist();
  404. that.topicShow();
  405. that.getxsList();
  406. that.getMallInfo(app.globalData.token);
  407. if (app.couponChannelListCallback) {
  408. app.couponChannelListCallback(app.globalData.token);
  409. }
  410. if (app.couponListCallback) {
  411. app.couponListCallback(app.globalData.token);
  412. }
  413. if (app.businessListCallback) {
  414. app.businessListCallback(app.globalData.token);
  415. }
  416. Http.get({
  417. url: config.api.getWeapNote,
  418. data: {
  419. appId: config.weapp.AppId,
  420. }
  421. })
  422. .then(res => {
  423. console.log(res)
  424. // that.getGameOne(app.globalData.token)
  425. that.getStaticGame(app.globalData.token)
  426. that.getGg(app.globalData.token)
  427. let weapNote = JSON.parse(res.data.weapNote);
  428. that.setData({
  429. desc: weapNote.firstpage.desc,
  430. title: weapNote.firstpage.title
  431. })
  432. })
  433. .catch(err => {
  434. // that.getGameOne(app.globalData.token)
  435. that.getStaticGame(app.globalData.token)
  436. that.getGg(app.globalData.token)
  437. wx.showModal({
  438. title: "提示",
  439. content: err.errMsg,
  440. showCancel: false
  441. });
  442. });
  443. },
  444. getStaticGame(token) {
  445. let _this = this;
  446. Http.get({
  447. url: config.api.getGame,
  448. data: {
  449. triggleAction: 2, // 固定入口
  450. token: token
  451. }
  452. }).then(res => {
  453. if (res.data.id) {
  454. _this.setData({
  455. showIf: true,
  456. newUrl: res.data.imgUrl
  457. })
  458. } else {
  459. _this.setData({
  460. showIf: false
  461. })
  462. }
  463. _this.setData({
  464. staticGamedata: res.data
  465. })
  466. })
  467. .catch(err => {
  468. _this.setData({
  469. showIf: false
  470. })
  471. console.log(err)
  472. })
  473. },
  474. getGameOne: function(token) {
  475. let _this = this;
  476. Http.get({
  477. url: config.api.getGame,
  478. data: {
  479. triggleAction: 1, // 登录触发
  480. token: token
  481. }
  482. }).then(res => {
  483. if (res.data.id) {
  484. _this.setData({
  485. showGame: true,
  486. })
  487. } else {
  488. _this.setData({
  489. showGame: false
  490. })
  491. }
  492. _this.setData({
  493. gamedata: res.data
  494. })
  495. })
  496. .catch(err => {
  497. _this.setData({
  498. showGame: false
  499. })
  500. this.alphaClick();
  501. })
  502. },
  503. /**
  504. * mallinfo
  505. */
  506. getMallInfo: function(token) {
  507. let that = this;
  508. Http.get({
  509. url: config.api.getMallInfo,
  510. data: {
  511. token: token,
  512. }
  513. }).then(res => {
  514. that.setData({
  515. liveFlag: res.data.liveSupport ,
  516. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  517. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  518. });
  519. console.log(that.data.liveFlag,"||||")
  520. })
  521. .catch(err => {
  522. // 不需要错误提示
  523. });
  524. },
  525. //获取限时抢购列表
  526. getxsList() {
  527. let that = this;
  528. Http.get({
  529. url: config.api.couponChannelList,
  530. data: {
  531. pageNum: 1,
  532. pageSize: 3,
  533. targetAd: 2
  534. }
  535. }).then(res => {
  536. if (res && res.data.total > 0) {
  537. that.setData({
  538. xslist: res.data.list,
  539. showQg: true
  540. });
  541. } else {
  542. that.setData({
  543. showQg: false
  544. })
  545. }
  546. })
  547. .catch(err => {
  548. console.log(err)
  549. wx.showToast({
  550. title: err.errMsg,
  551. icon: 'none',
  552. duration: 2000,
  553. mask: false
  554. });
  555. })
  556. },
  557. /**
  558. * banner
  559. */
  560. getBannerlist: function() {
  561. let that = this;
  562. Http.get({
  563. url: config.api.bannerlist,
  564. data: {
  565. pageNum: 1,
  566. pageSize: 7
  567. }
  568. }).then(res => {
  569. that.getmemberId(app.globalData.token);
  570. // that.checkUserCarStatus();
  571. that.setData({
  572. list: res.data.list
  573. });
  574. })
  575. .catch(err => {
  576. that.getmemberId(app.globalData.token);
  577. // that.checkUserCarStatus();
  578. });
  579. },
  580. // 专题显示
  581. topicShow: function() {
  582. let that = this;
  583. Http.get({
  584. url: config.api.topicShow,
  585. data: {
  586. token: app.globalData.token
  587. }
  588. }).then(res => {
  589. if (res && res.data) {
  590. that.setData({
  591. name: res.data.name,
  592. cover: res.data.cover,
  593. id: res.data.id,
  594. showTopic: true
  595. })
  596. } else {
  597. that.setData({
  598. showTopic: false
  599. })
  600. }
  601. })
  602. .catch(err => {
  603. console.log(err);
  604. })
  605. },
  606. gotoTopic() {
  607. wx.navigateTo({
  608. url: `/pages/topicDetail/index?id=${this.data.id}`
  609. })
  610. },
  611. /**
  612. * 检查用户是否有车
  613. */
  614. // checkUserCarStatus: function() {
  615. // var that = this;
  616. // Http.get({
  617. // url: config.api.userCarCount,
  618. // data: {}
  619. // }).then(res => {
  620. // if (res.data > 0) {
  621. // // 用户名下有车
  622. // app.globalData.phone = res.data.phone;
  623. // app.globalData.supportCar = true;
  624. // // 共同登录
  625. // that.userCarLogin();
  626. // }
  627. // });
  628. // },
  629. /**
  630. * car共同登录
  631. */
  632. // userCarLogin: function() {
  633. // var that = this;
  634. // if (!app.globalData.carLogin) {
  635. // // 共同登录
  636. // Http.post({
  637. // url: config.api.carInit,
  638. // data: {
  639. // phone: app.globalData.phone
  640. // }
  641. // }).then(res => {
  642. // app.globalData.carLogin = true;
  643. // app.globalData.parkVendor = res.data.vendor;
  644. // if (res.data.token != "undefined") {
  645. // app.globalData.etcpToken = res.data.token;
  646. // }
  647. // });
  648. // }
  649. // },
  650. /**
  651. * 获取用户信息
  652. */
  653. // getUserInfo: function() {
  654. // // 获取用户信息
  655. // wx.getSetting({
  656. // success: res => {
  657. // if (res.authSetting["scope.userInfo"]) {
  658. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  659. // wx.getUserInfo({
  660. // success: res => {
  661. // // 可以将 res 发送给后台解码出 unionId
  662. // }
  663. // });
  664. // }
  665. // }
  666. // });
  667. // },
  668. gotoBargain: function() {
  669. wx.navigateTo({
  670. url: '/pages/bargain/bargain'
  671. })
  672. },
  673. //限时抢购的详情页面
  674. gotodetail: function(e) {
  675. wx.navigateTo({
  676. url: `/pages/coupon/detail/index?couponChannelId=${
  677. e.currentTarget.dataset.couponchannelid
  678. }&couponId=${e.currentTarget.dataset.couponid}`
  679. });
  680. },
  681. //浮层广告
  682. getGg: function(token) {
  683. let that = this
  684. Http.get({
  685. url: config.api.getGg,
  686. data: {
  687. token: token,
  688. appId: config.weapp.AppId,
  689. openId: that.data.openId
  690. }
  691. }).then(res => {
  692. console.log(res)
  693. if (res.data.id) {
  694. that.setData({
  695. showGg: true,
  696. })
  697. console.log(that.data.showGg, 1111111111111)
  698. } else {
  699. that.setData({
  700. showGg: false
  701. })
  702. that.getGameOne(app.globalData.token)
  703. console.log(that.data.showGg, 222222222222222222)
  704. }
  705. that.setData({
  706. ggdata: res.data
  707. })
  708. })
  709. .catch(err => {
  710. this.setData({
  711. showGg: false
  712. })
  713. that.getGameOne(app.globalData.token)
  714. that.alphaClick1();
  715. })
  716. },
  717. /**
  718. * 刷新
  719. */
  720. onPullDownRefresh: function(e) {
  721. let that = this;
  722. that.getWeapNote();
  723. that.setData({
  724. page: 1
  725. })
  726. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  727. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  728. } else {
  729. this.getWeapNote()
  730. }
  731. if (that.data.code == 0 || that.data.code == undefined) {
  732. that.selectComponent("#lists").getList(0, 1, "refresh");
  733. wx.stopPullDownRefresh();
  734. } else {
  735. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  736. wx.stopPullDownRefresh();
  737. };
  738. // 砍价下拉刷新
  739. // that.selectComponent("#bargain").getList();
  740. // that.selectComponent("#spellGroup").getList();
  741. // that.selectComponent("#rushtobyCard").getList();
  742. wx.stopPullDownRefresh();
  743. //爆款专区下拉刷新
  744. that.selectComponent("#hot").getList();
  745. that.getxsList();
  746. that.topicShow();
  747. },
  748. //加载更多
  749. onReachBottom: function() {
  750. let that = this;
  751. that.data.page++;
  752. that.setData({
  753. page: that.data.page
  754. });
  755. console.log("加载更多页数" + that.data.page);
  756. console.log("加载更多key" + that.data.code);
  757. //父组件获得子组件的方法
  758. //如果code == 0
  759. if (that.data.code == 0 || that.data.code == undefined) {
  760. that.selectComponent("#lists").getList(0, that.data.page);
  761. } else {
  762. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  763. }
  764. },
  765. // 用户点击右上角分享
  766. onShareAppMessage: function() {
  767. return {
  768. title: this.data.weappShareTitle,
  769. imageUrl: this.data.weappShareCoverImg,
  770. // desc: this.data.desc,
  771. success: function(res) {
  772. wx.showToast({
  773. title: "分享成功",
  774. duration: 1000,
  775. icon: "success"
  776. });
  777. }
  778. };
  779. }
  780. });