C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

663 строки
17 KiB

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