searchTwo.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // pages/experience/activityinfo/activityinfo.js
  2. var app = getApp();
  3. var util = require("../../../../utils/util.js")
  4. Page({
  5. data: {
  6. appAssetsUrl:app.appAssetsUrl,
  7. nodata: util.nodata(),
  8. typeList: [{
  9. name: '兼职'
  10. }, {
  11. name: '活动'
  12. }],
  13. typeListIndex: 0,
  14. //兼职
  15. params1:{
  16. pageNum:1,
  17. pageSize:10,
  18. city:''
  19. },
  20. //活动
  21. params2:{
  22. page:1,
  23. limit:10,
  24. city:'',
  25. status:'',
  26. time:''
  27. },
  28. keyword: '',
  29. total:{
  30. currPage: 0,
  31. totalPage: 0
  32. },
  33. noMore:false,
  34. listData:[]
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. let cityData = wx.getStorageSync("CHOOSECITY");
  41. this.setData({
  42. ['params1.city']: cityData.cityId,
  43. ['params2.city']: cityData.cityId,
  44. })
  45. let that = this;
  46. that.loadList(true);
  47. wx.getSystemInfo({
  48. success: function (res) {
  49. that.setData({
  50. scrollHeight: res.windowHeight
  51. });
  52. }
  53. });
  54. },
  55. loadList(isRefresh) {
  56. let that = this;
  57. if (!isRefresh && this.data.noMore) {
  58. wx.showToast({
  59. title: '没有更多了~',
  60. icon: 'none'
  61. })
  62. return false;
  63. }
  64. let nowCity = wx.getStorageSync("CHOOSECITY");
  65. let url = this.data.typeListIndex==0?'home/label':'act/list'
  66. let params = this.data.typeListIndex==0?{
  67. ...this.data.params1,
  68. pageNum: isRefresh?1:this.data.params1.pageNum+1
  69. }:{
  70. ...this.data.params2,
  71. page: isRefresh?1:this.data.params2.page+1
  72. };
  73. this.setData({
  74. listData:isRefresh?[]:this.data.listData,
  75. [this.data.typeListIndex==0?'params1':'params2']: params,
  76. noMore:isRefresh?false:this.data.noMore
  77. })
  78. this.setData({
  79. listData: isRefresh ? [] : this.data.listData,
  80. noMore: isRefresh ? false : this.data.noMore,
  81. params:{
  82. ...params,
  83. keyword: this.data.keyword
  84. }
  85. })
  86. wx.showLoading({
  87. title: '努力加载中...',
  88. })
  89. app._post_form(url, '', this.data.params,
  90. function(res) {
  91. if (res.code == 0) {
  92. //防止触发onReachBottom钩子导致数据重复
  93. if(res.page.list.length>0 && that.data.listData.length>0 && res.page.list[0].id == that.data.listData[0].id){
  94. return ;
  95. }
  96. let listData = that.data.listData;
  97. listData.push(...res.page.list);
  98. that.setData({
  99. listData,
  100. currPage: res.page.currPage,
  101. totalPage: res.page.totalPage,
  102. noMore: res.page.totalPage == res.page.currPage
  103. })
  104. }
  105. })
  106. },
  107. keywordInput(e){
  108. this.setData({
  109. keyword: e.detail.value
  110. })
  111. },
  112. search(){
  113. this.loadList(true)
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. this.loadList();
  145. },
  146. /**
  147. * 用户点击右上角分享
  148. */
  149. onShareAppMessage: function () {
  150. },
  151. switchType(e) {
  152. if (e) {
  153. let typeListIndex = e.currentTarget.dataset.index;
  154. this.setData({
  155. typeListIndex
  156. })
  157. this.loadList(true);
  158. }
  159. }
  160. })