index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import {
  2. getComment,
  3. postReply,
  4. ReplyComment,
  5. likeReply,
  6. delPost,
  7. getLikeNotes,
  8. getLikeNote,
  9. getCommentNote
  10. } from '~/api/video'
  11. import {
  12. setFans
  13. } from '~/api/user'
  14. import reachBottom from '~/mixins/reachBottom'
  15. Component({
  16. behaviors: [reachBottom],
  17. properties: {
  18. // 是否在tabbar页面使用,是的话就给个padding
  19. tabBarPadding: {
  20. type: Boolean,
  21. value: false
  22. }
  23. },
  24. data: {
  25. show: false,
  26. quickShow: true,
  27. type: 'comment',
  28. commentId: '',
  29. firstData: {},
  30. list: [],
  31. count: {},
  32. detailDesc: '',
  33. postId: '',
  34. postIndex: '',
  35. ifGetFocus: false,
  36. replyType: 'works', // 回复类型,works是回复作品,comment是回复评论
  37. animation: {}
  38. },
  39. methods: {
  40. async open(columnId, type = 'comment', onceId) {
  41. console.log(columnId, type, onceId);
  42. // 背景遮罩层
  43. var animation = wx.createAnimation({
  44. duration: 300,
  45. timingFunction: "linear",
  46. delay: 0
  47. })
  48. animation.translateY(1000).step()
  49. this.setData({
  50. animationData: animation.export(),
  51. columnId,
  52. type,
  53. show: true,
  54. })
  55. setTimeout(() => {
  56. animation.translateY(0).step()
  57. this.setData({
  58. animationData: animation.export()
  59. })
  60. }, 100)
  61. if (onceId) {
  62. this.topping(onceId)
  63. } else {
  64. this.resetData()
  65. }
  66. let r1 = await getComment({
  67. columnId: this.data.columnId,
  68. pageSize: 1
  69. })
  70. let r2 = await getLikeNotes({
  71. userReadId: this.data.columnId,
  72. pageSize: 1
  73. })
  74. this.setData({
  75. count: {
  76. commentNum: r1.totalSize,
  77. likeNum: r2.totalSize
  78. }
  79. })
  80. },
  81. changeType({
  82. currentTarget
  83. }) {
  84. let type = currentTarget.dataset.type
  85. this.setData({
  86. type,
  87. firstData: {}
  88. })
  89. this.resetData()
  90. },
  91. close() {
  92. this.setData({
  93. show: false,
  94. quickShow: true,
  95. commentId: '',
  96. detailDesc: '',
  97. replyType: 'works',
  98. postId: null,
  99. postIndex: null,
  100. ifGetFocus: false,
  101. })
  102. },
  103. quickClose() {
  104. this.setData({
  105. quickShow: false
  106. })
  107. },
  108. loadMore() {
  109. this.getData((data) => {
  110. return new Promise(async (reslove) => {
  111. let res
  112. if (this.data.type == 'comment') {
  113. res = await getComment(data)
  114. this.setData({
  115. 'count.commentNum': res.totalSize
  116. })
  117. } else if (this.data.type == 'like') {
  118. res = await getLikeNotes(data)
  119. this.setData({
  120. 'count.likeNum': res.totalSize
  121. })
  122. }
  123. if (this.data.firstData.id) {
  124. res.list = res.list.filter(item => {
  125. return item.id != this.data.firstData.id
  126. })
  127. res.list.unshift(this.data.firstData)
  128. }
  129. reslove(res)
  130. })
  131. }, this.data.type == 'comment' ? {
  132. columnId: this.data.columnId
  133. } : {
  134. userReadId: this.data.columnId,
  135. })
  136. },
  137. bindKeyInput(e) {
  138. this.setData({
  139. detailDesc: e.detail.value
  140. })
  141. },
  142. async topping(id) {
  143. console.log(this.data.type);
  144. let res
  145. if (this.data.type == 'like') {
  146. res = await getLikeNote(id)
  147. } else {
  148. res = await getCommentNote(id)
  149. }
  150. console.log(res);
  151. this.setData({
  152. firstData: res
  153. })
  154. this.loadMore()
  155. },
  156. async quickRemark({
  157. currentTarget
  158. }) {
  159. let data = {
  160. columnId: this.data.columnId,
  161. detailDesc: currentTarget.dataset.remark
  162. }
  163. await postReply(data)
  164. // 评论数+1
  165. this.triggerEvent('addCommentNum', this.data.columnId)
  166. this.resetData()
  167. },
  168. // 评论作品
  169. async sendReply() {
  170. if (!this.data.detailDesc.trim()) {
  171. return
  172. }
  173. if (this.data.replyType == 'works') {
  174. let data = {
  175. columnId: this.data.columnId,
  176. detailDesc: this.data.detailDesc,
  177. }
  178. await postReply(data)
  179. // 评论数+1
  180. this.triggerEvent('addCommentNum', this.data.columnId)
  181. } else {
  182. let data = {
  183. postsId: this.data.postId,
  184. content: this.data.detailDesc,
  185. }
  186. await ReplyComment(data)
  187. }
  188. this.setData({
  189. detailDesc: '',
  190. replyType: 'works'
  191. })
  192. this.resetData()
  193. },
  194. async ReplyComment({
  195. currentTarget
  196. }) {
  197. let postId = currentTarget.dataset.id
  198. let index = currentTarget.dataset.index
  199. this.setData({
  200. postId: postId,
  201. replyType: 'comment',
  202. ifGetFocus: true,
  203. postIndex: index
  204. })
  205. },
  206. cancelId() {
  207. this.setData({
  208. replyType: 'works',
  209. postId: null,
  210. postIndex: null,
  211. ifGetFocus: false,
  212. })
  213. },
  214. // 评论点赞
  215. async setLike({
  216. currentTarget
  217. }) {
  218. let postId = currentTarget.dataset.id
  219. let index = currentTarget.dataset.index
  220. let res = await likeReply(postId)
  221. const str = `list[${index}].likeCount`;
  222. const strImg = `list[${index}].isLike`;
  223. this.setData({
  224. [str]: res,
  225. [strImg]: true
  226. })
  227. },
  228. jumpUserInfo({
  229. currentTarget
  230. }) {
  231. wx.navigateTo({
  232. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  233. })
  234. },
  235. onLongPress({
  236. currentTarget
  237. }) {
  238. let {
  239. id,
  240. type
  241. } = currentTarget.dataset
  242. wx.showActionSheet({
  243. itemList: ['删除评论'],
  244. success: async () => {
  245. let res2 = await delPost({
  246. id,
  247. type
  248. })
  249. console.log(res2);
  250. },
  251. })
  252. },
  253. // 关注
  254. async setFans() {
  255. /* if (this.data.videoInfoCopy.isFans) {
  256. return
  257. }
  258. await setFans({
  259. uid: this.data.videoInfoCopy.user.uid
  260. })
  261. this.triggerEvent('setListFans', this.data.videoInfoCopy.user.uid) */
  262. },
  263. }
  264. })