index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const app = getApp()
  2. Page({
  3. data: {
  4. spinShow: false,
  5. loadMoreLoad: false,
  6. loadMoreTip: '暂无数据',
  7. queryParam: {
  8. pageIndex: 1,
  9. pageSize: app.globalData.pageSize
  10. },
  11. tableData: [],
  12. total: 1
  13. },
  14. onLoad: function(options) {
  15. this.setData({
  16. spinShow: true
  17. });
  18. this.search(true);
  19. },
  20. onPullDownRefresh() {
  21. this.setData({
  22. spinShow: true
  23. });
  24. if (!this.loading) {
  25. this.setData({
  26. ['queryParam.pageIndex']: 1
  27. });
  28. this.search(true)
  29. }
  30. },
  31. onReachBottom() {
  32. if (!this.loading && this.data.queryParam.pageIndex < this.data.total) {
  33. this.setData({
  34. loadMoreLoad: true,
  35. loadMoreTip: '正在加载'
  36. });
  37. this.setData({
  38. ['queryParam.pageIndex']: this.data.queryParam.pageIndex + 1
  39. });
  40. this.search(false)
  41. }
  42. },
  43. search: function(override) {
  44. let _this = this
  45. app.formPost('/api/wx/student/user/message/page', this.data.queryParam).then(res => {
  46. _this.setData({
  47. spinShow: false
  48. });
  49. wx.stopPullDownRefresh()
  50. if (res.code === 1) {
  51. const re = res.response
  52. _this.setData({
  53. ['queryParam.pageIndex']: re.pageNum,
  54. tableData: override ? re.list : this.data.tableData.concat(re.list),
  55. total: re.pages
  56. });
  57. if (re.pageNum >= re.pages) {
  58. this.setData({
  59. loadMoreLoad: false,
  60. loadMoreTip: '暂无数据'
  61. });
  62. }
  63. }
  64. }).catch(e => {
  65. _this.setData({
  66. spinShow: false
  67. });
  68. app.message(e, 'error')
  69. })
  70. }
  71. })