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.
140 lines
4.0 KiB
140 lines
4.0 KiB
6 years ago
|
const api = require('../../../../utils/home')
|
||
|
import { getTimestamp } from '../../../../utils/common'
|
||
|
import util from '../../../../utils/util'
|
||
|
const app = getApp()
|
||
|
Page({
|
||
|
data: {
|
||
|
detailId: '',
|
||
|
supportStatus: 'support',
|
||
|
dispportStatus: 'dispport',
|
||
|
noticeObj: {},
|
||
|
infoCompleted: 0,
|
||
|
noticeObjContent: ''
|
||
|
},
|
||
|
onLoad (options) {
|
||
|
this.setData({
|
||
|
detailId: options.id,
|
||
|
infoCompleted: app.globalData.infoCompleted
|
||
|
})
|
||
|
this.getNewsDetail(options.id)
|
||
|
this.browseNews(options.id)
|
||
|
},
|
||
|
getNewsDetail (id) {
|
||
|
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)
|
||
|
})
|
||
|
},
|
||
|
browseNews (id) {
|
||
|
let para = {
|
||
|
newsId: id
|
||
|
}
|
||
|
api.browseNews(para).then(res => {
|
||
|
|
||
|
}).catch(err => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
},
|
||
|
// 检查 是否完善信息
|
||
|
verifyCompleteInfo () {
|
||
|
if (this.data.infoCompleted == 0) {
|
||
|
this.setData({
|
||
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
||
|
})
|
||
|
return true
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
},
|
||
|
newsPosition (e) {
|
||
|
// newsPosition (attitude, bySelf = false) {
|
||
|
if (this.verifyCompleteInfo()) {
|
||
|
return false
|
||
|
}
|
||
|
console.log(e)
|
||
|
let attitude = e.currentTarget.dataset.state,
|
||
|
bySelf = e.currentTarget.dataset.byself
|
||
|
if (bySelf=='true') {
|
||
|
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
|
||
|
}
|
||
|
// const res = await newsPosition(para)
|
||
|
// console.log('新闻表态', res)
|
||
|
api.newsPosition(para).then(res => {
|
||
|
|
||
|
}).catch(err => {
|
||
|
console.log(err)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|