searchList.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. // options.keyword='科学'
  19. this.setData({
  20. keyword: options.keyword ? options.keyword:'',
  21. type: options.type ? options.type:'',
  22. act: options.act
  23. })
  24. if (options.keyword ){
  25. this.getData()
  26. }
  27. },
  28. getData:function(){
  29. wx.showNavigationBarLoading()
  30. wx.request({
  31. url: host + '/api/search',
  32. method: 'GET',
  33. data: {
  34. keyword: this.data.keyword,
  35. // type: this.data.type
  36. },
  37. success: res => {
  38. wx.hideNavigationBarLoading();
  39. this.setData({
  40. data: res.data.data
  41. })
  42. },
  43. fail: function () {
  44. wx.hideLoading();
  45. wx.showToast({
  46. title: '服务器开小差啦!',
  47. icon: 'none'
  48. })
  49. }
  50. })
  51. },
  52. inputChange:function(e){
  53. this.setData({
  54. keyword:e.detail.value
  55. })
  56. this.getData();
  57. },
  58. tab:function(e){
  59. var i=e.target.dataset.id;
  60. var array = ['', 'organizer', 'article', 'conference', 'journal','subject'];
  61. this.setData({
  62. type: array[i],
  63. act:i
  64. })
  65. // this.getData()
  66. },
  67. more: function (e) {
  68. var value = e.target.dataset.id;
  69. this.setData({
  70. type: value,
  71. act: e.target.dataset.index
  72. })
  73. },
  74. /**organizer/article/conference/journal/subject
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })