C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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