index.js 2.9 KB

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