You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
279 lines
7.1 KiB
279 lines
7.1 KiB
import {
|
|
getMomentDetail,
|
|
getCommentList,
|
|
likeMoment,
|
|
likeComment,
|
|
commentMoment
|
|
} from "../../api/moment"
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
// pages/moment/detail/index.js
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
id: null,
|
|
safeBottom: app.globalData.safeBottom,
|
|
height: app.globalData.safeFragmentHeight,
|
|
type: 0,
|
|
tabList: [{
|
|
id: 0,
|
|
name: '评论',
|
|
badge: 12
|
|
},
|
|
{
|
|
id: 1,
|
|
name: '系统',
|
|
badge: 0
|
|
}
|
|
],
|
|
tabIndex: 0,
|
|
inputBottom: 0,
|
|
keyboardHeight: 0,
|
|
focus: false,
|
|
comment: '',
|
|
momentDetail: null,
|
|
commentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize:15
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.data.keyboardHeight = wx.getStorageSync('keyboardHeight')
|
|
if (options.type) {
|
|
this.data.type = Number(options.type)
|
|
}
|
|
this.setData({
|
|
type: this.data.type,
|
|
safeBottom: app.globalData.safeBottom,
|
|
height: app.globalData.safeFragmentHeight - 100
|
|
})
|
|
if (options.id) {
|
|
this.data.id = options.id
|
|
this.data.form.articleId = options.id
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask: true
|
|
})
|
|
getMomentDetail(options.id).then(result => {
|
|
this.setData({
|
|
momentDetail: result.data
|
|
})
|
|
this.fetchCommentList()
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({
|
|
commentList: [],
|
|
['form.pageNum']: 1,
|
|
finished: false
|
|
})
|
|
this.fetchCommentList()
|
|
},
|
|
fetchCommentList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.setData({
|
|
requesting: true
|
|
})
|
|
getCommentList(this.data.id, this.data.form).then(result => {
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `commentList[${this.data.commentList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
if (num == 1) {
|
|
this.setData({
|
|
commentList: [],
|
|
[nowList]: respList,
|
|
requesting: false,
|
|
['form.pageNum']: (num + 1),
|
|
['momentDetail.replyQuantity']: result.data.total,
|
|
finished
|
|
})
|
|
} else {
|
|
this.setData({
|
|
[nowList]: respList,
|
|
requesting: false,
|
|
['form.pageNum']: (num + 1),
|
|
['momentDetail.replyQuantity']: result.data.total,
|
|
finished
|
|
})
|
|
}
|
|
} else {
|
|
this.setData({
|
|
requesting: false,
|
|
finished: true
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
this.setData({
|
|
requesting: false
|
|
})
|
|
})
|
|
},
|
|
onTabChange: function (e) {
|
|
if (this.data.tabIndex == Number(e.detail.key)) {
|
|
return
|
|
}
|
|
this.data.tabIndex = Number(e.detail.key)
|
|
},
|
|
bindInput: function (e) {
|
|
this.data.comment = e.detail.value
|
|
},
|
|
inputFocus: function (e) {
|
|
if (this.data.keyboardHeight) {
|
|
return
|
|
}
|
|
this.data.keyboardHeight = Number(e.detail.height)
|
|
wx.setStorageSync('keyboardHeight', this.data.keyboardHeight)
|
|
this.setData({
|
|
inputBottom: e.detail.height
|
|
})
|
|
},
|
|
inputBlur: function (e) {
|
|
this.setData({
|
|
inputBottom: 0,
|
|
focus: false
|
|
})
|
|
},
|
|
showComment: function (e) {
|
|
if (!app.globalData.userInfo) {
|
|
wx.navigateTo({
|
|
url: '/pages/login/index'
|
|
})
|
|
return
|
|
}
|
|
if (this.data.keyboardHeight) {
|
|
this.setData({
|
|
focus: true,
|
|
inputBottom: this.data.keyboardHeight
|
|
})
|
|
} else {
|
|
this.setData({
|
|
focus: true
|
|
})
|
|
}
|
|
},
|
|
submitComment: function () {
|
|
if (util.isEmpty(this.data.comment)) {
|
|
util.showToast('请输入评论内容')
|
|
return
|
|
}
|
|
wx.showLoading({
|
|
title: '处理中',
|
|
mask: true
|
|
})
|
|
var form = {
|
|
content: this.data.comment,
|
|
articleId: this.data.id
|
|
}
|
|
commentMoment(form).then(result => {
|
|
this.setData({
|
|
inputBottom: 0,
|
|
focus: false,
|
|
comment: ''
|
|
})
|
|
wx.hideLoading()
|
|
util.showToast('评论成功')
|
|
this.onRefreshList()
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
postLikeComment: function (e) {
|
|
if (!app.globalData.userInfo) {
|
|
wx.navigateTo({
|
|
url: '/pages/login/index'
|
|
})
|
|
return
|
|
}
|
|
var item = this.data.commentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
if (item.isLiked) {
|
|
util.showToast('请勿重复点赞')
|
|
return
|
|
}
|
|
likeComment({
|
|
replyId: item.id
|
|
}).then(result => {
|
|
if (item.isLiked) {
|
|
this.setData({
|
|
['commentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].likeQuantity']: result.data.likeQuantity,
|
|
['commentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].isLiked']: 0
|
|
})
|
|
} else {
|
|
this.setData({
|
|
['commentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].likeQuantity']: result.data.likeQuantity,
|
|
['commentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].isLiked']: 1
|
|
})
|
|
}
|
|
}).catch(error => {
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
likePost: function () {
|
|
if (!app.globalData.userInfo) {
|
|
wx.navigateTo({
|
|
url: '/pages/login/index'
|
|
})
|
|
return
|
|
}
|
|
if (this.data.momentDetail.isLiked) {
|
|
util.showToast('请勿重复点赞')
|
|
return
|
|
}
|
|
likeMoment({
|
|
articleId: this.data.id
|
|
}).then(result => {
|
|
this.setData({
|
|
['momentDetail.likeQuantity']: result.data.likeQuantity,
|
|
['momentDetail.isLiked']: 1
|
|
})
|
|
}).catch(error => {
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
toMill: function () {
|
|
util.navigateTo('/pages/agent/factory/index?id=' + this.data.momentDetail.millPaperId)
|
|
},
|
|
onShareAppMessage: function () {
|
|
var imageUrl = '/assets/image/icon_logo.png'
|
|
if (this.data.momentDetail.imgUrlList && this.data.momentDetail.imgUrlList.length > 0) {
|
|
imageUrl = this.data.momentDetail.imgUrlList[0]
|
|
}
|
|
return {
|
|
title: this.data.momentDetail.title,
|
|
path: 'pages/index/index?url=/pages/article/detail/index&key=id&value=' + this.data.momentDetail.id,
|
|
// imageUrl: imageUrl
|
|
}
|
|
},
|
|
//分享至朋友圈
|
|
onShareTimeline(res) {
|
|
var imageUrl = '/assets/image/icon_logo.png'
|
|
if (this.data.momentDetail.imgUrlList && this.data.momentDetail.imgUrlList.length > 0) {
|
|
imageUrl = this.data.momentDetail.imgUrlList[0]
|
|
}
|
|
return {
|
|
title: this.data.momentDetail.title,
|
|
path: 'pages/index/index?url=/pages/article/detail/index&key=id&value=' + this.data.momentDetail.id,
|
|
imageUrl: imageUrl
|
|
}
|
|
},
|
|
})
|