index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import {
  2. getComment,
  3. postReply,
  4. ReplyComment,
  5. likeReply,
  6. getLikeNotes,
  7. getLikeNote
  8. } from '~/api/video'
  9. import reachBottom from '~/mixins/reachBottom'
  10. Component({
  11. behaviors: [reachBottom],
  12. properties: {
  13. // 是否在tabbar页面使用,是的话就给个padding
  14. tabBarPadding: {
  15. type: Boolean,
  16. value: false
  17. }
  18. },
  19. data: {
  20. show: false,
  21. quickShow: true,
  22. type: 'comment',
  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, type = 'comment') {
  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. type,
  46. show: true,
  47. })
  48. console.log(type);
  49. setTimeout(() => {
  50. animation.translateY(0).step()
  51. this.setData({
  52. animationData: animation.export()
  53. })
  54. }, 100)
  55. this.resetData()
  56. },
  57. changeType({
  58. currentTarget
  59. }) {
  60. let type = currentTarget.dataset.type
  61. this.setData({
  62. type
  63. })
  64. this.resetData()
  65. console.log(currentTarget.dataset);
  66. },
  67. close() {
  68. this.setData({
  69. show: false,
  70. quickShow: true,
  71. commentId: '',
  72. detailDesc: '',
  73. replyType: 'works',
  74. postId: null,
  75. postIndex: null,
  76. ifGetFocus: false,
  77. })
  78. },
  79. quickClose() {
  80. this.setData({
  81. quickShow: false
  82. })
  83. },
  84. loadMore() {
  85. if (this.data.type == 'like') {
  86. this.getData(getLikeNotes, {
  87. columnId: this.data.columnId,
  88. })
  89. return
  90. }
  91. let params = {
  92. columnId: this.data.columnId,
  93. }
  94. this.getData(getComment, params)
  95. },
  96. bindKeyInput(e) {
  97. this.setData({
  98. detailDesc: e.detail.value
  99. })
  100. },
  101. async quickRemark({
  102. currentTarget
  103. }) {
  104. let data = {
  105. columnId: this.data.columnId,
  106. detailDesc: currentTarget.dataset.remark
  107. }
  108. await postReply(data)
  109. // 评论数+1
  110. this.triggerEvent('addCommentNum', this.data.columnId)
  111. this.resetData()
  112. },
  113. // 评论作品
  114. async sendReply() {
  115. if (!this.data.detailDesc.trim()) {
  116. return
  117. }
  118. if (this.data.replyType == 'works') {
  119. let data = {
  120. columnId: this.data.columnId,
  121. detailDesc: this.data.detailDesc,
  122. }
  123. await postReply(data)
  124. // 评论数+1
  125. this.triggerEvent('addCommentNum', this.data.columnId)
  126. } else {
  127. let data = {
  128. postsId: this.data.postId,
  129. content: this.data.detailDesc,
  130. }
  131. await ReplyComment(data)
  132. }
  133. this.setData({
  134. detailDesc: '',
  135. replyType: 'works'
  136. })
  137. this.resetData()
  138. },
  139. async ReplyComment({
  140. currentTarget
  141. }) {
  142. let postId = currentTarget.dataset.id
  143. let index = currentTarget.dataset.index
  144. this.setData({
  145. postId: postId,
  146. replyType: 'comment',
  147. ifGetFocus: true,
  148. postIndex: index
  149. })
  150. },
  151. cancelId() {
  152. this.setData({
  153. replyType: 'works',
  154. postId: null,
  155. postIndex: null,
  156. ifGetFocus: false,
  157. })
  158. },
  159. // 评论点赞
  160. async setLike({
  161. currentTarget
  162. }) {
  163. let postId = currentTarget.dataset.id
  164. let index = currentTarget.dataset.index
  165. let res = await likeReply(postId)
  166. const str = `list[${index}].likeCount`;
  167. const strImg = `list[${index}].isLike`;
  168. this.setData({
  169. [str]: res,
  170. [strImg]: true
  171. })
  172. },
  173. jumpUserInfo({
  174. currentTarget
  175. }) {
  176. wx.navigateTo({
  177. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  178. })
  179. },
  180. onLongPress(e) {
  181. wx.showActionSheet({
  182. itemList: ['删除评论'],
  183. success(res) {
  184. console.log(res.tapIndex)
  185. },
  186. })
  187. },
  188. }
  189. })