system.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const util = require('../../../utils/util.js');
  2. Page({
  3. data: {
  4. columnsIndex:0,
  5. scrollLeft:0,
  6. list: [],
  7. columns:[],
  8. imgPath: util.config.imgPath,
  9. isLoadMore: true,
  10. pageIndex: 1,
  11. pageSize: 10
  12. },
  13. onLoad() {
  14. this.getColumns();
  15. },
  16. getColumns() {
  17. let that = this;
  18. util.ajax({
  19. func:"v3/column",
  20. data:{ ctype: 0 },
  21. },function(res){
  22. if(res.code == 0){
  23. that.setData({ columns:res.data });
  24. that.getList(false);
  25. }
  26. });
  27. },
  28. getList(load) {
  29. let self = this;
  30. util.ajax({
  31. func: "article/list",
  32. data: { "cid": self.data.columns[self.data.columnsIndex].id, "pageSize": self.data.pageSize, "pageIndex": self.data.pageIndex }
  33. }, function (res) {
  34. if (res.code == 0) {
  35. let isLoadMore = true;
  36. let newData = res.data.list;
  37. let oldData = !load ? newData : [...self.data.list, ...newData];
  38. if (newData.length < self.data.pageSize || oldData.length > self.data.pageSize) {
  39. isLoadMore = false;
  40. }
  41. self.setData({ list: oldData, remark: res.data.remark, isLoadMore });
  42. } else
  43. util.showTips(res.reason);
  44. });
  45. },
  46. columnChange(e){
  47. let index = e.currentTarget.dataset.index;
  48. this.setData({ columnsIndex: index, pageIndex: 1, scrollLeft: ((index - 1) * 90)});
  49. this.getList(false);
  50. },
  51. onPullDownRefresh: function () {
  52. var self = this;
  53. wx.showNavigationBarLoading();
  54. this.setData({pageIndex:1})
  55. setTimeout(function () {
  56. self.getList(false);
  57. wx.hideNavigationBarLoading();
  58. wx.stopPullDownRefresh();
  59. }, 1500);
  60. },
  61. onReachBottom: function () {
  62. var self = this;
  63. if (self.data.isLoadMore == false) {
  64. return false;
  65. }
  66. setTimeout(function () {
  67. self.setData({ pageIndex: self.data.pageIndex + 1 });
  68. self.getList(true);
  69. }, 1000);
  70. },
  71. onShareAppMessage() {
  72. return {
  73. title: '宝贝走天下-更安全的儿童户外教育专家',
  74. path: '/pages/product/activity/system'
  75. }
  76. }
  77. })