import { getTopicDetailV2, //getRemarkList, //closeTopic, // publishStatement, //topicComLike, //topicComUnlike, //getCloseReason } from "../../utils/api" const app = getApp() Page({ data: { detailId: "", detailInfo: { id: "", topicContent: "", browseNum: "", nickname: "", userAvatar: "", images: "", createdTime: "", partyMember: "", // 是否党员 operationalFlag: true, // 是否可操作 closeFlag: true, // 是否可关闭 changeFlag: true, // 是否可转议题m groupState: 0, // 群状态 topicState: 0, // 话题状态 }, pageNo: 1, pageSize: 10, remarkType: "new", timestamp: "", noticeVerifyVisible: false, remarkList: [], statementNum: "", loadMoreVisible: false, loadMoreType: "loading", lordFlag: "0", supportTimer: "", disportTimer: "", dialogVisible: false, noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], closeObj: {}, infoCompleted: 0, completeInfoDialogVisible: false }, onLoad (options) { this.getTopicDetail(options.detailId) this.setData({ detailId: options.detailId, infoCompleted: app.globalData.infoCompleted }) // this.getCloseReason() }, onShow () { // this.setData({ // pageNo: 1, // loadMoreType: "loading", // timestamp: "" // }) // this.getTopicRemark() }, 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) // } }, // 跳转 评论 inputFocus () { if (this.checkIsCompleteInfo()) { return false } if (this.data.detailInfo.groupState == "15") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], 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 } this.setData({ detailInfo: this.data.detailInfo }) }).catch(err => { console.log(err) }) }, previewImage (e) { wx.previewImage({ urls: this.data.detailInfo.images, current: e.currentTarget.dataset.src }) }, // 获取话题评论列表 getTopicRemark () { const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize, timestamp: this.data.timestamp, orderType: this.data.remarkType === "new" ? 0 : 1, topicId: this.data.detailId } getRemarkList(para).then(res => { console.log("话题评论列表", res) 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", 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") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } const para = { id: this.data.detailId, processingOpinions: e.detail.data } wx.showLoading({ title: "加载中" }) closeTopic(para).then(res => { wx.hideLoading() console.log("关闭话题", res) wx.showToast({ title: "关闭话题成功", icon: "none", 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") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } this.setData({ noticeVerifyVisible: !this.data.noticeVerifyVisible }) }, // 话题转议题 changeToIssue () { if (this.checkIsCompleteInfo()) { return false } if (this.data.detailInfo.groupState == "15") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], 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") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } clearTimeout(this.data.supportTimer) this.data.supportTimer = setTimeout(() => { this.supportReply(e) }, 200) }, // 支持某条评论 supportReply (e) { const para = { attitude: "0", 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: ["已表达过态度,不可以更改哦!"], dialogVisible: !this.data.dialogVisible }) throw new Error(false) } } }) } catch (err) { return false } topicComLike(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) }) // 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) // }) }, // 反对某条评论 debounce 防抖 debiunceDispportReply (e) { if (this.checkIsCompleteInfo()) { return false } if (this.data.detailInfo.groupState == "15") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } clearTimeout(this.data.disportTimer) this.data.disportTimer = setTimeout(() => { this.dispportReply(e) }, 200) }, // 反对某条评论 dispportReply (e) { const para = { attitude: "1", 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: ["已表达过态度,不可以更改哦!"], dialogVisible: !this.data.dialogVisible }) throw new Error(false) } } }) } catch (err) { return false } topicComUnlike(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) }) // 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) // }) }, // 对评论进行回复 replyRemark (e) { if (this.checkIsCompleteInfo()) { return false } if (this.data.detailInfo.groupState == "15") { this.setData({ noticeTitle: "社群已禁言", noticeContent: ["社群已禁言,不可再", "评论/回复/支持/不支持等表达态度"], dialogVisible: !this.data.dialogVisible }) return false } else if (this.data.detailInfo.topicState == "20") { this.setData({ noticeTitle: "话题已关闭", noticeContent: ["话题已关闭,不可再", "评论/回复/支持/不支持等表达态度"], 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" }) const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize, timestamp: "", orderType: e.detail.type === "new" ? 0 : 1, topicId: this.data.detailId } getRemarkList(para).then(res => { console.log("话题评论列表", res) 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" }) }).catch(err => { console.log(err) }) }, // 获取关闭原因 getCloseReason () { getCloseReason(this.data.detailId).then(res => { console.log("获取关闭原因", res) 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 } } })