index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const app = getApp()
  2. import { match_status } from '../../utils/dict';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '首页', leftArrow: false, useBar: true },
  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. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. const that = this;
  33. that.watchLogin()
  34. },
  35. watchLogin: function () {
  36. const that = this;
  37. let searchInfo = that.data.searchInfo;
  38. wx.getStorage({
  39. key: 'user',
  40. success: async (res) => {
  41. let info = {};
  42. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  43. const arr = await app.$get(`/newCourt/api/match`, { ...info });
  44. if (arr.errcode == '0') {
  45. 11
  46. that.setData({ list: arr.data })
  47. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  48. },
  49. fail: async (res) => {
  50. wx.redirectTo({ url: '/pages/index/index' });
  51. },
  52. });
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. }
  89. })