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.

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