C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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