index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. },
  27. methods: {
  28. open(columnId) {
  29. this.setData({
  30. show: true,
  31. columnId,
  32. })
  33. this.getComment()
  34. },
  35. close() {
  36. this.setData({
  37. show: false,
  38. commentId: '',
  39. totalSize: 0,
  40. list: [],
  41. detailDesc: '',
  42. replyType: 'works',
  43. postId: null,
  44. postIndex: null,
  45. ifGetFocus: false,
  46. })
  47. },
  48. async getComment() {
  49. let params = {
  50. columnId: this.data.columnId,
  51. pageNo: 1,
  52. pageSize: 10000
  53. }
  54. let {
  55. totalSize,
  56. list
  57. } = await getComment(params)
  58. this.setData({
  59. totalSize,
  60. list
  61. })
  62. },
  63. bindKeyInput(e) {
  64. this.setData({
  65. detailDesc: e.detail.value
  66. })
  67. },
  68. // 评论作品
  69. async sendReply() {
  70. if (!this.data.detailDesc) {
  71. return
  72. }
  73. if (this.data.replyType == 'works') {
  74. let data = {
  75. columnId: this.data.columnId,
  76. detailDesc: this.data.detailDesc,
  77. }
  78. await postReply(data)
  79. } else {
  80. let data = {
  81. postsId: this.data.postId,
  82. content: this.data.detailDesc,
  83. }
  84. await ReplyComment(data)
  85. }
  86. this.setData({
  87. detailDesc: '',
  88. replyType: 'works'
  89. })
  90. this.getComment()
  91. },
  92. async ReplyComment({
  93. currentTarget
  94. }) {
  95. let postId = currentTarget.dataset.id
  96. let index = currentTarget.dataset.index
  97. this.setData({
  98. postId: postId,
  99. replyType: 'comment',
  100. ifGetFocus: true,
  101. postIndex: index
  102. })
  103. },
  104. cancelId() {
  105. this.setData({
  106. replyType: 'works',
  107. postId: null,
  108. postIndex: null,
  109. ifGetFocus: false,
  110. })
  111. },
  112. // 评论点赞
  113. async setLike({
  114. currentTarget
  115. }) {
  116. let postId = currentTarget.dataset.id
  117. let index = currentTarget.dataset.index
  118. let res = await likeReply(postId)
  119. const str = `list[${index}].likeCount`;
  120. const strImg = `list[${index}].isLike`;
  121. this.setData({
  122. [str]: res,
  123. [strImg]: true
  124. })
  125. }
  126. }
  127. })