index.js 2.6 KB

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