list.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. id:"",
  6. title:'',
  7. list:{},
  8. imgPath: util.config.imgPath,
  9. isLoadMore: true,
  10. pageIndex: 1,
  11. pageSize: 10
  12. },
  13. onLoad: function (options) {
  14. let title = decodeURIComponent(options.title);
  15. wx.setNavigationBarTitle({
  16. title: options.title
  17. });
  18. this.setData({
  19. id: options.id,
  20. title: options.title
  21. });
  22. this.getList(false);
  23. },
  24. getList(load){
  25. let self = this;
  26. util.ajax({
  27. func: "v2/categoryHomePageChallenge/articleList",
  28. data: { "id": self.data.id, "pageSize": self.data.pageSize, "pageIndex": self.data.pageIndex }
  29. }, function (res) {
  30. if (res.code == 0) {
  31. let isLoadMore = true;
  32. res.data.list.map(el => {
  33. if (!util.isEmpty(el.discount)) {
  34. let arr =[];
  35. if (el.discount.indexOf('+')==-1) {
  36. arr.push(el.discount);
  37. } else {
  38. arr=el.discount.split('+');
  39. }
  40. el.discount=arr;
  41. }
  42. });
  43. let newData = res.data.list;
  44. let oldData = !load ? newData : [...self.data.list, ...newData];
  45. console.log(oldData.length,self.data.pageSize)
  46. if (newData.length < self.data.pageSize) {
  47. isLoadMore = false;
  48. }
  49. self.setData({ list: oldData, isLoadMore: isLoadMore });
  50. }else
  51. util.showTips(res.reason);
  52. });
  53. },
  54. onPullDownRefresh: function () {
  55. var self = this;
  56. this.setData({pageIndex:1})
  57. wx.showNavigationBarLoading();
  58. setTimeout(function () {
  59. self.getList(false);
  60. wx.hideNavigationBarLoading();
  61. wx.stopPullDownRefresh();
  62. }, 1500);
  63. },
  64. onReachBottom: function () {
  65. var self = this;
  66. if (self.data.isLoadMore == false) {
  67. return false;
  68. }
  69. setTimeout(function () {
  70. self.setData({ pageIndex: self.data.pageIndex + 1 });
  71. self.getList(true);
  72. }, 1000);
  73. },
  74. onShareAppMessage() {
  75. return {
  76. title: this.data.title,
  77. path: '/pages/public/swiper/list?id='+this.data.id+('&title='+this.data.title)
  78. }
  79. }
  80. })