|
|
|
const api = require('../../../../utils/understandJs')
|
|
|
|
const app = getApp()
|
|
|
|
import util from '../../../../utils/util'
|
|
|
|
import { formatTimestamp } from "../../utils/common"
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
noticeObj: {},
|
|
|
|
noticeObjContent: "",
|
|
|
|
categoryName:'',
|
|
|
|
preloadVisible: true,
|
|
|
|
isNeedBanner: false,
|
|
|
|
bannerList: [],
|
|
|
|
indicatorDots: false, //指示点
|
|
|
|
autoplay: true, //true,//自动播放
|
|
|
|
circular: true, //衔接滑动
|
|
|
|
interval: 5000, //自动播放间隔时长(ms)
|
|
|
|
duration: 500, //幻灯片切换时长(ms)
|
|
|
|
currentSwiper: 0,
|
|
|
|
nodata: false,
|
|
|
|
showTitle: true,
|
|
|
|
noticeId: '',
|
|
|
|
infoCompleted: 0, // 当前用户是否完善信息
|
|
|
|
completeInfoDialogVisible: false, // 完善信息弹窗
|
|
|
|
commentFlag: '0', //是否显示评论列表
|
|
|
|
remarkType: "new", // 评论 最新最热类型
|
|
|
|
pageIndex:1,
|
|
|
|
pageSize:10,
|
|
|
|
remarkObj: { // 评论列表
|
|
|
|
statementNum: 0,
|
|
|
|
commentsList: []
|
|
|
|
},
|
|
|
|
supportTimer: "", // 点赞 支持的计时器
|
|
|
|
dispportTimer: "", // 点踩 反对的计时器
|
|
|
|
dialogVisible: false, // 提示信息探矿所需入参
|
|
|
|
dialogTitle: "",
|
|
|
|
dialogContent: "",
|
|
|
|
dialogConformText: "",
|
|
|
|
dialogCancelText: "",
|
|
|
|
loadMoreVisible: false, // loadMoreVisible 和 loadMoreType 控制 超出一屏时的 加载和没有更多的显示与隐藏
|
|
|
|
loadMoreType: "none",
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.setData({
|
|
|
|
infoCompleted: app.globalData.infoCompleted,
|
|
|
|
commentFlag: options.commentFlag
|
|
|
|
})
|
|
|
|
if (options.id) {
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
title: options.title
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
noticeId: options.id
|
|
|
|
})
|
|
|
|
this.noticeDetail(options.id)
|
|
|
|
this.getRemarkList()
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
categoryName:options.categorycode
|
|
|
|
})
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
title: options.categoryname
|
|
|
|
})
|
|
|
|
if (options.bannerflag == '1') {
|
|
|
|
this.setData({
|
|
|
|
isNeedBanner: true
|
|
|
|
})
|
|
|
|
if (this.data.isNeedBanner) {
|
|
|
|
this.videoBannerList(options.categorycode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.noticelist()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
swiperChange: function(e) {
|
|
|
|
wx.createVideoContext('video'+this.data.currentSwiper).pause()
|
|
|
|
this.setData({
|
|
|
|
currentSwiper: e.detail.current,
|
|
|
|
autoplay: true
|
|
|
|
})
|
|
|
|
},
|
|
|
|
bindplay() {
|
|
|
|
this.setData({
|
|
|
|
autoplay: false
|
|
|
|
})
|
|
|
|
wx.getNetworkType({
|
|
|
|
success (res) {
|
|
|
|
const networkType = res.networkType
|
|
|
|
if (res.networkType != 'wifi') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '当前为非WI-FI环境,请注意流量消耗',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 3000
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
bindended() {
|
|
|
|
this.setData({
|
|
|
|
autoplay: true
|
|
|
|
})
|
|
|
|
},
|
|
|
|
bindcontrolstoggle(e) {
|
|
|
|
this.setData({
|
|
|
|
showTitle: e.detail.show
|
|
|
|
})
|
|
|
|
},
|
|
|
|
videoBannerList (code) {
|
|
|
|
api.videoBannerList(code).then( res => {
|
|
|
|
this.setData({
|
|
|
|
bannerList: res.data
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
noticelist () {
|
|
|
|
let that = this;
|
|
|
|
let params = {
|
|
|
|
pageIndex: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
noticeCategory: that.data.categoryName
|
|
|
|
}
|
|
|
|
api.noticelist(params).then(function (res) {
|
|
|
|
if (res.data.length == 0) {
|
|
|
|
that.setData({
|
|
|
|
nodata: true
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
that.setData({
|
|
|
|
nodata: false,
|
|
|
|
noticeId: res.data[0].id
|
|
|
|
})
|
|
|
|
that.noticeDetail(res.data[0].id)
|
|
|
|
that.getRemarkList()
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
noticeDetail (noticeId){
|
|
|
|
let that = this;
|
|
|
|
api.noticeDetail(noticeId).then(function (res) {
|
|
|
|
that.setData({
|
|
|
|
noticeObj: res.data,
|
|
|
|
noticeObjContent: util.formatRichText(res.data.noticeContent),
|
|
|
|
preloadVisible: false
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
// 最新最热 评论列表切换
|
|
|
|
changeRemarkType (e) {
|
|
|
|
this.setData({
|
|
|
|
remarkType: e.detail.type,
|
|
|
|
loadMoreVisible: false
|
|
|
|
})
|
|
|
|
this.getRemarkList()
|
|
|
|
},
|
|
|
|
// 获取评论列表 下拉刷新
|
|
|
|
getRemarkList () {
|
|
|
|
if (this.data.commentFlag != '1') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
pageIndex: 1,
|
|
|
|
pageSize: 10
|
|
|
|
})
|
|
|
|
const para = {
|
|
|
|
pageIndex: this.data.pageIndex,
|
|
|
|
pageSize: this.data.pageSize,
|
|
|
|
timestamp: formatTimestamp(),
|
|
|
|
orderType: this.data.remarkType === "new" ? 0 : 1,
|
|
|
|
noticeId: this.data.noticeId,
|
|
|
|
}
|
|
|
|
api.getCommentList(para).then(res => {
|
|
|
|
console.log("评论列表", res)
|
|
|
|
this.setData({
|
|
|
|
remarkObj: {
|
|
|
|
statementNum: res.data.statementNum,
|
|
|
|
commentsList: [...res.data.commentsList]
|
|
|
|
},
|
|
|
|
loadMoreType: res.data.commentsList.length === 10 ? "loading" : "none"
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取评论列表 上拉加载
|
|
|
|
loadMoreGetRemarkList () {
|
|
|
|
const para = {
|
|
|
|
pageIndex: this.data.pageIndex,
|
|
|
|
pageSize: this.data.pageSize,
|
|
|
|
timestamp: formatTimestamp(),
|
|
|
|
orderType: this.data.remarkType === "new" ? 0 : 1,
|
|
|
|
noticeId: this.data.noticeId,
|
|
|
|
}
|
|
|
|
api.getCommentList(para).then(res => {
|
|
|
|
console.log("评论列表", res)
|
|
|
|
this.setData({
|
|
|
|
remarkObj: {
|
|
|
|
statementNum: res.data.statementNum,
|
|
|
|
commentsList: [...this.data.remarkObj.commentsList, ...res.data.commentsList]
|
|
|
|
},
|
|
|
|
loadMoreType: res.data.commentsList.length === 10 ? "loading" : "none"
|
|
|
|
})
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
debounceSupportRemark (e) {
|
|
|
|
clearTimeout(this.data.supportTimer)
|
|
|
|
this.data.supportTimer = setTimeout(() => {
|
|
|
|
this.supportRemark(e)
|
|
|
|
}, 300)
|
|
|
|
},
|
|
|
|
// 评论 支持 点赞
|
|
|
|
supportRemark (e) {
|
|
|
|
if (this.verifyCompleteInfo()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const hasAttitude = this.data.remarkObj.commentsList.some(item => item.commentId === e.detail.commentId && (item.userLike || item.userDislike))
|
|
|
|
if (hasAttitude) {
|
|
|
|
this.setData({
|
|
|
|
dialogConformText: "知道了",
|
|
|
|
dialogContent: ["已表达过态度,不可以更改哦!"],
|
|
|
|
dialogTitle: "已表态",
|
|
|
|
dialogVisible: !this.data.dialogVisible
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const index = this.data.remarkObj.commentsList.findIndex(item => item.commentId === e.detail.commentId)
|
|
|
|
this.setData({
|
|
|
|
[`remarkObj.commentsList[${index}].userLike`]: true,
|
|
|
|
[`remarkObj.commentsList[${index}].approveNum`]: parseInt(this.data.remarkObj.commentsList[index].approveNum) + 1,
|
|
|
|
["remarkObj.statementNum"]: parseInt(this.data.remarkObj.statementNum) + 1
|
|
|
|
})
|
|
|
|
const para = {
|
|
|
|
attitude: "0",
|
|
|
|
commentId: e.detail.commentId,
|
|
|
|
noticeId: this.data.noticeId
|
|
|
|
}
|
|
|
|
api.commentSupport(para).then(res => {
|
|
|
|
console.log('评论支持', res)
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
debounceDispportRemark (e) {
|
|
|
|
clearTimeout(this.data.dispportTimer)
|
|
|
|
this.data.dispportTimer = setTimeout(() => {
|
|
|
|
this.dispportRemark(e)
|
|
|
|
}, 300)
|
|
|
|
},
|
|
|
|
// 评论 不支持 点踩
|
|
|
|
dispportRemark (e) {
|
|
|
|
if (this.verifyCompleteInfo()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const hasAttitude = this.data.remarkObj.commentsList.some(item => item.commentId === e.detail.commentId && (item.userLike || item.userDislike))
|
|
|
|
if (hasAttitude) {
|
|
|
|
this.setData({
|
|
|
|
dialogConformText: "知道了",
|
|
|
|
dialogContent: ["已表达过态度,不可以更改哦!"],
|
|
|
|
dialogTitle: "已表态",
|
|
|
|
dialogVisible: !this.data.dialogVisible
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const index = this.data.remarkObj.commentsList.findIndex(item => item.commentId === e.detail.commentId)
|
|
|
|
this.setData({
|
|
|
|
[`remarkObj.commentsList[${index}].userDislike`]: true,
|
|
|
|
[`remarkObj.commentsList[${index}].opposeNum`]: parseInt(this.data.remarkObj.commentsList[index].opposeNum) + 1,
|
|
|
|
["remarkObj.statementNum"]: parseInt(this.data.remarkObj.statementNum) + 1
|
|
|
|
})
|
|
|
|
const para = {
|
|
|
|
attitude: "1",
|
|
|
|
commentId: e.detail.commentId,
|
|
|
|
noticeId: this.data.noticeId
|
|
|
|
}
|
|
|
|
api.commentOpposition(para).then(res => {
|
|
|
|
console.log('评论不支持', res)
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 进行评论
|
|
|
|
navigateToReply () {
|
|
|
|
if (this.verifyCompleteInfo()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../remarkOrReply/remarkOrReply?noticeId=${this.data.noticeId}&faCommentId=`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 评论 回复 回调
|
|
|
|
replyRemark (e) {
|
|
|
|
if (this.verifyCompleteInfo()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `../remarkOrReply/remarkOrReply?noticeId=${this.data.noticeId}&faCommentId=${e.detail.commentId}`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 检查 是否完善信息
|
|
|
|
verifyCompleteInfo () {
|
|
|
|
if (this.data.infoCompleted == 0) {
|
|
|
|
this.setData({
|
|
|
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
this.setData({
|
|
|
|
loadMoreVisible: true
|
|
|
|
})
|
|
|
|
if (this.data.loadMoreType === "loading") {
|
|
|
|
this.setData({
|
|
|
|
pageIndex: this.data.pageIndex + 1
|
|
|
|
})
|
|
|
|
this.loadMoreGetRemarkList()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
// onShareAppMessage: function () {
|
|
|
|
|
|
|
|
// }
|
|
|
|
})
|