C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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