index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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: 10000
  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) {
  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. } else {
  100. let data = {
  101. postsId: this.data.postId,
  102. content: this.data.detailDesc,
  103. }
  104. await ReplyComment(data)
  105. }
  106. this.setData({
  107. detailDesc: '',
  108. replyType: 'works'
  109. })
  110. this.getComment()
  111. },
  112. async ReplyComment({
  113. currentTarget
  114. }) {
  115. let postId = currentTarget.dataset.id
  116. let index = currentTarget.dataset.index
  117. this.setData({
  118. postId: postId,
  119. replyType: 'comment',
  120. ifGetFocus: true,
  121. postIndex: index
  122. })
  123. },
  124. cancelId() {
  125. this.setData({
  126. replyType: 'works',
  127. postId: null,
  128. postIndex: null,
  129. ifGetFocus: false,
  130. })
  131. },
  132. // 评论点赞
  133. async setLike({
  134. currentTarget
  135. }) {
  136. let postId = currentTarget.dataset.id
  137. let index = currentTarget.dataset.index
  138. let res = await likeReply(postId)
  139. const str = `list[${index}].likeCount`;
  140. const strImg = `list[${index}].isLike`;
  141. this.setData({
  142. [str]: res,
  143. [strImg]: true
  144. })
  145. }
  146. }
  147. })