list.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. keyword: ['','',''],
  8. tab: 0,
  9. url:['portal/articles/index','activity/activity/index','activity/activity_review/index'],
  10. is_first: [true,true,true],
  11. list: [[],[],[]],
  12. no_more:[false,false,false],
  13. page:[1,1,1],
  14. custombar: app.globalData.CustomBar,
  15. nav_top: 0,
  16. nav_fixed: false,
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. if (options.tab) {
  23. this.setData({tab:options.tab});
  24. }
  25. if (options.keyword) {
  26. let keyword = this.data.keyword;
  27. keyword[this.data.tab] = options.keyword;
  28. this.setData({keyword:keyword});
  29. }
  30. //获取导航栏top
  31. let query = wx.createSelectorQuery()
  32. query.select('#nav').boundingClientRect( (rect) => {
  33. this.setData({nav_top:rect.top - this.data.custombar});
  34. }).exec()
  35. //获取数据
  36. let is_first = this.data.is_first;
  37. is_first[this.data.tab] = false;
  38. this.setData({is_first:is_first});
  39. this.getList();
  40. },
  41. //tab切换
  42. tabSelect(e) {
  43. let tab = e.currentTarget.dataset.tab;
  44. this.setData({tab:tab});
  45. let is_first = this.data.is_first;
  46. if (is_first[tab]) {
  47. is_first[tab] = false;
  48. this.setData({is_first:is_first});
  49. this.getList();
  50. }
  51. },
  52. //搜索
  53. bindInput(e) {
  54. let keyword = this.data.keyword;
  55. keyword[this.data.tab] = e.detail.value;
  56. this.setData({keyword:keyword});
  57. },
  58. bindSearch(){
  59. this.resetParam();
  60. this.getList();
  61. },
  62. //获取数据
  63. getList() {
  64. let self = this;
  65. let tab = this.data.tab;
  66. let no_more = this.data.no_more;
  67. let url = this.data.url;
  68. //没有下一页
  69. if (no_more[tab]) {
  70. return false;
  71. }
  72. //获取数据
  73. app.post(url[tab],{
  74. page:self.data.page[tab],
  75. keyword:self.data.keyword[tab],
  76. },function(res){
  77. if (res.length < 10) {
  78. no_more[tab] = true;
  79. self.setData({no_more:no_more});
  80. }
  81. let list = self.data.list;
  82. list[tab] = list[tab].concat(res);
  83. let page = self.data.page;
  84. page[tab]++;
  85. self.setData({list:list,page:page});
  86. })
  87. },
  88. //重置参数
  89. resetParam() {
  90. let tab = this.data.tab;
  91. let list = this.data.list;
  92. list[tab] = [];
  93. let no_more = this.data.no_more;
  94. no_more[tab] = false;
  95. let page = this.data.page;
  96. page[tab] = 1;
  97. this.setData({list:list,no_more:no_more,page:page});
  98. },
  99. resetKeyword() {
  100. let keyword = this.data.keyword;
  101. keyword[this.data.tab] = '';
  102. this.setData({keyword:keyword});
  103. },
  104. //滚动事件
  105. onPageScroll(e) {
  106. if (e.scrollTop >= this.data.nav_top) {
  107. if (!this.data.nav_fixed) {
  108. this.setData({nav_fixed: true});
  109. }
  110. } else {
  111. if (this.data.nav_fixed) {
  112. this.setData({nav_fixed:false});
  113. }
  114. }
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. this.resetParam();
  121. this.resetKeyword();
  122. this.getList();
  123. wx.stopPullDownRefresh();
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. this.getList();
  130. },
  131. //跳转
  132. toRcs() {
  133. wx.navigateTo({
  134. url: '/pages/webview/rcs/rcs',
  135. })
  136. },
  137. toRecuperate() {
  138. wx.navigateTo({
  139. url: '/pages/webview/recuperate/recuperate',
  140. })
  141. },
  142. toBusiness() {
  143. wx.navigateTo({
  144. url: '/pages/business/home/home',
  145. })
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. return {
  152. title: "晋爱人才",
  153. path: "/pages/home/home/home",
  154. };
  155. },
  156. })