// pages/circlesDetail/circlesDetail.js const app = getApp(); const request = require("../../utils/request.js"); const login = require("../../utils/login.js"); Page({ /** * 页面的初始数据 */ data: { bannerIndex: 0, contentId: null, info: {}, scale: 1, commentList: [], focusStatus: false, iptValue: '', iptPla: '喜欢就给个评论呗~', reply_params: { contentId: null, comment: '', parentCommentId: null, atUserId: null }, handleStatus: true, commentId: null, scene: null, deleteStatus: true }, previewMedia(event) { let sources = this.data.info.imgUrlList.map((item, index)=>{ return {url: item} }); let current = event.currentTarget.dataset.index; wx.previewMedia({ sources: sources, current: current }) }, toReport() { wx.navigateTo({ url: '../report/report?targetType=Comment&targetId=' + this.data.commentId }) }, deleteComFun() { let that = this; request.postData( 'app/cont/comment/del', {commentId: that.data.commentId}, res => { that.getDetailData() that.getCommentList() that.setData({ commentId: null, handleStatus: true }) wx.showToast({ title: '删除成功', icon: 'none', duration: 2000 }) } ) }, pressReplyComment(event) { let userId = event.currentTarget.dataset.userid; let userId2 = app.globalData.userInfo.userId ? app.globalData.userInfo.userId : null; this.data.commentId = event.currentTarget.dataset.commentid ? event.currentTarget.dataset.commentid : null; if(userId == userId2) { this.setData({ deleteStatus: false, commentId: this.data.commentId, handleStatus: !this.data.handleStatus }) }else{ this.setData({ deleteStatus: true, commentId: this.data.commentId, handleStatus: !this.data.handleStatus }) } }, tapReplyComment(event) { let that = this; that.data.reply_params.contentId = that.data.contentId; that.data.reply_params.parentCommentId = event.currentTarget.dataset.commentid; that.data.reply_params.atUserId = event.currentTarget.dataset.userid; this.setData({ focusStatus: true, reply_params: that.data.reply_params, iptPla: '@' + event.currentTarget.dataset.name }) }, sendComment(event) { let that = this; if(that.data.reply_params.atUserId){ that.data.reply_params.comment = event.detail.value; request.postData( 'app/cont/comment/reply', that.data.reply_params, res => { that.data.reply_params.atUserId = null; that.data.info.commentCount++; that.setData({ iptValue: '', reply_params: that.data.reply_params, info: that.data.info }) that.getCommentList(); }, res => { that.data.reply_params.atUserId = null; that.setData({ iptValue: '', reply_params: that.data.reply_params }) } ) }else{ let comment = event.detail.value; request.postData( 'app/cont/comment', {contentId: that.data.contentId, comment: comment}, res => { that.data.info.commentCount++; that.getCommentList(); that.setData({ info: that.data.info, iptValue: '' }) }, res => { console.log(res) } ) } }, iptBlurFun() { this.setData({ iptPla: '喜欢就给个评论呗~' }) }, iptFun() { this.setData({ focusStatus: !this.data.focusStatus }) }, commentlikeFun(event) { let that = this; let commentId = event.currentTarget.dataset.commentid; request.postData( 'app/op/like', {recordType: 'CommentList', outBusiId: commentId}, res => { that.getCommentList(); }, res => { console.log(res) } ) }, commentCellikeFun(event) { let that = this; let commentId = event.currentTarget.dataset.commentid; request.postData( 'app/op/like/cancel', {recordType: 'CommentList', outBusiId: commentId}, res => { that.getCommentList(); }, res => { console.log(res) } ) }, contentlikeFun() { let that = this; request.postData( 'app/op/like', {recordType: 'ContentLike', outBusiId: that.data.contentId}, res => { that.getDetailData(); }, res => { console.log(res) } ) }, contentCellikeFun() { let that = this; request.postData( 'app/op/like/cancel', {recordType: 'ContentLike', outBusiId: that.data.contentId}, res => { that.getDetailData(); }, res => { console.log(res) } ) }, getCommentList() { let that = this; request.getData( 'app/cont/comment/list', {contentId : that.data.contentId}, res => { that.setData({ commentList: res.data.data }) }, res => { console.log(res) } ) }, toPersonHome(event) { let userId = event.currentTarget.dataset.userid; login.ifLogin('../personHome/personHome?userId=' + userId) }, getDetailData() { let that = this; request.getData( 'app/cont/content/detail', {contentId : that.data.contentId}, res => { let scale = request.getUrlKey(res.data.data.imgUrlList[0], 'scale'); that.setData({ info: res.data.data, scale: scale ? scale : 1 }) }, res => { console.log(res) } ) }, backPge() { if(this.data.scene == 1007 || this.data.scene == 1008) { wx.switchTab({ url: '../index/index' }) }else{ wx.navigateBack({ delta: 1 }) } }, bindchange(event) { this.setData({ bannerIndex: event.detail.current }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ contentId: options.contentId }) this.getDetailData() this.getCommentList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ handleStatus: true }) let EnterOptions = wx.getEnterOptionsSync() this.setData({ scene: EnterOptions.scene }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { let that = this; if(that.data.commentList.length>0) { let lastCommentId = Number(that.data.commentList[that.data.commentList.length-1].commentId); request.getData( 'app/cont/comment/list', {contentId : that.data.contentId, lastCommentId: lastCommentId}, res => { if(res.data.data.length > 0) { that.setData({ commentList: that.data.commentList.concat(res.data.data) }) } }, res => { console.log(res) } ) } }, /** * 用户点击右上角分享 */ onShareAppMessage() { let title = this.data.info.content let contentId = this.data.contentId let imageUrl = this.data.info.imgUrlList[0] return { title: title, imageUrl: imageUrl, path: '/pages/circlesDetail/circlesDetail?contentId=' + contentId } }, onShareTimeline() { } })