index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/search/index.js
  2. const app = getApp();
  3. var util = require("../../utils/util.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. appAssetsUrl: app.appAssetsUrl,
  10. appAssetsUrl2: app.appAssetsUrl2,
  11. appAssetsUrl3: app.appAssetsUrl3,
  12. nodata: util.nodata(),
  13. statusBarHeight: 0,
  14. staHeight: 0,
  15. shaiHeight: 0,
  16. tabsList: [
  17. { label: "潮兼职", value: 0 },
  18. { label: "最会玩", value: 1 },
  19. ],
  20. current: 0,
  21. listData: [],
  22. params: {
  23. pageNum: 1,
  24. pageSize: 10,
  25. keyword: "",
  26. city: wx.getStorageSync("CHOOSECITY").cityId
  27. },
  28. currPage: 0,
  29. totalPage: 0,
  30. noMore: false,
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad(options) {
  36. this.getList();
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady() {},
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow() {},
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide() {},
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload() {},
  54. /**
  55. * 页面相关事件处理函数--监听用户下拉动作
  56. */
  57. onPullDownRefresh() {
  58. this.setData({
  59. "params.pageNum": 1,
  60. });
  61. this.getList();
  62. setTimeout(() => {
  63. wx.stopPullDownRefresh();
  64. }, 500);
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom() {
  70. if (!(this.data.currPage < this.data.totalPage))
  71. return wx.showToast({
  72. title: "没有更多了~",
  73. icon: "none",
  74. });
  75. this.setData({
  76. "params.pageNum": this.data.params.pageNum + 1,
  77. });
  78. this.getList();
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage() {},
  84. debounce(fn, wait) {},
  85. tabChange(e) {
  86. let i = e.currentTarget.dataset.index;
  87. if (this.data.current == i) {
  88. return false;
  89. }
  90. this.setData({
  91. current: i,
  92. "params.pageNum": 1,
  93. listData: [],
  94. });
  95. this.getList();
  96. },
  97. bindKeyInput(e) {
  98. let timer = null;
  99. if (timer !== null) {
  100. clearTimeout(timer);
  101. }
  102. timer = setTimeout(() => {
  103. this.setData({
  104. "params.keyword": e.detail.value,
  105. });
  106. this.getList()
  107. }, 500);
  108. },
  109. closeSearch() {
  110. this.setData({
  111. "params.keyword": "",
  112. });
  113. this.getList();
  114. },
  115. getList() {
  116. let url;
  117. if (this.data.current == 0) {
  118. url = "home/label";
  119. } else {
  120. url = "act/list";
  121. }
  122. if (this.data.params.pageNum == 1) {
  123. this.setData({
  124. listData: [],
  125. });
  126. }
  127. wx.showLoading({
  128. title: "加载中...",
  129. });
  130. app._post_form(
  131. url,
  132. "",
  133. this.data.params,
  134. (res) => {
  135. if (res.code == 0) {
  136. if (this.data.current == 1) {
  137. res.page.list.map((v) => {
  138. v.startTime = v.startTime.replace(/-/g, ".").split(" ")[0];
  139. v.endTime = v.endTime.replace(/-/g, ".").split(" ")[0];
  140. });
  141. }
  142. let listData = this.data.listData;
  143. listData = listData.concat(res.page.list);
  144. this.setData({
  145. listData,
  146. currPage: res.page.currPage,
  147. totalPage: res.page.totalPage,
  148. noMore: res.page.totalPage == res.page.currPage,
  149. });
  150. wx.hideLoading();
  151. }
  152. },
  153. (err) => {
  154. wx.hideLoading();
  155. }
  156. );
  157. },
  158. toPartDetail(e) {
  159. wx.navigateTo({
  160. url: `/pages/home/index/partDetail/partDetail?id=${e.currentTarget.dataset.id}`,
  161. });
  162. },
  163. activeDetail(e) {
  164. if (e.currentTarget.dataset.id) {
  165. wx.navigateTo({
  166. url:
  167. "/pages/home/index/activityDetail/activityDetail?id=" +
  168. e.currentTarget.dataset.id,
  169. });
  170. }
  171. },
  172. });