index.js 5.1 KB

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