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.

656 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. let that = this;
  189. let optionss;
  190. if (wx.getStorageSync('options')){
  191. optionss = JSON.parse(wx.getStorageSync('options'));
  192. }
  193. if (options.played == "true") {
  194. that.setData({
  195. played: true
  196. })
  197. }
  198. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  199. that.setData({
  200. optionsData: optionss
  201. })
  202. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  203. } else {
  204. that.getWeapNote()
  205. }
  206. //获取条形码
  207. // util.barcode("barcode", optionss.quancode, 510, 100);
  208. },
  209. onShow: function() {
  210. if (typeof this.getTabBar === 'function' &&
  211. this.getTabBar()) {
  212. this.getTabBar().setData({
  213. selected: 0
  214. })
  215. }
  216. let that = this;
  217. that.setData({
  218. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false
  219. })
  220. /**
  221. * couponNum 是否有普通的优惠券购买
  222. * couponNum2 是否有新买的消费卡
  223. */
  224. let num = wx.getStorageSync('couponNum');
  225. let num1 = wx.getStorageSync('couponNum2');
  226. if (num == 'couponNum' || num1 == 'couponNum2') {
  227. wx.showTabBarRedDot({
  228. index: 3
  229. })
  230. } else {
  231. wx.hideTabBarRedDot({
  232. index: 3
  233. })
  234. }
  235. if (app.globalData.score) {
  236. that.setData({
  237. fistLogin: app.globalData.score
  238. })
  239. }
  240. // 如果有游戏
  241. setTimeout(function() {
  242. that.alphaClick();
  243. }, 8000)
  244. },
  245. getmemberId: function(token) {
  246. let that = this;
  247. Http.get({
  248. url: config.api.getScore,
  249. data: {
  250. token: token
  251. }
  252. }).then(res => {
  253. that.setData({
  254. levelName: res.data.levelName,
  255. upgradePercent: res.data.upgradePercent,
  256. upgradeScore: res.data.upgradeScore,
  257. memberId: res.data.id
  258. })
  259. })
  260. .catch(err => {
  261. wx.showModal({
  262. title: '提示',
  263. content: err.message,
  264. showCancel: false
  265. })
  266. })
  267. },
  268. gotoChengzhangzhi: function() {
  269. wx.navigateTo({
  270. url: '/pages/czdetail/czdetail',
  271. })
  272. },
  273. gotoBargain: function () {
  274. wx.navigateTo({
  275. url: '/pages/bargain/bargain',
  276. })
  277. },
  278. gotoSpellGroup: function () {
  279. wx.navigateTo({
  280. url: '/pages/spellGroup/spellGroup',
  281. })
  282. },
  283. gotoCard: function () {
  284. wx.navigateTo({
  285. url: '/pages/discountCardList/discountCardList',
  286. })
  287. },
  288. // gotoGame: function () {
  289. // wx.navigateTo({
  290. // url: '/pages/game/index',
  291. // })
  292. // },
  293. gotoJfsc: function () {
  294. wx.navigateTo({
  295. url: '/pages/integralmall/index',
  296. })
  297. },
  298. /**
  299. *
  300. * @param {code,page}
  301. * 子组件向父组件传值
  302. */
  303. onGetCode: function(e) {
  304. this.setData({
  305. code: e.detail.val,
  306. page: e.detail.pageNum,
  307. });
  308. console.log(e.detail.val)
  309. console.log(e.detail.pageNum)
  310. },
  311. getWeapNote: function(couponChannelId, couponId, orderId) {
  312. var that = this;
  313. // 登录
  314. that.getmemberId(app.globalData.token);
  315. that.getBannerlist();
  316. that.topicShow();
  317. that.getxsList();
  318. that.getMallInfo(app.globalData.token);
  319. if (app.couponChannelListCallback) {
  320. app.couponChannelListCallback(app.globalData.token);
  321. }
  322. if (app.couponListCallback) {
  323. app.couponListCallback(app.globalData.token);
  324. }
  325. if (app.businessListCallback) {
  326. app.businessListCallback(app.globalData.token);
  327. }
  328. Http.get({
  329. url: config.api.getWeapNote,
  330. data: {
  331. appId: config.weapp.AppId,
  332. }
  333. })
  334. .then(res => {
  335. that.getGameOne(app.globalData.token)
  336. that.getStaticGame(app.globalData.token)
  337. let weapNote = JSON.parse(res.data.weapNote);
  338. that.setData({
  339. desc: weapNote.firstpage.desc,
  340. title: weapNote.firstpage.title
  341. })
  342. })
  343. .catch(err => {
  344. that.getGameOne(app.globalData.token)
  345. that.getStaticGame(app.globalData.token)
  346. wx.showModal({
  347. title: "提示",
  348. content: err.errMsg,
  349. showCancel: false
  350. });
  351. });
  352. },
  353. getStaticGame(token) {
  354. let _this = this;
  355. Http.get({
  356. url: config.api.getGame,
  357. data: {
  358. triggleAction: 2, // 固定入口
  359. token: token
  360. }
  361. }).then(res => {
  362. if (res.data.id) {
  363. _this.setData({
  364. showIf: true,
  365. newUrl: res.data.imgUrl
  366. })
  367. } else {
  368. _this.setData({
  369. showIf: false
  370. })
  371. }
  372. _this.setData({
  373. staticGamedata: res.data
  374. })
  375. })
  376. .catch(err => {
  377. _this.setData({
  378. showIf: false
  379. })
  380. console.log(err)
  381. })
  382. },
  383. getGameOne: function(token) {
  384. let _this = this;
  385. Http.get({
  386. url: config.api.getGame,
  387. data: {
  388. triggleAction: 1, // 登录触发
  389. token: token
  390. }
  391. }).then(res => {
  392. if (res.data.id) {
  393. _this.setData({
  394. showGame: true,
  395. })
  396. } else {
  397. _this.setData({
  398. showGame: false
  399. })
  400. }
  401. _this.setData({
  402. gamedata: res.data
  403. })
  404. })
  405. .catch(err => {
  406. _this.setData({
  407. showGame: false
  408. })
  409. this.alphaClick();
  410. })
  411. },
  412. /**
  413. * mallinfo
  414. */
  415. getMallInfo: function(token) {
  416. let that = this;
  417. Http.get({
  418. url: config.api.getMallInfo,
  419. data: {
  420. token: token,
  421. }
  422. }).then(res => {
  423. that.setData({
  424. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  425. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  426. });
  427. })
  428. .catch(err => {
  429. // 不需要错误提示
  430. });
  431. },
  432. //获取限时抢购列表
  433. getxsList(){
  434. let that = this;
  435. Http.get({
  436. url: config.api.couponChannelList,
  437. data: {
  438. pageNum: 1,
  439. pageSize: 3,
  440. targetAd: 2
  441. }
  442. }).then(res => {
  443. if (res && res.data.total>0) {
  444. that.setData({
  445. xslist: res.data.list,
  446. showQg:true
  447. });
  448. }else{
  449. that.setData({
  450. showQg:false
  451. })
  452. }
  453. })
  454. .catch(err => {
  455. console.log(err)
  456. wx.showToast({
  457. title: err.errMsg,
  458. icon: 'none',
  459. duration: 2000,
  460. mask: false
  461. });
  462. })
  463. },
  464. /**
  465. * banner
  466. */
  467. getBannerlist: function() {
  468. let that = this;
  469. Http.get({
  470. url: config.api.bannerlist,
  471. data: {
  472. pageNum: 1,
  473. pageSize: 7
  474. }
  475. }).then(res => {
  476. that.getmemberId(app.globalData.token);
  477. // that.checkUserCarStatus();
  478. that.setData({
  479. list: res.data.list
  480. });
  481. })
  482. .catch(err => {
  483. that.getmemberId(app.globalData.token);
  484. // that.checkUserCarStatus();
  485. });
  486. },
  487. // 专题显示
  488. topicShow: function() {
  489. let that = this;
  490. Http.get({
  491. url: config.api.topicShow,
  492. data: {
  493. token: app.globalData.token
  494. }
  495. }).then(res => {
  496. if (res && res.data) {
  497. that.setData({
  498. name: res.data.name,
  499. cover: res.data.cover,
  500. id: res.data.id,
  501. showTopic: true
  502. })
  503. } else {
  504. that.setData({
  505. showTopic: false
  506. })
  507. }
  508. })
  509. .catch(err => {
  510. console.log(err);
  511. })
  512. },
  513. gotoTopic() {
  514. wx.navigateTo({
  515. url: `/pages/topicDetail/index?id=${this.data.id}`
  516. })
  517. },
  518. /**
  519. * 检查用户是否有车
  520. */
  521. // checkUserCarStatus: function() {
  522. // var that = this;
  523. // Http.get({
  524. // url: config.api.userCarCount,
  525. // data: {}
  526. // }).then(res => {
  527. // if (res.data > 0) {
  528. // // 用户名下有车
  529. // app.globalData.phone = res.data.phone;
  530. // app.globalData.supportCar = true;
  531. // // 共同登录
  532. // that.userCarLogin();
  533. // }
  534. // });
  535. // },
  536. /**
  537. * car共同登录
  538. */
  539. // userCarLogin: function() {
  540. // var that = this;
  541. // if (!app.globalData.carLogin) {
  542. // // 共同登录
  543. // Http.post({
  544. // url: config.api.carInit,
  545. // data: {
  546. // phone: app.globalData.phone
  547. // }
  548. // }).then(res => {
  549. // app.globalData.carLogin = true;
  550. // app.globalData.parkVendor = res.data.vendor;
  551. // if (res.data.token != "undefined") {
  552. // app.globalData.etcpToken = res.data.token;
  553. // }
  554. // });
  555. // }
  556. // },
  557. /**
  558. * 获取用户信息
  559. */
  560. // getUserInfo: function() {
  561. // // 获取用户信息
  562. // wx.getSetting({
  563. // success: res => {
  564. // if (res.authSetting["scope.userInfo"]) {
  565. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  566. // wx.getUserInfo({
  567. // success: res => {
  568. // // 可以将 res 发送给后台解码出 unionId
  569. // }
  570. // });
  571. // }
  572. // }
  573. // });
  574. // },
  575. gotoBargain: function() {
  576. wx.navigateTo({
  577. url: '/pages/bargain/bargain'
  578. })
  579. },
  580. //限时抢购的详情页面
  581. gotodetail: function (e) {
  582. wx.navigateTo({
  583. url: `/pages/coupon/detail/index?couponChannelId=${
  584. e.currentTarget.dataset.couponchannelid
  585. }&couponId=${e.currentTarget.dataset.couponid}`
  586. });
  587. },
  588. /**
  589. * 刷新
  590. */
  591. onPullDownRefresh: function(e) {
  592. let that = this;
  593. that.getWeapNote();
  594. that.setData({
  595. page: 1
  596. })
  597. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  598. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  599. } else {
  600. this.getWeapNote()
  601. }
  602. if (that.data.code == 0 || that.data.code == undefined) {
  603. that.selectComponent("#lists").getList(0, 1, "refresh");
  604. wx.stopPullDownRefresh();
  605. } else {
  606. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  607. wx.stopPullDownRefresh();
  608. };
  609. // 砍价下拉刷新
  610. // that.selectComponent("#bargain").getList();
  611. // that.selectComponent("#spellGroup").getList();
  612. // that.selectComponent("#rushtobyCard").getList();
  613. wx.stopPullDownRefresh();
  614. //爆款专区下拉刷新
  615. that.selectComponent("#hot").getList();
  616. that.getxsList();
  617. that.topicShow();
  618. },
  619. //加载更多
  620. onReachBottom: function() {
  621. let that = this;
  622. that.data.page++;
  623. that.setData({
  624. page: that.data.page
  625. });
  626. console.log("加载更多页数" + that.data.page);
  627. console.log("加载更多key" + that.data.code);
  628. //父组件获得子组件的方法
  629. //如果code == 0
  630. if (that.data.code == 0 || that.data.code == undefined) {
  631. that.selectComponent("#lists").getList(0, that.data.page);
  632. } else {
  633. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  634. }
  635. },
  636. // 用户点击右上角分享
  637. onShareAppMessage: function() {
  638. return {
  639. title: this.data.weappShareTitle,
  640. imageUrl: this.data.weappShareCoverImg,
  641. // desc: this.data.desc,
  642. success: function(res) {
  643. wx.showToast({
  644. title: "分享成功",
  645. duration: 1000,
  646. icon: "success"
  647. });
  648. }
  649. };
  650. }
  651. });