searchList.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. wx.request({
  27. url: host + '/api/search/default',
  28. method: 'GET',
  29. success: res=>{
  30. this.setData({
  31. info: res.data.data
  32. })
  33. }
  34. })
  35. // this.setData({
  36. // keyword: options.keyword ? options.keyword:'',
  37. // type: options.type ? options.type:'',
  38. // act: options.act
  39. // })
  40. // if (options.keyword||true ){
  41. // this.getData()
  42. // }
  43. },
  44. getData:function(){
  45. wx.showNavigationBarLoading()
  46. wx.request({
  47. url: host + '/api/search',
  48. method: 'GET',
  49. data: {
  50. keyword: this.data.keyword,
  51. type: this.data.type,
  52. page_size:20,
  53. page:this.data.page
  54. },
  55. success: res => {
  56. wx.hideNavigationBarLoading()
  57. if(this.data.act>0){
  58. let list = this.data.list, data = res.data.data[0].list;
  59. if (data.length<=0){
  60. this.setData({
  61. loading:false
  62. })
  63. return;
  64. }
  65. for (let i = 0; i <data.length;i++) {
  66. data[i]._name = data[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword+'</span>')
  67. list.push(data[i])
  68. }
  69. this.setData({
  70. title: res.data.data[0].name,
  71. value: res.data.data[0].value,
  72. list:list
  73. })
  74. }else{
  75. let data = res.data.data
  76. for(let i=0;i<data.length;i++){
  77. for (let j = 0; j < data[i].list.length; j++) {
  78. data[i].list[j]._name = data[i].list[j].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  79. }
  80. }
  81. this.setData({
  82. data: data
  83. })
  84. }
  85. },
  86. fail: function () {
  87. wx.hideLoading();
  88. wx.showToast({
  89. title: '服务器开小差啦!',
  90. icon: 'none'
  91. })
  92. }
  93. })
  94. },
  95. next:function(){
  96. if(this.data.act>0 && this.data.loading){
  97. this.setData({
  98. page:this.data.page+1
  99. })
  100. this.getData()
  101. }
  102. },
  103. search:function(e){
  104. this.setData({
  105. keyword: e.target.dataset.value,
  106. act:0
  107. })
  108. this.getData();
  109. },
  110. inputChange:function(e){
  111. this.setData({
  112. keyword:e.detail.value,
  113. page: 1,
  114. list: [],
  115. data: [],
  116. top: 0
  117. })
  118. this.getData();
  119. },
  120. search1: function () {
  121. this.setData({
  122. page:1,
  123. list:[],
  124. data:[],
  125. top:0
  126. })
  127. this.getData();
  128. },
  129. tab:function(e){
  130. var i=e.target.dataset.id;
  131. var array = ['', 'organizer', 'article', 'conference', 'journal','subject'];
  132. this.setData({
  133. type: array[i],
  134. act:i,
  135. top:0,
  136. list:[],
  137. page:1,
  138. loading:true
  139. })
  140. this.getData()
  141. },
  142. more: function (e) {
  143. var value = e.target.dataset.id;
  144. this.setData({
  145. type: value,
  146. act: e.target.dataset.index,
  147. left: e.target.dataset.index>3?250:0,
  148. list: [],
  149. top:0,
  150. page: 1,
  151. loading: true
  152. })
  153. this.getData()
  154. },
  155. /**organizer/article/conference/journal/subject
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })