search.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/searchList/searchList.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. act: 0,
  10. data: [],
  11. keyword: '',
  12. type: '',
  13. left: 0,
  14. top: 0,
  15. title: '',
  16. value: '',
  17. list: [],
  18. page: 1,
  19. loading: true
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. // options.keyword='科学'
  26. this.setData({
  27. type: options.type,
  28. title: '相关'+options.title
  29. })
  30. },
  31. getData: function () {
  32. wx.showNavigationBarLoading()
  33. wx.request({
  34. url: host + '/api/search',
  35. method: 'GET',
  36. data: {
  37. keyword: this.data.keyword,
  38. type: this.data.type,
  39. page_size: 20,
  40. page: this.data.page
  41. },
  42. success: res => {
  43. wx.hideNavigationBarLoading()
  44. let list = this.data.list, data = res.data.data[0].list;
  45. if (data.length <= 0) {
  46. this.setData({
  47. loading: false
  48. })
  49. return;
  50. }
  51. for (let i = 0; i < data.length; i++) {
  52. data[i].name = data[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  53. data[i].name = "<div style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis;'>" + data[i].name + "</div>"
  54. list.push(data[i])
  55. }
  56. this.setData({
  57. title: res.data.data[0].name,
  58. value: res.data.data[0].value,
  59. list: list
  60. })
  61. },
  62. fail: function () {
  63. wx.hideLoading();
  64. wx.showToast({
  65. title: '服务器开小差啦!',
  66. icon: 'none'
  67. })
  68. }
  69. })
  70. },
  71. next: function () {
  72. if (this.data.loading) {
  73. this.setData({
  74. page: this.data.page + 1
  75. })
  76. this.getData()
  77. }
  78. },
  79. search: function () {
  80. this.setData({
  81. list:[],
  82. page:1,
  83. top: 0
  84. })
  85. this.getData();
  86. },
  87. inputChange: function (e) {
  88. this.setData({
  89. keyword: e.detail.value,
  90. page: 1,
  91. list: [],
  92. top: 0
  93. })
  94. this.getData();
  95. },
  96. tab: function (e) {
  97. var i = e.target.dataset.id;
  98. var array = ['', 'organizer', 'article', 'conference', 'journal', 'subject'];
  99. this.setData({
  100. type: array[i],
  101. act: i,
  102. top: 0,
  103. list: [],
  104. page: 1,
  105. loading: true
  106. })
  107. this.getData()
  108. },
  109. more: function (e) {
  110. var value = e.target.dataset.id;
  111. this.setData({
  112. type: value,
  113. act: e.target.dataset.index,
  114. left: e.target.dataset.index > 3 ? 250 : 0,
  115. list: [],
  116. top: 0,
  117. page: 1,
  118. loading: true
  119. })
  120. },
  121. /**organizer/article/conference/journal/subject
  122. * 生命周期函数--监听页面初次渲染完成
  123. */
  124. onReady: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面显示
  128. */
  129. onShow: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload: function () {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh: function () {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom: function () {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage: function () {
  155. }
  156. })