wenzhang.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/wenzhang/wenzhang.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. keyword:'',
  10. id:'',
  11. list:[],
  12. page:1,
  13. loading:true
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.setData({
  20. id:options.id
  21. })
  22. this.getData()
  23. },
  24. search: function (e) {
  25. this.setData({
  26. keyword: e.detail.value,
  27. page:1,
  28. list:[]
  29. })
  30. this.getData();
  31. },
  32. search1: function (e) {
  33. this.setData({
  34. page: 1,
  35. list: []
  36. })
  37. this.getData();
  38. },
  39. next: function () {
  40. if (this.data.loading) {
  41. this.setData({
  42. page: this.data.page + 1
  43. })
  44. this.getData()
  45. }
  46. },
  47. getData: function () {
  48. var that = this;
  49. wx.showNavigationBarLoading()
  50. wx.request({
  51. url: host + '/api/article/list',
  52. data: {
  53. journal_id: this.data.id,
  54. keyword: this.data.keyword,
  55. page_size: 20,
  56. page: this.data.page
  57. },
  58. success: res => {
  59. wx.hideNavigationBarLoading()
  60. if (!res.data) {
  61. return
  62. }
  63. let list = this.data.list, data = res.data.data.list;
  64. if (data.length <= 0) {
  65. this.setData({
  66. loading: false
  67. })
  68. return;
  69. }
  70. for (let i = 0; i < data.length; i++) {
  71. data[i].name = data[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  72. list.push(data[i])
  73. }
  74. this.setData({
  75. list: list
  76. })
  77. }
  78. })
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload: function () {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh: function () {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage: function () {
  114. }
  115. })