index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. firstData: {},
  26. list: [],
  27. detailDesc: '',
  28. postId: '',
  29. postIndex: '',
  30. ifGetFocus: false,
  31. replyType: 'works', // 回复类型,works是回复作品,comment是回复评论
  32. animation: {}
  33. },
  34. methods: {
  35. open(columnId, type = 'comment', onceId) {
  36. console.log(columnId, type, onceId);
  37. // 背景遮罩层
  38. var animation = wx.createAnimation({
  39. duration: 300,
  40. timingFunction: "linear",
  41. delay: 0
  42. })
  43. animation.translateY(1000).step()
  44. this.setData({
  45. animationData: animation.export(),
  46. columnId,
  47. type,
  48. show: true,
  49. })
  50. setTimeout(() => {
  51. animation.translateY(0).step()
  52. this.setData({
  53. animationData: animation.export()
  54. })
  55. }, 100)
  56. if (onceId) {
  57. this.topping(onceId)
  58. } else {
  59. this.resetData()
  60. }
  61. },
  62. changeType({
  63. currentTarget
  64. }) {
  65. let type = currentTarget.dataset.type
  66. this.setData({
  67. type
  68. })
  69. this.resetData()
  70. console.log(currentTarget.dataset);
  71. },
  72. close() {
  73. this.setData({
  74. show: false,
  75. quickShow: true,
  76. commentId: '',
  77. detailDesc: '',
  78. replyType: 'works',
  79. postId: null,
  80. postIndex: null,
  81. ifGetFocus: false,
  82. })
  83. },
  84. quickClose() {
  85. this.setData({
  86. quickShow: false
  87. })
  88. },
  89. loadMore() {
  90. if (this.data.type == 'like') {
  91. this.getData((data) => {
  92. return new Promise(async (reslove) => {
  93. let res = await getLikeNotes(data)
  94. if (this.data.firstData) {
  95. res.list = res.list.filter(item => {
  96. return item.id != this.data.firstData.id
  97. })
  98. res.list.unshift(this.data.firstData)
  99. }
  100. reslove(res)
  101. })
  102. }, {
  103. userReadId: this.data.columnId,
  104. })
  105. } else {
  106. this.getData(getComment, {
  107. columnId: this.data.columnId,
  108. })
  109. }
  110. },
  111. bindKeyInput(e) {
  112. this.setData({
  113. detailDesc: e.detail.value
  114. })
  115. },
  116. async topping(id) {
  117. let res = await getLikeNote(id)
  118. console.log(res);
  119. this.setData({
  120. firstData: res
  121. })
  122. this.loadMore()
  123. },
  124. async quickRemark({
  125. currentTarget
  126. }) {
  127. let data = {
  128. columnId: this.data.columnId,
  129. detailDesc: currentTarget.dataset.remark
  130. }
  131. await postReply(data)
  132. // 评论数+1
  133. this.triggerEvent('addCommentNum', this.data.columnId)
  134. this.resetData()
  135. },
  136. // 评论作品
  137. async sendReply() {
  138. if (!this.data.detailDesc.trim()) {
  139. return
  140. }
  141. if (this.data.replyType == 'works') {
  142. let data = {
  143. columnId: this.data.columnId,
  144. detailDesc: this.data.detailDesc,
  145. }
  146. await postReply(data)
  147. // 评论数+1
  148. this.triggerEvent('addCommentNum', this.data.columnId)
  149. } else {
  150. let data = {
  151. postsId: this.data.postId,
  152. content: this.data.detailDesc,
  153. }
  154. await ReplyComment(data)
  155. }
  156. this.setData({
  157. detailDesc: '',
  158. replyType: 'works'
  159. })
  160. this.resetData()
  161. },
  162. async ReplyComment({
  163. currentTarget
  164. }) {
  165. let postId = currentTarget.dataset.id
  166. let index = currentTarget.dataset.index
  167. this.setData({
  168. postId: postId,
  169. replyType: 'comment',
  170. ifGetFocus: true,
  171. postIndex: index
  172. })
  173. },
  174. cancelId() {
  175. this.setData({
  176. replyType: 'works',
  177. postId: null,
  178. postIndex: null,
  179. ifGetFocus: false,
  180. })
  181. },
  182. // 评论点赞
  183. async setLike({
  184. currentTarget
  185. }) {
  186. let postId = currentTarget.dataset.id
  187. let index = currentTarget.dataset.index
  188. let res = await likeReply(postId)
  189. const str = `list[${index}].likeCount`;
  190. const strImg = `list[${index}].isLike`;
  191. this.setData({
  192. [str]: res,
  193. [strImg]: true
  194. })
  195. },
  196. jumpUserInfo({
  197. currentTarget
  198. }) {
  199. wx.navigateTo({
  200. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  201. })
  202. },
  203. onLongPress(e) {
  204. wx.showActionSheet({
  205. itemList: ['删除评论'],
  206. success(res) {
  207. console.log(res.tapIndex)
  208. },
  209. })
  210. },
  211. }
  212. })