锦水居民端小程序
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.

525 lines
16 KiB

5 years ago
import {
getTopicDetailV2,
//getRemarkList,
//closeTopic,
5 years ago
// publishStatement,
//topicComLike,
//topicComUnlike,
//getCloseReason
} from "../../utils/api"
6 years ago
const app = getApp()
Page({
data: {
detailId: "",
6 years ago
detailInfo: {
id: "",
topicContent: "",
browseNum: "",
nickname: "",
userAvatar: "",
images: "",
createdTime: "",
partyMember: "", // 是否党员
6 years ago
operationalFlag: true, // 是否可操作
closeFlag: true, // 是否可关闭
changeFlag: true, // 是否可转议题m
groupState: 0, // 群状态
topicState: 0, // 话题状态
},
pageNo: 1,
pageSize: 10,
remarkType: "new",
timestamp: "",
6 years ago
noticeVerifyVisible: false,
remarkList: [],
statementNum: "",
6 years ago
loadMoreVisible: false,
loadMoreType: "loading",
lordFlag: "0",
supportTimer: "",
disportTimer: "",
6 years ago
dialogVisible: false,
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
closeObj: {},
infoCompleted: 0,
completeInfoDialogVisible: false
},
onLoad (options) {
this.getTopicDetail(options.detailId)
this.setData({
detailId: options.detailId,
infoCompleted: app.globalData.infoCompleted
})
// this.getCloseReason()
6 years ago
},
onShow () {
// this.setData({
// pageNo: 1,
// loadMoreType: "loading",
// timestamp: ""
// })
// this.getTopicRemark()
6 years ago
},
onReachBottom () {
// if (!this.data.loadMoreVisible) {
// this.setData({
// loadMoreVisible: true
// })
// }
// if (this.data.loadMoreType === "loading") {
// this.setData({
// pageNo: this.data.pageNo + 1
// })
// setTimeout(() => {
// this.getTopicRemark()
// },500)
// }
6 years ago
},
// 跳转 评论
inputFocus () {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else {
wx.navigateTo({
url: `/subpages/association/pages/replyOrRemark/replyOrRemark?topicId=${this.data.detailId}&faCommentId=`
})
}
},
// 获取话题详情
getTopicDetail (detailId) {
getTopicDetailV2(detailId).then(res => {
console.log("话题详情",res)
// const detailInfo = {}
// for(const key in this.data.detailInfo) {
// detailInfo[key] = res.data[key]
// }
// this.setData({
// lordFlag: res.data.lordFlag,
// detailInfo
// })
this.data.detailInfo = { ...res.data }
6 years ago
this.setData({
detailInfo: this.data.detailInfo
6 years ago
})
}).catch(err => {
console.log(err)
})
},
previewImage (e) {
wx.previewImage({
urls: this.data.detailInfo.images,
current: e.currentTarget.dataset.src
})
},
6 years ago
// 获取话题评论列表
getTopicRemark () {
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
orderType: this.data.remarkType === "new" ? 0 : 1,
6 years ago
topicId: this.data.detailId
}
getRemarkList(para).then(res => {
console.log("话题评论列表", res)
6 years ago
let remarkList = []
if (this.data.pageNo === 1) {
remarkList = [...res.data.commentsList]
} else {
remarkList = [...this.data.remarkList.concat(res.data.commentsList)]
}
if (remarkList.length > 0) {
this.setData({
timestamp: remarkList[0].commentTime
})
}
this.setData({
statementNum: res.data.statementNum,
loadMoreType: res.data.commentsList.length === 10 ? "loading" : "none",
6 years ago
remarkList,
})
}).catch(err => {
console.log(err)
})
},
// 获取话题评论表态次数
getTopicAltitudeNum () {
this.setData({
statementNum: parseInt(this.data.statementNum) + 1
})
},
// 关闭话题
closeTopic (e) {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
const para = {
id: this.data.detailId,
processingOpinions: e.detail.data
}
wx.showLoading({
title: "加载中"
6 years ago
})
closeTopic(para).then(res => {
wx.hideLoading()
console.log("关闭话题", res)
6 years ago
wx.showToast({
title: "关闭话题成功",
icon: "none",
6 years ago
duration: 2000
})
const pages = getCurrentPages()
const page = pages[pages.length - 2]
if (page.pullRefreshGetTopicList) {
page.pullRefreshGetTopicList()
}
setTimeout(() => {
wx.navigateBack()
}, 1000)
}).catch( err => {
console.log(err)
})
},
// 关闭弹框
closeDialog () {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
this.setData({
noticeVerifyVisible: !this.data.noticeVerifyVisible
})
},
// 话题转议题
changeToIssue () {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
wx.navigateTo({
url: `/subpages/association/pages/changeToIssue/changeToIssue?topicId=${this.data.detailId}`
})
},
// 支持某条评论 debounce防抖
debounceSupportReply (e) {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
clearTimeout(this.data.supportTimer)
this.data.supportTimer = setTimeout(() => {
this.supportReply(e)
}, 200)
},
// 支持某条评论
supportReply (e) {
const para = {
attitude: "0",
6 years ago
commentId: e.detail.commentId,
topicId: this.data.detailId
}
try {
this.data.remarkList.forEach(item => {
if (item.commentId === e.detail.commentId) {
if (item.userLike || item.userDislike) {
this.setData({
noticeTitle: "已表态",
noticeContent: ["已表达过态度,不可以更改哦!"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
throw new Error(false)
}
}
})
} catch (err) {
return false
}
5 years ago
topicComLike(para).then(res => {
6 years ago
this.getTopicAltitudeNum()
console.log("支持", res)
5 years ago
this.data.remarkList.forEach((item, index) => {
6 years ago
if (item.commentId === e.detail.commentId) {
this.setData({
[`remarkList[${index}].userLike`]: true,
[`remarkList[${index}].userDislike`]: false,
[`remarkList[${index}].approveNum`]: parseInt(this.data.remarkList[index].approveNum) + 1,
[`remarkList[${index}].opposeNum`]: parseInt(this.data.remarkList[index].opposeNum) > 0 ? parseInt(this.data.remarkList[index].opposeNum) - 1 : 0
})
wx.showToast({
title: "表态成功",
icon: "none",
6 years ago
duration: 2000
})
}
})
}).catch(err => {
console.log(err)
})
5 years ago
// publishStatement(para).then(res => {
// this.getTopicAltitudeNum()
// console.log('支持', res)
// this.data.remarkList.forEach((item,index) => {
// if (item.commentId === e.detail.commentId) {
// this.setData({
// [`remarkList[${index}].userLike`]: true,
// [`remarkList[${index}].userDislike`]: false,
// [`remarkList[${index}].approveNum`]: parseInt(this.data.remarkList[index].approveNum) + 1,
// [`remarkList[${index}].opposeNum`]: parseInt(this.data.remarkList[index].opposeNum) > 0 ? parseInt(this.data.remarkList[index].opposeNum) - 1 : 0
// })
// wx.showToast({
// title: '表态成功',
// icon: 'none',
// duration: 2000
// })
// }
// })
// }).catch(err => {
// console.log(err)
// })
6 years ago
},
// 反对某条评论 debounce 防抖
debiunceDispportReply (e) {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
clearTimeout(this.data.disportTimer)
this.data.disportTimer = setTimeout(() => {
this.dispportReply(e)
}, 200)
},
// 反对某条评论
dispportReply (e) {
const para = {
attitude: "1",
6 years ago
commentId: e.detail.commentId,
topicId: this.data.detailId
}
try {
this.data.remarkList.forEach(item => {
if (item.commentId === e.detail.commentId) {
if (item.userLike || item.userDislike) {
this.setData({
noticeTitle: "已表态",
noticeContent: ["已表达过态度,不可以更改哦!"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
throw new Error(false)
}
}
})
} catch (err) {
return false
}
5 years ago
topicComUnlike(para).then(res => {
6 years ago
this.getTopicAltitudeNum()
console.log("反对", res)
6 years ago
this.data.remarkList.forEach((item, index) => {
if (item.commentId === e.detail.commentId) {
this.setData({
[`remarkList[${index}].userLike`]: false,
[`remarkList[${index}].userDislike`]: true,
5 years ago
[`remarkList[${index}].approveNum`]: parseInt(this.data.remarkList[index].approveNum) > 0 ? parseInt(this.data.remarkList[index].approveNum) - 1 : 0,
6 years ago
[`remarkList[${index}].opposeNum`]: parseInt(this.data.remarkList[index].opposeNum) + 1
})
wx.showToast({
title: "表态成功",
icon: "none",
6 years ago
duration: 2000
})
}
})
}).catch(err => {
console.log(err)
})
5 years ago
// publishStatement(para).then(res => {
// this.getTopicAltitudeNum()
// console.log('反对', res)
// this.data.remarkList.forEach((item, index) => {
// if (item.commentId === e.detail.commentId) {
// this.setData({
// [`remarkList[${index}].userLike`]: false,
// [`remarkList[${index}].userDislike`]: true,
// [`remarkList[${index}].approveNum`]: parseInt(this.data.remarkList[index].approveNum) > 0 ? parseInt(this.data.remarkList[index].approveNum) - 1: 0,
// [`remarkList[${index}].opposeNum`]: parseInt(this.data.remarkList[index].opposeNum) + 1
// })
// wx.showToast({
// title: '表态成功',
// icon: 'none',
// duration: 2000
// })
// }
// })
// }).catch(err => {
// console.log(err)
// })
6 years ago
},
// 对评论进行回复
replyRemark (e) {
if (this.checkIsCompleteInfo()) {
return false
}
if (this.data.detailInfo.groupState == "15") {
6 years ago
this.setData({
noticeTitle: "社群已禁言",
noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
} else if (this.data.detailInfo.topicState == "20") {
6 years ago
this.setData({
noticeTitle: "话题已关闭",
noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"],
6 years ago
dialogVisible: !this.data.dialogVisible
})
return false
}
wx.navigateTo({
url: `/subpages/association/pages/replyOrRemark/replyOrRemark?topicId=${this.data.detailId}&faCommentId=${e.detail.commentId}`
})
},
// 评论列表 type 切换
changeRemarkType (e) {
this.setData({
pageNo: 1,
remarkType: e.detail.type,
timestamp: "",
loadMoreType: "loading"
6 years ago
})
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: "",
orderType: e.detail.type === "new" ? 0 : 1,
6 years ago
topicId: this.data.detailId
}
getRemarkList(para).then(res => {
console.log("话题评论列表", res)
6 years ago
if (res.data.commentsList.length > 0) {
this.setData({
timestamp: res.data.commentsList[0].commentTime
})
}
this.setData({
remarkList: res.data.commentsList,
statementNum: res.data.statementNum,
// loadMoreVisible: false,
loadMoreType: res.data.commentsList.length === 10 ? "loading" : "none"
6 years ago
})
}).catch(err => {
console.log(err)
})
},
// 获取关闭原因
getCloseReason () {
getCloseReason(this.data.detailId).then(res => {
console.log("获取关闭原因", res)
6 years ago
if (res.data.length > 0) {
this.setData({
closeObj: {
createdTime: res.data[0].createdTime,
processingOpinions: res.data[0].processingOpinions
}
})
}
}).catch(err => {
console.log(err)
})
},
checkIsCompleteInfo () {
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return true
}
}
})