home.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. list: [],
  8. page: 1,
  9. no_more: false,
  10. keyword: '',
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. if (options.keyword) {
  17. this.setData({keyword:options.keyword});
  18. }
  19. this.getList();
  20. },
  21. /**
  22. * 页面相关事件处理函数--监听用户下拉动作
  23. */
  24. onPullDownRefresh: function () {
  25. this.setData({list:[],page:1,no_more:false,keyword:''});
  26. this.getList();
  27. wx.stopPullDownRefresh();
  28. },
  29. /**
  30. * 页面上拉触底事件的处理函数
  31. */
  32. onReachBottom: function () {
  33. this.getList();
  34. },
  35. /**
  36. * 用户点击右上角分享
  37. */
  38. onShareAppMessage() {
  39. return {
  40. title: "晋爱人才",
  41. path: "/pages/home/home/home",
  42. };
  43. },
  44. //列表
  45. getList() {
  46. var self = this;
  47. if (self.data.no_more) {
  48. return false;
  49. }
  50. app.post('portal/articles/index',{
  51. page:self.data.page,
  52. keyword:self.data.keyword,
  53. },function(res){
  54. if (res.length < 10) {
  55. self.setData({no_more:true});
  56. }
  57. let list = self.data.list;
  58. list = list.concat(res);
  59. let page = self.data.page;
  60. page++;
  61. self.setData({list:list,page:page});
  62. });
  63. },
  64. //搜索
  65. bindSearch() {
  66. this.setData({list:[],page:1,no_more:false});
  67. this.getList();
  68. }
  69. })