news.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const pages = require('../../mixin/pages')
  2. const { postFollowUser } = require('./api/index')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. ...pages.data(),
  9. listUrl: '/api/user/track/list',
  10. searchForm: {
  11. 'key_words': ''
  12. // 'follow_type': 1
  13. },
  14. nav: [
  15. {
  16. name: '推荐',
  17. value: '1'
  18. },
  19. {
  20. name: '关注',
  21. value: '2'
  22. }
  23. ],
  24. active: '1',
  25. booLock: false
  26. },
  27. ...pages.methods,
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. this.fetchOrderList()
  33. },
  34. /**
  35. * 生命周期函数--监听页面初次渲染完成
  36. */
  37. onReady() {
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow() {
  43. this.getTabBar().init()
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload() {
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh() {
  59. if (this.data.freshing) {
  60. return
  61. }
  62. this.setData({
  63. freshing: true
  64. })
  65. this.bindCallBack()
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom() {
  71. this.fetchOrderList()
  72. },
  73. bindCallBack() {
  74. this.refreshOrderList()
  75. },
  76. handleNav(e) {
  77. const { value } = e.detail
  78. const searchForm = JSON.parse(JSON.stringify(this.data.searchForm))
  79. if (value === '1' && searchForm.hasOwnProperty('follow_type')) {
  80. delete searchForm.follow_type
  81. } else if (value === '2') {
  82. searchForm.follow_type = 1
  83. }
  84. this.setData({
  85. active: value,
  86. searchForm: searchForm
  87. }, () => {
  88. this.refreshOrderList()
  89. })
  90. },
  91. // 关注
  92. async followUser(e) {
  93. const { item, index } = e.target.dataset
  94. this.setData({
  95. booLock: true
  96. })
  97. try {
  98. const { status, msg } = await postFollowUser(item.user_id)
  99. if (status) {
  100. wx.showToast({
  101. title: '已关注',
  102. icon: 'none'
  103. })
  104. this.setData({
  105. [listData[index].follow_status]: 1
  106. })
  107. } else {
  108. wx.showToast({
  109. title: msg,
  110. icon: 'none'
  111. })
  112. }
  113. } catch (err) {}
  114. this.setData({
  115. booLock: false
  116. })
  117. },
  118. jumpAddNews() {
  119. wx.navigateTo({
  120. url: '/pages/addNews/addNews'
  121. })
  122. }
  123. })