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

351 lines
9.0 KiB

5 years ago
// subpages/associationNew/pages/eventlist/eventlist.js
const app = getApp()
import { topiclist, commentSubmit, statement } from "../../utils/api"
5 years ago
import {
getTimestamp
} from "../../../../utils/common"
5 years ago
Page({
/**
* 页面的初始数据
*/
data: {
topiclist: [],
timestamp: "",
5 years ago
pageIndex: 1,
pageSize: 10,
partyGroupId: "",//党群id
topicType: "",//0:事好儿鼓个掌 1:话对捧个场
5 years ago
nodata: false,
loadMoreType: "none",
5 years ago
loadMoreVisible: false,
bannedFlag: "",//是否禁言 0:否 1:是
5 years ago
ifcomment: false,//是否显示评论
focus: false,
topicId: "",//被评论的话题ID
commentContent: "",
5 years ago
index: 0,//点击的第几条数据,用于评论的局部刷新用
infoCompleted: 0,
completeInfoDialogVisible: false,
ifpreviewImage:false,//解决图片放大刷新列表的问题
commentViewContent: "捧个场" // 写评论按钮 文字内容
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
partyGroupId: options.partyGroupId,
topicType: options.topicType,//0:事好儿鼓个掌 1:话对捧个场
infoCompleted: app.globalData.infoCompleted,
commentViewContent: options.topicType == 0 ? "鼓个掌" : "捧个场"
5 years ago
})
if (options.topicType == 0) {
wx.setNavigationBarTitle({
title: "事好鼓个掌"
5 years ago
})
} else {
wx.setNavigationBarTitle({
title: "话对捧个场"
5 years ago
})
}
},
// 查列表
topiclist () {
5 years ago
let that = this;
const para = {
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize,
timestamp: getTimestamp(),
topicType: this.data.topicType,
partyGroupId: this.data.partyGroupId, //党群id
partyTopicId:""
5 years ago
}
topiclist(para).then(res => {
wx.stopPullDownRefresh();
that.setData({
bannedFlag: res.data.bannedFlag,
nodata: false,
topiclist: that.data.topiclist.concat(res.data.topicList),
loadMoreType: res.data.topicList.length === that.data.pageSize ? "loading" : "none",
5 years ago
loadMoreVisible: res.data.topicList.length === that.data.pageSize ? false : true
})
if (that.data.topiclist.length == 0) {//没有值
that.setData({
nodata: true,
loadMoreType: "none",
5 years ago
loadMoreVisible: false,
})
}
}).catch(err => {
wx.stopPullDownRefresh();
that.setData({
topiclist: [],
nodata: true,
loadMoreType: "none",
5 years ago
loadMoreVisible: false,
})
console.log(err)
})
},
// 跳转 发布话题
navigateToAddTopic () {
5 years ago
if (this.verifyCompleteInfo()) {
return false
}
wx.navigateTo({
url: `/subpages/associationNew/pages/addTopic/addTopic?partyGroupId=${this.data.partyGroupId}&topicType=${this.data.topicType}`
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(this.data.ifpreviewImage){
this.setData({
ifpreviewImage:false
})
} else {
this.setData({
pageIndex: 1,
pageSize: 10,
nodata: false,
loadMoreType: "none",
5 years ago
loadMoreVisible: false,
topiclist: [],
})
this.topiclist()
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.setData({
pageIndex: 1,
pageSize: 10,
nodata: false,
loadMoreType: "none",
5 years ago
loadMoreVisible: false,
topiclist: [],
})
this.topiclist()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === "loading") {
5 years ago
this.setData({
pageIndex: this.data.pageIndex + 1,
pageSize: this.data.pageSize,
})
this.topiclist()
}
},
//点赞
clicklike (e) {
5 years ago
if (this.verifyCompleteInfo()) {
return false
}
this.setData({
index: e.currentTarget.dataset.index
})
// <!-- 用户是否已点赞 0否;1是 -->
if (this.data.bannedFlag == "1") {//被禁言
5 years ago
wx.showToast({
title: "您已经被禁言",
icon: "none",
5 years ago
duration: 2000
})
return false
}
let attitude = ""
if (e.currentTarget.dataset.likeflag == "0") {//点赞
5 years ago
attitude = 0
} else {
attitude = 2
}
let that = this;
const para = {
topicId: e.currentTarget.dataset.id,//被评论的话题ID
attitude: attitude,//表态 0赞;1踩;2取消赞;3取消踩
}
statement(para).then(() => {
5 years ago
// 点赞成功以后实现局部刷新功能
that.nowLikesList(e.currentTarget.dataset.id);
}).catch(err => {
console.log(err)
})
},
// Textarea获取焦点
clickTextarea (e) {
5 years ago
if (this.verifyCompleteInfo()) {
return false
}
let index = e.currentTarget.dataset.index
if (this.data.bannedFlag == "1") {//被禁言
5 years ago
wx.showToast({
title: "您已经被禁言",
icon: "none",
5 years ago
duration: 2000
})
return false
}
this.setData({
ifcomment: true,
focus: true,
topicId: e.currentTarget.dataset.id,
index: index
})
},
// 失去焦点
bindAddressInput () {
5 years ago
this.setData({ //失去焦点以后view隐藏
ifcomment: false,
commentContent: ""
5 years ago
})
},
// 双向绑定
bindIdentity (e) {
5 years ago
this.setData({
commentContent: e.detail.value
})
},
// 评论按钮点击事件
commentSubmit () {
5 years ago
let that = this;
const para = {
topicId: that.data.topicId,//被评论的话题ID
faCommentId: "",//父评论(被评论)ID
5 years ago
content: that.data.commentContent,//评论内容
}
commentSubmit(para).then(() => {
5 years ago
// 评论成功以后,调用接口比对出当前评论列表的数据,对已有列表数据进行替换
that.NowTopiclist()
}).catch(err => {
console.log(err)
})
},
// 列表内当前操作的数据
NowTopiclist () {
5 years ago
let that = this;
const para = {
pageIndex: 1,
pageSize: 1,
timestamp: getTimestamp(),
topicType: that.data.topicType,
partyGroupId: that.data.partyGroupId, //党群id
partyTopicId: that.data.topicId
}
topiclist(para).then(res => {
console.log(JSON.stringify(res))
// 评论成功以后实现局部刷新功能
var obj = that.data.topiclist[that.data.index]
// 评论成功以后评论数量加1
// obj.commentNum = obj.commentNum + 1
// obj.comments.splice(0, 0, {username:obj.nickname,content:para.content});
obj = res.data.topicList[0]
that.setData({
["topiclist[" + that.data.index + "]"]: obj
})
}).catch(err => {
console.log(err)
})
},
//列表照片的放大查看
previewImage (e) {
5 years ago
this.setData({
ifpreviewImage:true
})
app.globalData.previewImage = true
wx.previewImage({
urls: e.currentTarget.dataset.imgarry,
current: e.currentTarget.dataset.src
})
},
// 检查 是否完善信息
verifyCompleteInfo () {
5 years ago
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return true
} else {
return false
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
/**
* 点赞后局部更新内容
*/
nowLikesList (topicId) {
let that = this;
const para = {
pageIndex: 1,
pageSize: 10,
timestamp: getTimestamp(),
topicType: this.data.topicType,
partyGroupId: this.data.partyGroupId, //党群id
partyTopicId: topicId
}
topiclist(para).then(res => {
var obj = that.data.topiclist[that.data.index]
obj = res.data.topicList[0]
// <!-- 用户是否已点赞 0否;1是 -->
// obj.likeFlag = obj.likeFlag == '0' ? '1' : '0'
// obj.supportNum = obj.likeFlag == '1' ? obj.supportNum + 1 : obj.supportNum - 1
that.setData({
["topiclist[" + that.data.index + "]"]: obj
})
}).catch(err => {
console.log(err)
})
},
/*
* 前往论坛指南页面
*/
navToForumGuide () {
console.log("前往论坛指南")
5 years ago
wx.navigateTo({
url: `/subpages/associationNew/pages/guideInfo/guideInfo?partyGroupId=${this.data.partyGroupId}`
})
}
5 years ago
})