index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '首页', leftArrow: false, useBar: true },
  5. lingdang: '/image/lingdang.png',
  6. user: {},
  7. list: [],
  8. page: 0,
  9. skip: 0,
  10. limit: 5,
  11. total: 0,
  12. },
  13. // 跳转菜单
  14. tabPath(e) {
  15. let { route } = e.detail.detail;
  16. if (route) wx.redirectTo({ url: `/${route}` })
  17. },
  18. toView: function (e) {
  19. const { item } = e.currentTarget.dataset;
  20. wx.navigateTo({ url: `/pages/match/info?id=${item._id}` })
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) { },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady: function () { },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function () {
  34. const that = this;
  35. // 监听用户是否登录
  36. that.watchLogin();
  37. },
  38. // 监听用户是否登录
  39. watchLogin: async function () {
  40. const that = this;
  41. wx.getStorage({
  42. key: 'user',
  43. success: async res => {
  44. let info = { skip: that.data.skip, limit: that.data.limit };
  45. const arr = await app.$get(`/newCourt/api/match`, { ...info });
  46. if (arr.errcode == '0') {
  47. let arr1 = that.data.list;
  48. let arr2 = arr.data;
  49. arr1 = arr1.concat(arr2);
  50. that.setData({ list: arr1 })
  51. }
  52. const aee = await app.$get(`/newCourt/api/match`);
  53. if (aee.errcode == '0') {
  54. that.setData({ total: aee.data.length })
  55. }
  56. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  57. },
  58. fail: async res => {
  59. wx.redirectTo({ url: '/pages/index/index' })
  60. }
  61. })
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. const that = this;
  68. if (that.data.total > that.data.list.length) {
  69. wx.showLoading({ title: '加载中', mask: true })
  70. let page = that.data.page + 1; //获取当前页数并+1
  71. that.setData({ page: page })//更新当前页数
  72. let limit = that.data.limit;
  73. let skip = page * limit;
  74. that.setData({ skip: skip })
  75. that.watchLogin();
  76. wx.hideLoading()
  77. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. }
  99. })