index.js 4.9 KB

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