index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. quickShow: true,
  24. commentId: '',
  25. totalSize: 0,
  26. list: [],
  27. detailDesc: '',
  28. postId: '',
  29. postIndex: '',
  30. ifGetFocus: false,
  31. replyType: 'works', // 回复类型,works是回复作品,comment是回复评论
  32. animation: {}
  33. },
  34. methods: {
  35. open(columnId) {
  36. // 背景遮罩层
  37. var animation = wx.createAnimation({
  38. duration: 300,
  39. timingFunction: "linear",
  40. delay: 0
  41. })
  42. animation.translateY(1000).step()
  43. this.setData({
  44. animationData: animation.export(),
  45. columnId,
  46. show: true,
  47. })
  48. setTimeout(() => {
  49. animation.translateY(0).step()
  50. this.setData({
  51. animationData: animation.export()
  52. })
  53. }, 100)
  54. this.getComment()
  55. },
  56. close() {
  57. this.setData({
  58. show: false,
  59. quickShow:true,
  60. commentId: '',
  61. totalSize: 0,
  62. list: [],
  63. detailDesc: '',
  64. replyType: 'works',
  65. postId: null,
  66. postIndex: null,
  67. ifGetFocus: false,
  68. })
  69. },
  70. quickClose() {
  71. this.setData({
  72. quickShow: false
  73. })
  74. },
  75. async getComment() {
  76. let params = {
  77. columnId: this.data.columnId,
  78. pageNo: 1,
  79. pageSize: 100
  80. }
  81. let {
  82. totalSize,
  83. list
  84. } = await getComment(params)
  85. this.setData({
  86. totalSize,
  87. list
  88. })
  89. },
  90. bindKeyInput(e) {
  91. this.setData({
  92. detailDesc: e.detail.value
  93. })
  94. },
  95. async quickRemark({
  96. currentTarget
  97. }) {
  98. let data = {
  99. columnId: this.data.columnId,
  100. detailDesc: currentTarget.dataset.remark
  101. }
  102. await postReply(data)
  103. // 评论数+1
  104. this.triggerEvent('addCommentNum', this.data.columnId)
  105. this.getComment()
  106. },
  107. // 评论作品
  108. async sendReply() {
  109. if (!this.data.detailDesc.trim()) {
  110. return
  111. }
  112. if (this.data.replyType == 'works') {
  113. let data = {
  114. columnId: this.data.columnId,
  115. detailDesc: this.data.detailDesc,
  116. }
  117. await postReply(data)
  118. // 评论数+1
  119. this.triggerEvent('addCommentNum', this.data.columnId)
  120. } else {
  121. let data = {
  122. postsId: this.data.postId,
  123. content: this.data.detailDesc,
  124. }
  125. await ReplyComment(data)
  126. }
  127. this.setData({
  128. detailDesc: '',
  129. replyType: 'works'
  130. })
  131. this.getComment()
  132. },
  133. async ReplyComment({
  134. currentTarget
  135. }) {
  136. let postId = currentTarget.dataset.id
  137. let index = currentTarget.dataset.index
  138. this.setData({
  139. postId: postId,
  140. replyType: 'comment',
  141. ifGetFocus: true,
  142. postIndex: index
  143. })
  144. },
  145. cancelId() {
  146. this.setData({
  147. replyType: 'works',
  148. postId: null,
  149. postIndex: null,
  150. ifGetFocus: false,
  151. })
  152. },
  153. // 评论点赞
  154. async setLike({
  155. currentTarget
  156. }) {
  157. let postId = currentTarget.dataset.id
  158. let index = currentTarget.dataset.index
  159. let res = await likeReply(postId)
  160. const str = `list[${index}].likeCount`;
  161. const strImg = `list[${index}].isLike`;
  162. this.setData({
  163. [str]: res,
  164. [strImg]: true
  165. })
  166. },
  167. jumpUserInfo({
  168. currentTarget
  169. }) {
  170. wx.navigateTo({
  171. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  172. })
  173. },
  174. }
  175. })