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

301 lines
7.3 KiB

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