index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const app = getApp()
  2. Page({
  3. data: {
  4. searchInfo: {},
  5. list: [],
  6. total: 0,
  7. page: 0,
  8. skip: 0,
  9. limit: 5,
  10. statusList: []
  11. },
  12. toPath(e) {
  13. let data = e.detail;
  14. let url = `/${data.route}`;
  15. if (data.type == '0') wx.navigateTo({ url })
  16. else if (data.type == '1') wx.redirectTo({ url })
  17. else if (data.type == '2') wx.relaunch({ url })
  18. else if (data.type == '3') wx.switchTab({ url })
  19. },
  20. // 查询
  21. async toSearch(e) {
  22. const that = this;
  23. that.setData({ 'searchInfo.name': e.detail.value })
  24. that.clearPage();
  25. that.search()
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. async onLoad(options) {
  31. const that = this;
  32. wx.showLoading({ title: '加载中', mask: true })
  33. await that.searchOther()
  34. await that.search()
  35. wx.hideLoading()
  36. },
  37. // 查询通知
  38. async search() {
  39. const that = this;
  40. let info = { skip: that.data.skip, limit: that.data.limit };
  41. let res = await app.$api('match', 'GET', { ...info, ...that.data.searchInfo })
  42. if (res.errcode == '0') {
  43. let list = [...that.data.list, ...res.data]
  44. for (const val of list) {
  45. val.status_name = that.getDict(val.status, 'status')
  46. }
  47. that.setData({ list })
  48. that.setData({ total: res.total })
  49. }
  50. },
  51. // 分页-触底
  52. toLower() {
  53. const that = this;
  54. let list = that.data.list;
  55. let limit = that.data.limit;
  56. if (that.data.total > list.length) {
  57. wx.showLoading({ title: '加载中', mask: true })
  58. let page = that.data.page + 1;
  59. that.setData({ page })
  60. let skip = page * limit
  61. that.setData({ skip })
  62. that.search()
  63. wx.hideLoading()
  64. } else {
  65. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  66. }
  67. },
  68. // 分页-滚动
  69. toScroll() {
  70. // console.log('滚动');
  71. },
  72. // 字典
  73. getDict(value, model) {
  74. const that = this;
  75. if (model == 'status') {
  76. if (value) {
  77. let data = that.data.statusList.find(i => i.value == value)
  78. if (data) return data.label
  79. else return '暂无'
  80. }
  81. }
  82. },
  83. // 查询其他信息
  84. async searchOther() {
  85. const that = this;
  86. let res;
  87. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  88. if (res.errcode == '0') that.setData({ statusList: res.data })
  89. },
  90. // 清空列表
  91. clearPage() {
  92. const that = this;
  93. that.setData({ list: [] })
  94. that.setData({ skip: 0 })
  95. that.setData({ limit: 5 })
  96. that.setData({ total: 0 })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload() {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh() {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom() {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage() {
  132. }
  133. })