C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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