import { getComment, postReply, ReplyComment, likeReply } from '~/api/video' import reachBottom from '~/mixins/reachBottom' Component({ behaviors: [reachBottom], properties: { // 是否在tabbar页面使用,是的话就给个padding tabBarPadding: { type: Boolean, value: false } }, /** * 组件的初始数据 */ data: { show: false, quickShow: true, type: 'comment', commentId: '', totalSize: 0, list: [], detailDesc: '', postId: '', postIndex: '', ifGetFocus: false, replyType: 'works', // 回复类型,works是回复作品,comment是回复评论 animation: {} }, methods: { open(columnId) { // 背景遮罩层 var animation = wx.createAnimation({ duration: 300, timingFunction: "linear", delay: 0 }) animation.translateY(1000).step() this.setData({ animationData: animation.export(), columnId, show: true, }) setTimeout(() => { animation.translateY(0).step() this.setData({ animationData: animation.export() }) }, 100) this.resetData() }, changeType({ currentTarget }) { let type = currentTarget.dataset.type this.setData({ type }) this.resetData() console.log(currentTarget.dataset); }, close() { this.setData({ show: false, quickShow: true, commentId: '', detailDesc: '', replyType: 'works', postId: null, postIndex: null, ifGetFocus: false, }) }, quickClose() { this.setData({ quickShow: false }) }, loadMore() { if (this.data.type == 'like') { return } let params = { columnId: this.data.columnId, } this.getData(getComment, params) }, bindKeyInput(e) { this.setData({ detailDesc: e.detail.value }) }, async quickRemark({ currentTarget }) { let data = { columnId: this.data.columnId, detailDesc: currentTarget.dataset.remark } await postReply(data) // 评论数+1 this.triggerEvent('addCommentNum', this.data.columnId) this.resetData() }, // 评论作品 async sendReply() { if (!this.data.detailDesc.trim()) { return } if (this.data.replyType == 'works') { let data = { columnId: this.data.columnId, detailDesc: this.data.detailDesc, } await postReply(data) // 评论数+1 this.triggerEvent('addCommentNum', this.data.columnId) } else { let data = { postsId: this.data.postId, content: this.data.detailDesc, } await ReplyComment(data) } this.setData({ detailDesc: '', replyType: 'works' }) this.resetData() }, async ReplyComment({ currentTarget }) { let postId = currentTarget.dataset.id let index = currentTarget.dataset.index this.setData({ postId: postId, replyType: 'comment', ifGetFocus: true, postIndex: index }) }, cancelId() { this.setData({ replyType: 'works', postId: null, postIndex: null, ifGetFocus: false, }) }, // 评论点赞 async setLike({ currentTarget }) { let postId = currentTarget.dataset.id let index = currentTarget.dataset.index let res = await likeReply(postId) const str = `list[${index}].likeCount`; const strImg = `list[${index}].isLike`; this.setData({ [str]: res, [strImg]: true }) }, jumpUserInfo({ currentTarget }) { wx.navigateTo({ url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`, }) }, onLongPress(e) { wx.showActionSheet({ itemList: ['删除评论'], success(res) { console.log(res.tapIndex) }, }) }, } })