index.js 4.0 KB

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