index.js 3.2 KB

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