index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import {
  2. getComment,
  3. postReply,
  4. ReplyComment,
  5. likeReply
  6. } from '~/api/video'
  7. Component({
  8. /**
  9. * 组件的属性列表
  10. */
  11. properties: {
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. show: false,
  18. commentId: '',
  19. totalSize: 0,
  20. list: [],
  21. detailDesc: '',
  22. postId: '',
  23. postIndex: '',
  24. ifGetFocus: false,
  25. replyType: 'works', // 回复类型,works是回复作品,comment是回复评论
  26. animation: {}
  27. },
  28. methods: {
  29. open(columnId) {
  30. // 背景遮罩层
  31. var animation = wx.createAnimation({
  32. duration: 300,
  33. timingFunction: "linear",
  34. delay: 0
  35. })
  36. animation.translateY(1000).step()
  37. this.setData({
  38. animationData: animation.export(),
  39. columnId,
  40. show: true,
  41. })
  42. setTimeout(() => {
  43. animation.translateY(0).step()
  44. this.setData({
  45. animationData: animation.export()
  46. })
  47. }, 100)
  48. this.getComment()
  49. },
  50. close() {
  51. this.setData({
  52. show: false,
  53. commentId: '',
  54. totalSize: 0,
  55. list: [],
  56. detailDesc: '',
  57. replyType: 'works',
  58. postId: null,
  59. postIndex: null,
  60. ifGetFocus: false,
  61. })
  62. },
  63. async getComment() {
  64. let params = {
  65. columnId: this.data.columnId,
  66. pageNo: 1,
  67. pageSize: 10000
  68. }
  69. let {
  70. totalSize,
  71. list
  72. } = await getComment(params)
  73. this.setData({
  74. totalSize,
  75. list
  76. })
  77. },
  78. bindKeyInput(e) {
  79. this.setData({
  80. detailDesc: e.detail.value
  81. })
  82. },
  83. // 评论作品
  84. async sendReply() {
  85. if (!this.data.detailDesc) {
  86. return
  87. }
  88. if (this.data.replyType == 'works') {
  89. let data = {
  90. columnId: this.data.columnId,
  91. detailDesc: this.data.detailDesc,
  92. }
  93. await postReply(data)
  94. } else {
  95. let data = {
  96. postsId: this.data.postId,
  97. content: this.data.detailDesc,
  98. }
  99. await ReplyComment(data)
  100. }
  101. this.setData({
  102. detailDesc: '',
  103. replyType: 'works'
  104. })
  105. this.getComment()
  106. },
  107. async ReplyComment({
  108. currentTarget
  109. }) {
  110. let postId = currentTarget.dataset.id
  111. let index = currentTarget.dataset.index
  112. this.setData({
  113. postId: postId,
  114. replyType: 'comment',
  115. ifGetFocus: true,
  116. postIndex: index
  117. })
  118. },
  119. cancelId() {
  120. this.setData({
  121. replyType: 'works',
  122. postId: null,
  123. postIndex: null,
  124. ifGetFocus: false,
  125. })
  126. },
  127. // 评论点赞
  128. async setLike({
  129. currentTarget
  130. }) {
  131. let postId = currentTarget.dataset.id
  132. let index = currentTarget.dataset.index
  133. let res = await likeReply(postId)
  134. const str = `list[${index}].likeCount`;
  135. const strImg = `list[${index}].isLike`;
  136. this.setData({
  137. [str]: res,
  138. [strImg]: true
  139. })
  140. }
  141. }
  142. })