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.

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