list.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const util = require("../../../../utils/util.js");
  2. Page({
  3. data: {
  4. data:{
  5. pageIndex: 1,
  6. pageSize: 10,
  7. courseId:'',
  8. playerId:''
  9. },
  10. list: [],
  11. bottom:true
  12. },
  13. onLoad(options){
  14. this.data.data.courseId = options.courseId; this.data.data.playerId = options.playerId;
  15. this.setData({ data: this.data.data })
  16. },
  17. onShow() {
  18. this.data.data.pageIndex=1;
  19. this.setData({data:this.data.data})
  20. this.getListData(false);
  21. },
  22. onPullDownRefresh() {
  23. var self = this;
  24. wx.showNavigationBarLoading();
  25. setTimeout(function () {
  26. self.data.data.pageIndex = 1;
  27. self.setData({ data: self.data.data });
  28. self.getListData(false);
  29. wx.hideNavigationBarLoading();
  30. wx.stopPullDownRefresh();
  31. }, 1000);
  32. },
  33. onReachBottom() {
  34. var self = this;
  35. if (self.data.bottom == false) return false;
  36. setTimeout(function () {
  37. self.data.data.pageIndex++;
  38. self.setData({ data: self.data.data });
  39. self.getListData(true);
  40. }, 1000);
  41. },
  42. getListData(load){
  43. let that = this;
  44. util.ajax({
  45. func: "v2/course/read/list",
  46. data: {'courseId': that.data.data.courseId, 'playerId': that.data.data.playerId, 'pageIndex': that.data.data.pageIndex, 'pageSize': that.data.data.pageSize},
  47. load: load
  48. }, function (res) {
  49. if (res.code == 0) {
  50. let newData = res.data.list, bottom = true;
  51. let list = !load ? newData : [...that.data.list, ...newData];
  52. if (newData.length < that.data.data.pageSize && list.length > that.data.data.pageSize) bottom = false;
  53. that.setData({ list, bottom })
  54. }else{
  55. util.showTips(res.reason);
  56. }
  57. });
  58. }
  59. })