searchList.js 2.2 KB

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