list.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '组队信息', leftArrow: true, useBar: false },
  8. list: [],
  9. total: 0,
  10. page: 0,
  11. skip: 0,
  12. limit: 10,
  13. statusList: []
  14. },
  15. // 返回
  16. back: function () {
  17. wx.navigateBack({ delta: 1 })
  18. },
  19. //通用添加 详细信息
  20. toCommon: function (e) {
  21. const that = this;
  22. const { item, route } = e.currentTarget.dataset;
  23. that.setData({ skip: 0, page: 0, list: [] });
  24. wx.navigateTo({ url: `/pagesMatch/${route}?id=${item && item._id ? item._id : ''}` })
  25. },
  26. // 分页
  27. toPage: function () {
  28. const that = this;
  29. let list = that.data.list;
  30. let limit = that.data.limit;
  31. if (that.data.total > list.length) {
  32. wx.showLoading({ title: '加载中', mask: true })
  33. let page = that.data.page + 1;
  34. that.setData({ page: page })
  35. let skip = page * limit;
  36. that.setData({ skip: skip })
  37. that.watchLogin();
  38. wx.hideLoading()
  39. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: async function () {
  55. const that = this;
  56. // 查询其他信息
  57. await that.searchOther();
  58. // 监听用户是否登录
  59. await that.watchLogin();
  60. },
  61. searchOther: async function () {
  62. const that = this;
  63. let arr;
  64. // 状态
  65. arr = await app.$get(`/dict`, { code: "examine_status" });
  66. if (arr.errcode == '0' && arr.total > 0) { let list = arr.data[0].list; that.setData({ statusList: list }); }
  67. },
  68. // 监听用户是否登录
  69. watchLogin: async function () {
  70. const that = this;
  71. wx.getStorage({
  72. key: 'raceuser',
  73. success: async res => {
  74. let info = { skip: that.data.skip, limit: that.data.limit, user_id: res.data._id };
  75. let arr = await app.$get(`/teamApply`, { ...info }, 'race');
  76. if (arr.errcode == '0') {
  77. let list = [...that.data.list, ...arr.data];
  78. for (const val of list) { val.zhStatus = that.searchStatus(val.status) }
  79. that.setData({ list: list })
  80. that.setData({ total: arr.total })
  81. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  82. },
  83. fail: async res => {
  84. wx.redirectTo({ url: '/pages/index/index' })
  85. }
  86. })
  87. },
  88. searchStatus: function (e) {
  89. const that = this;
  90. let data = that.data.statusList.find(i => i.value == e);
  91. if (data) return data.label;
  92. else return '暂无';
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. const that = this;
  99. that.setData({ skip: 0, page: 0, list: [] })
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })