index.js 1.7 KB

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