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

639 lines
19 KiB

6 years ago
import {
getIssueDetail,
getIssueTypeStatistics,
getRemarkList,
5 years ago
// showRemarkStatement,
issueComLike,
issueComUnlike,
itemComLike,
itemComUnlike,
// showIssueStatement,
issueSupport,
issueOpposition,
itemSupport,
itemOpposition,
6 years ago
getProjectDetail,
getProjectTypeStatistics,
getIssueHandleProgressV2,
getProjectHandleProgressV2
} from '../../utils/api'
5 years ago
import {
formatTimestamp
} from '../../utils/common'
6 years ago
const app = getApp()
Page({
data: {
loadMoreVisible: false, // loadMoreVisible 和 loadMoreType 控制 超出一屏时的 加载和没有更多的显示与隐藏
loadMoreType: 'none',
issueId: '', // 议题id
projectId: '', // 项目id
detailId: '', // 页面获得项目或议题id
detailType: 'issue', // 议题详情 还是 项目详情
detailObj: { // 详情内容对象
id: '',
content: '',
distributeTime: '',
partyFlag: '',
nickname: '',
avatar: '',
browseNum: '',
approveNum: 0,
opposeNum: '',
images: '',
userLike: '',
categoryCode: '',
firstCategoryCode: '', // 一级分类code
userDislike: '',
isOperational: '',
address: '',
operational: true, // 议题是否可操作
itemState: '', // 项目状态 0-处理中 5-已关闭 10-已结案
showSatisfactionEvaluation: false,
issueToProjectId: '', // 项目当中,之前的议题id
},
typeStatisticsObj: { // 列表统计对象
attitudeNum: '',
categoryCode: '',
categoryName: '',
issueNum: '',
itemNum: ''
},
handleProgressList: [], // 处理进展列表
timeStamp: '', // 加载评论列表 需要的时间戳
remarkType: 'new', // 评论 最新最热类型
pageNo: 1, // 页码
pageSize: 10, // 页长
remarkObj: { // 评论列表
statementNum: 0,
commentsList: []
},
supportTimer: '', // 点赞 支持的计时器
dispportTimer: '', // 点踩 反对的计时器
dialogVisible: false, // 提示信息探矿所需入参
dialogTitle: '',
dialogContent: '',
dialogConformText: '',
dialogCancelText: '',
completeInfoDialogVisible: false, // 完善信息弹窗
infoCompleted: 0, // 当前用户是否完善信息
showClassify: 'hide' // 是否显示 议题/项目分类列表
},
5 years ago
onLoad(options) {
6 years ago
if (options.showClassify === 'show') {
this.setData({
showClassify: 'show'
})
}
if (options.type === 'issue') {
this.setData({
detailType: 'issue',
detailId: options.detailId,
issueId: options.detailId
})
this.getIssueDetail().then(() => {
this.getIssueTypeStatistics(this.data.detailObj.firstCategoryCode)
})
this.getIssueHandleProgressV2(this.data.issueId).then(res => {
const handleProgressList = []
5 years ago
res.forEach((item, index) => {
6 years ago
if (index === res.length - 1) {
item.type = 'point'
item.isFirst = true
handleProgressList.push(item)
} else {
item.type = 'issue'
item.isFirst = false
handleProgressList.push(item)
}
})
this.setData({
handleProgressList
})
})
this.getRemarkList()
wx.setNavigationBarTitle({
title: '议题详情'
})
} else if (options.type === 'project') {
wx.setNavigationBarTitle({
title: '项目详情'
})
this.setData({
detailType: 'project',
projectId: options.detailId,
detailId: options.detailId
})
this.getProjectDetail().then(() => {
this.getProjectTypeStatistics(this.data.detailObj.firstCategoryCode)
Promise.all([this.getIssueHandleProgressV2(this.data.detailObj.issueToProjectId), this.getProjectHandleProgressV2()]).then(res => {
console.log('项目和议题处理进展', res)
const issueList = []
const projectList = []
5 years ago
res[0].forEach((item, index) => {
6 years ago
if (index === res[0].length - 1) {
item.type = 'point'
item.isFirst = true
issueList.push(item)
} else {
item.type = 'issue'
item.isFirst = false
issueList.push(item)
}
})
res[1].forEach((item, index) => {
if (index === res[1].length - 1) {
item.type = 'issueToProject'
item.isFirst = false
projectList.push(item)
} else {
item.type = 'project'
item.isFirst = false
projectList.push(item)
}
})
this.setData({
handleProgressList: [...projectList, ...issueList]
})
}).catch(err => {
console.log(err)
})
})
this.getRemarkList()
5 years ago
6 years ago
}
this.setData({
infoCompleted: app.globalData.infoCompleted
})
},
5 years ago
onReachBottom() {
6 years ago
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === 'loading') {
this.setData({
pageNo: this.data.pageNo + 1
})
this.loadMoreGetRemarkList()
}
},
// 获取议题详情
5 years ago
getIssueDetail() {
6 years ago
return new Promise((resolve, reject) => {
getIssueDetail(this.data.issueId).then(res => {
console.log('议题详情', res)
const detailObj = {}
for (const key in this.data.detailObj) {
detailObj[key] = res.data[key]
}
this.setData({
detailObj
})
resolve(true)
}).catch(err => {
console.log(err)
reject(false)
})
})
},
// 获取项目详情
5 years ago
getProjectDetail() {
6 years ago
return new Promise((resolve, reject) => {
getProjectDetail(this.data.projectId).then(res => {
console.log('项目详情', res)
const detailObj = {}
for (const key in this.data.detailObj) {
detailObj[key] = res.data[key]
}
detailObj.issueToProjectId = res.data.issueId
this.setData({
detailObj
})
resolve(true)
}).catch(err => {
console.log(err)
reject(false)
})
})
},
// 议题类别统计
5 years ago
getIssueTypeStatistics(categoryCode) {
6 years ago
getIssueTypeStatistics(categoryCode).then(res => {
console.log('议题类别统计', res)
const typeStatisticsObj = {}
for (const key in this.data.typeStatisticsObj) {
typeStatisticsObj[key] = res.data[key] || ''
}
this.setData({
typeStatisticsObj
})
}).catch(err => {
console.log(err)
})
},
// 项目类别统计
5 years ago
getProjectTypeStatistics(categoryCode) {
6 years ago
getProjectTypeStatistics(categoryCode).then(res => {
console.log('项目类别统计', res)
const typeStatisticsObj = {}
for (const key in this.data.typeStatisticsObj) {
typeStatisticsObj[key] = res.data[key] || ''
}
this.setData({
typeStatisticsObj
})
}).catch(err => {
console.log(err)
})
},
// 议题处理进展 v2
5 years ago
getIssueHandleProgressV2(issueId) {
6 years ago
return new Promise((resolve, reject) => {
getIssueHandleProgressV2(issueId).then(res => {
5 years ago
console.log('议题处理进度v2', res)
6 years ago
resolve(res.data)
}).catch(err => {
console.log(err)
reject(err)
})
})
},
// 项目处理进展 v2
5 years ago
getProjectHandleProgressV2() {
6 years ago
return new Promise((resolve, reject) => {
getProjectHandleProgressV2(this.data.projectId).then(res => {
console.log('项目处理进展', res)
resolve(res.data)
}).catch(err => {
console.log(err)
reject(err)
})
})
},
// 最新最热 评论列表切换
5 years ago
changeRemarkType(e) {
6 years ago
this.setData({
remarkType: e.detail.type,
loadMoreVisible: false
})
this.getRemarkList()
},
// 获取评论列表 下拉刷新
5 years ago
getRemarkList() {
6 years ago
this.setData({
timeStamp: formatTimestamp(),
pageNo: 1,
pageSize: 10
})
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
orderType: this.data.remarkType === 'new' ? 0 : 1,
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
getRemarkList(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)
})
},
// 获取评论列表 上拉加载
5 years ago
loadMoreGetRemarkList() {
6 years ago
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
orderType: this.data.remarkType === 'new' ? 0 : 1,
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
getRemarkList(para).then(res => {
console.log('评论列表', res)
this.setData({
remarkObj: {
statementNum: res.data.statementNum,
5 years ago
commentsList: [...this.data.remarkObj.commentsList, ...res.data.commentsList]
6 years ago
},
loadMoreType: res.data.commentsList.length === 10 ? 'loading' : 'none'
})
}).catch(err => {
console.log(err)
})
},
5 years ago
debounceSupportRemark(e) {
6 years ago
clearTimeout(this.data.supportTimer)
this.data.supportTimer = setTimeout(() => {
this.supportRemark(e)
}, 300)
},
// 评论 支持 点赞
5 years ago
supportRemark(e) {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
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,
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
5 years ago
if (this.data.detailType == 'issue') { //议题
issueComLike(para).then(res => {
console.log('评论支持', res)
}).catch(err => {
console.log(err)
})
} else {
itemComLike(para).then(res => {
console.log('评论支持', res)
}).catch(err => {
console.log(err)
})
}
// showRemarkStatement(para).then(res => {
// console.log('评论支持', res)
// }).catch(err => {
// console.log(err)
// })
6 years ago
},
5 years ago
debounceDispportRemark(e) {
6 years ago
clearTimeout(this.data.dispportTimer)
this.data.dispportTimer = setTimeout(() => {
this.dispportRemark(e)
}, 300)
},
// 评论 不支持 点踩
5 years ago
dispportRemark(e) {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
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
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,
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
5 years ago
if (this.data.detailType == 'issue') { //议题
issueComUnlike(para).then(res => {
console.log('评论不支持', res)
}).catch(err => {
console.log(err)
})
} else {
itemComUnlike(para).then(res => {
console.log('评论不支持', res)
}).catch(err => {
console.log(err)
})
}
// showRemarkStatement(para).then(res => {
// console.log('评论不支持', res)
// }).catch(err => {
// console.log(err)
// })
6 years ago
},
// 对 议题/项目 进行评论
5 years ago
navigateToReply() {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
return false
}
wx.navigateTo({
url: `/subpages/discussion/pages/remarkOrReply/remarkOrReply?detailId=${this.data.detailId}&faCommentId=&detailType=${this.data.detailType}`
})
},
// 评论 回复 回调
5 years ago
replyRemark(e) {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
return false
}
wx.navigateTo({
url: `/subpages/discussion/pages/remarkOrReply/remarkOrReply?detailId=${this.data.detailId}&faCommentId=${e.detail.commentId}&detailType=${this.data.detailType}`
})
},
5 years ago
debounceSupportIssueOrProject() {
6 years ago
clearTimeout(this.data.supportTimer)
this.data.supportTimer = setTimeout(() => {
this.supportIssueOrProject()
}, 300)
},
// 点赞 议题或评论
5 years ago
supportIssueOrProject() {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
return false
}
if (this.data.detailObj.userDislike || this.data.detailObj.userLike) {
this.setData({
dialogConformText: '知道了',
dialogContent: ['已表达过态度,不可以更改哦!'],
dialogTitle: '已表态',
dialogVisible: !this.data.dialogVisible
})
return false
}
this.setData({
['detailObj.userLike']: true,
['detailObj.approveNum']: parseInt(this.data.detailObj.approveNum) + 1
})
const para = {
attitude: '0',
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
5 years ago
// showIssueStatement(para).then(res => {
// console.log('点赞议题或项目', res)
// }).catch(err => {
// console.log(err)
// })
if (this.data.detailType == 'issue') { //议题
issueSupport(para).then(res => { //v2新接口 2020.5.8
console.log('点赞议题', res)
}).catch(err => {
console.log(err)
})
} else { //项目 itemSupport,
itemSupport(para).then(res => { //v2新接口 2020.5.8
console.log('点赞项目', res)
}).catch(err => {
console.log(err)
})
}
6 years ago
},
5 years ago
debounceDispportIssueOrProject() {
6 years ago
clearTimeout(this.data.dispportTimer)
this.data.dispportTimer = setTimeout(() => {
this.dispportIssueOrProject()
}, 300)
},
// 点踩 议题活评论
5 years ago
dispportIssueOrProject() {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
5 years ago
if (this.verifyState()) {
6 years ago
return false
}
if (this.data.detailObj.userDislike || this.data.detailObj.userLike) {
this.setData({
dialogConformText: '知道了',
dialogContent: ['已表达过态度,不可以更改哦!'],
dialogTitle: '已表态',
dialogVisible: !this.data.dialogVisible
})
return false
}
this.setData({
['detailObj.userDislike']: true,
['detailObj.opposeNum']: parseInt(this.data.detailObj.opposeNum) + 1
})
const para = {
attitude: '1',
issueId: this.data.detailType === 'issue' ? this.data.issueId : '',
itemId: this.data.detailType === 'project' ? this.data.projectId : ''
}
5 years ago
// showIssueStatement(para).then(res => {
// console.log('点踩议题或项目', res)
// }).catch(err => {
// console.log(err)
// })
if (this.data.detailType == 'issue') { //议题
issueOpposition(para).then(res => { //v2新接口 2020.5.8
console.log('点踩议题', res)
}).catch(err => {
console.log(err)
})
} else {
itemOpposition(para).then(res => { //v2新接口 2020.5.8
console.log('点踩项目', res)
}).catch(err => {
console.log(err)
})
}
6 years ago
},
// 跳转到 分类列表
5 years ago
navigateToCategoryList() {
6 years ago
if (this.data.showClassify === 'show') {
wx.navigateTo({
url: `/subpages/discussion/pages/categoryList/categoryList?type=${this.data.detailType}&categoryCode=${this.data.detailObj.firstCategoryCode}`
})
}
},
// 满意度评价
5 years ago
publishEvaluation() {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
if (this.data.detailObj.itemState !== 10) {
this.setData({
dialogConformText: '知道了',
5 years ago
dialogContent: ['项目未处理完毕或已关闭', '不能进行评价!'],
6 years ago
dialogTitle: '满意度评价',
dialogVisible: !this.data.dialogVisible
})
return false
}
wx.navigateTo({
url: `/subpages/discussion/pages/publishEvaluation/publishEvaluation?itemId=${this.data.projectId}`
})
},
// 检查 议题/项目的状态
5 years ago
verifyState() {
6 years ago
if (this.data.detailType === 'issue' && !this.data.detailObj.operational) {
this.setData({
dialogConformText: '知道了',
5 years ago
dialogContent: ['议题已关闭,不可再进行', '评论/回复/支持/不支持等表达态度'],
6 years ago
dialogTitle: '已关闭',
dialogVisible: !this.data.dialogVisible
})
return true
} else if (this.data.detailType === 'project') {
if (this.data.detailObj.itemState === 5) {
this.setData({
dialogConformText: '知道了',
5 years ago
dialogContent: ['项目已关闭,不可再进行', '评论/回复/支持/不支持等表达态度'],
6 years ago
dialogTitle: '已关闭',
dialogVisible: !this.data.dialogVisible
})
return true
} else if (this.data.detailObj.itemState === 10) {
this.setData({
dialogConformText: '知道了',
5 years ago
dialogContent: ['项目已结案,不可再进行', '评论/回复/支持/不支持等表达态度'],
6 years ago
dialogTitle: '已结案',
dialogVisible: !this.data.dialogVisible
})
return true
}
}
},
// 检查 是否完善信息
5 years ago
verifyCompleteInfo() {
6 years ago
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return true
} else {
return false
}
}
})