myNews.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const pages = require('../../mixin/pages')
  2. const { postDelComment } = require('../news/api/index')
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. ...pages.data(),
  10. listUrl: '/api/user/track/list',
  11. searchForm: {},
  12. booLock: false,
  13. booDeleteNews: false,
  14. itemData: {},
  15. userInfo: {},
  16. fans_num: 0,
  17. follow_num: 0
  18. },
  19. currentItem: {}, // 当前选中的动态
  20. ...pages.methods,
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. const { user_id } = options
  26. this.setData({
  27. 'searchForm.user_id': user_id
  28. }, () => {
  29. this.fetchOrderList()
  30. })
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady() {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow() {
  41. this.setData({
  42. userInfo: app.globalData.userInfo
  43. })
  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. showDeleteNews(e) {
  77. const { item } = e.currentTarget.dataset
  78. this.setData({
  79. booDeleteNews: true,
  80. itemData: item
  81. })
  82. },
  83. hideDeleteNews() {
  84. this.setData({
  85. booDeleteNews: false,
  86. itemData: {}
  87. })
  88. },
  89. // 删除动态
  90. async confirmDeleteNews(e) {
  91. this.setData({
  92. booLock: true
  93. })
  94. try {
  95. const { status, msg } = await postDelComment(this.data.itemData.id)
  96. if (status) {
  97. wx.showToast({
  98. title: '已删除',
  99. icon: 'none'
  100. })
  101. this.hideDeleteNews()
  102. this.refreshOrderList()
  103. } else {
  104. wx.showToast({
  105. title: msg,
  106. icon: 'none'
  107. })
  108. }
  109. } catch (err) {}
  110. this.setData({
  111. booLock: false
  112. })
  113. },
  114. handlePreviewImage(e) {
  115. const { imgs, index } = e.currentTarget.dataset
  116. if (Array.isArray(imgs)) {
  117. wx.previewImage({
  118. urls: imgs,
  119. current: imgs[index]
  120. })
  121. }
  122. }
  123. })