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

164 lines
4.6 KiB

6 years ago
const api = require('../../../../utils/home')
5 years ago
import {
getTimestamp
} from '../../../../utils/common'
6 years ago
import util from '../../../../utils/util'
const app = getApp()
Page({
data: {
detailId: '',
supportStatus: 'support',
dispportStatus: 'dispport',
noticeObj: {},
infoCompleted: 0,
noticeObjContent: ''
},
5 years ago
onLoad(options) {
6 years ago
this.setData({
detailId: options.id,
infoCompleted: app.globalData.infoCompleted
})
this.getNewsDetail(options.id)
this.browseNews(options.id)
},
5 years ago
getNewsDetail(id) {
6 years ago
let that = this
api.getNewsDetail(id).then(res => {
that.setData({
noticeObj: res.data,
noticeObjContent: util.formatRichText(res.data.newsContent)
})
if (that.data.noticeObj.likeFlag == '1') {
that.setData({
supportStatus: 'supported'
})
}
if (that.data.noticeObj.unLikeFlag == '1') {
that.setData({
dispportStatus: 'dispported'
})
}
}).catch(err => {
console.log(err)
})
},
5 years ago
browseNews(id) {
6 years ago
let para = {
newsId: id
}
api.browseNews(para).then(res => {
5 years ago
6 years ago
}).catch(err => {
console.log(err)
})
},
// 检查 是否完善信息
5 years ago
verifyCompleteInfo() {
6 years ago
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return true
} else {
return false
}
},
5 years ago
newsPosition(e) {
// newsPosition (attitude, bySelf = false) {
6 years ago
if (this.verifyCompleteInfo()) {
return false
}
console.log(e)
let attitude = e.currentTarget.dataset.state,
5 years ago
bySelf = e.currentTarget.dataset.byself
if (bySelf == 'true') {
6 years ago
let attitudeState = ''
if (attitude === '0') {
if (this.data.dispportStatus === 'dispported') {
// this.dispportStatus = 'dispport'
// this.newsObj.unlikeNumber -= 1
this.setData({
dispportStatus: 'dispport',
['noticeObj.unlikeNumber']: this.data.noticeObj.unlikeNumber - 1
})
}
if (this.data.supportStatus === 'support') {
attitudeState = '0'
// this.supportStatus = 'supported'
// this.newsObj.likeNumber += 1
this.setData({
supportStatus: 'supported',
['noticeObj.likeNumber']: this.data.noticeObj.likeNumber + 1
})
} else if (this.data.supportStatus === 'supported') {
attitudeState = '2'
// this.supportStatus = 'support'
// this.newsObj.likeNumber -= 1
this.setData({
supportStatus: 'support',
['noticeObj.likeNumber']: this.data.noticeObj.likeNumber - 1
})
}
} else if (attitude === '1') {
if (this.data.supportStatus === 'supported') {
// this.supportStatus = 'support'
// this.newsObj.likeNumber -= 1
this.setData({
supportStatus: 'support',
['noticeObj.likeNumber']: this.data.noticeObj.likeNumber - 1
})
}
if (this.data.dispportStatus === 'dispport') {
attitudeState = '1'
// this.dispportStatus = 'dispported'
// this.newsObj.unlikeNumber += 1
this.setData({
dispportStatus: 'dispported',
['noticeObj.unlikeNumber']: this.data.noticeObj.unlikeNumber + 1
})
} else if (this.data.dispportStatus === 'dispported') {
attitudeState = '3'
// this.dispportStatus = 'dispport'
// this.newsObj.unlikeNumber -= 1
this.setData({
dispportStatus: 'dispport',
['noticeObj.unlikeNumber']: this.data.noticeObj.unlikeNumber - 1
})
}
}
const para = {
newsId: this.data.detailId,
attitude: attitudeState
}
5 years ago
console.log(attitudeState)
if (attitudeState == 0) { //表态 0赞;1踩;2取消赞;3取消踩
5 years ago
api.newsSupport(para).then(res => {
}).catch(err => {
console.log(err)
})
5 years ago
} else if (attitudeState == 1) {
5 years ago
api.newsOpposition(para).then(res => {
5 years ago
}).catch(err => {
console.log(err)
})
} else {
// const res = await newsPosition(para)
// console.log('新闻表态', res)
api.newsPosition(para).then(res => {
5 years ago
}).catch(err => {
console.log(err)
})
}
6 years ago
// const res = await newsPosition(para)
// console.log('新闻表态', res)
5 years ago
// api.newsPosition(para).then(res => {
6 years ago
5 years ago
// }).catch(err => {
// console.log(err)
// })
6 years ago
}
}
})