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.

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