index.js 2.0 KB

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