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

231 lines
6.6 KiB

const api = require("../../../../utils/home")
var api_getResidentConfig = require("../../../../utils/api.js")
import util from "../../../../utils/util"
6 years ago
const app = getApp()
Page({
data: {
detailId: "",
supportStatus: "support",
dispportStatus: "dispport",
6 years ago
noticeObj: {},
infoCompleted: 0,
noticeObjContent: "",
residentValue:0,//配置时间
defaultGridId: '' //默认网格id
6 years ago
},
onLoad (options) {
6 years ago
this.setData({
detailId: options.id,
infoCompleted: app.globalData.infoCompleted
})
this.getNewsDetail(options.id)
this.browseNews(options.id)
// 获取默认配置
this.getResidentConfig()
6 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") {
6 years ago
that.setData({
supportStatus: "supported"
6 years ago
})
}
if (that.data.noticeObj.unLikeFlag == "1") {
6 years ago
that.setData({
dispportStatus: "dispported"
6 years ago
})
}
}).catch(err => {
console.log(err)
})
},
browseNews (id) {
6 years ago
let para = {
newsId: id
}
api.browseNews(para).then(() => {
5 years ago
6 years ago
}).catch(err => {
console.log(err)
})
},
// 检查 是否完善信息
verifyCompleteInfo () {
6 years ago
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return true
} else {
return false
}
},
newsPosition (e) {
5 years ago
// 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") {
let attitudeState = ""
if (attitude === "0") {
if (this.data.dispportStatus === "dispported") {
6 years ago
// this.dispportStatus = 'dispport'
// this.newsObj.unlikeNumber -= 1
this.setData({
dispportStatus: "dispport",
["noticeObj.unlikeNumber"]: this.data.noticeObj.unlikeNumber - 1
6 years ago
})
}
if (this.data.supportStatus === "support") {
attitudeState = "0"
6 years ago
// this.supportStatus = 'supported'
// this.newsObj.likeNumber += 1
this.setData({
supportStatus: "supported",
["noticeObj.likeNumber"]: this.data.noticeObj.likeNumber + 1
6 years ago
})
} else if (this.data.supportStatus === "supported") {
attitudeState = "2"
6 years ago
// this.supportStatus = 'support'
// this.newsObj.likeNumber -= 1
this.setData({
supportStatus: "support",
["noticeObj.likeNumber"]: this.data.noticeObj.likeNumber - 1
6 years ago
})
}
} else if (attitude === "1") {
if (this.data.supportStatus === "supported") {
6 years ago
// this.supportStatus = 'support'
// this.newsObj.likeNumber -= 1
this.setData({
supportStatus: "support",
["noticeObj.likeNumber"]: this.data.noticeObj.likeNumber - 1
6 years ago
})
}
if (this.data.dispportStatus === "dispport") {
attitudeState = "1"
6 years ago
// this.dispportStatus = 'dispported'
// this.newsObj.unlikeNumber += 1
this.setData({
dispportStatus: "dispported",
["noticeObj.unlikeNumber"]: this.data.noticeObj.unlikeNumber + 1
6 years ago
})
} else if (this.data.dispportStatus === "dispported") {
attitudeState = "3"
6 years ago
// this.dispportStatus = 'dispport'
// this.newsObj.unlikeNumber -= 1
this.setData({
dispportStatus: "dispport",
["noticeObj.unlikeNumber"]: this.data.noticeObj.unlikeNumber - 1
6 years ago
})
}
}
const para = {
newsId: this.data.detailId,
attitude: attitudeState
}
5 years ago
console.log(attitudeState)
if (attitudeState == 0) { //表态 0赞;1踩;2取消赞;3取消踩
api.newsSupport(para).then(() => {
5 years ago
}).catch(err => {
console.log(err)
})
5 years ago
} else if (attitudeState == 1) {
api.newsOpposition(para).then(() => {
5 years ago
5 years ago
}).catch(err => {
console.log(err)
})
} else {
// const res = await newsPosition(para)
// console.log('新闻表态', res)
api.newsPosition(para).then(() => {
5 years ago
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
}
},
// 获取默认配置, 阅读时间, 获取默认网格
getResidentConfig (){
let that = this
api_getResidentConfig.getResidentConfig().then(res => {
if (res.code === 0 && res.msg === "success") {
res.data.forEach(item => {
if (item.residentType === "poins_config" && item.residentCode === "news_browse_time") {
that.setData({
residentValue:parseInt(item.residentValue)
})
} else if (item.residentCode === "default_grid" && item.residentType === "default_grid") {
that.setData({
defaultGridId: item.residentValue
})
}
})
that.countDown()
}
}).catch(err => {
console.log(err)
})
},
// 倒计时
countDown () {
if (this.data.infoCompleted == 0) {
return
}
this.data.timer = setInterval(() => {
console.log("加积分倒计时"+this.data.residentValue)
if (this.data.residentValue > 1) {
this.data.residentValue--
this.setData({
residentValue: this.data.residentValue
})
} else {
this.browsePoints()
clearInterval(this.data.timer)
}
}, 1000)
},
// 加积分
browsePoints () {
let that = this
const para = {
newsId: that.data.detailId
}
api.browsePoints(para).then(res => {
console.log("加积分成功",res)
}).catch(err => {
console.log(err)
})
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
clearInterval(this.data.timer)
},
//2020.7.29 新闻转发-没注册过的人进入默认网格
onShareAppMessage(res) {
return {
title: '新闻资讯-新闻详情',
path: `/pages/indexNew/indexNew?shareType=newsDetail&detailId=${this.data.detailId}&defaultGridId=${this.data.defaultGridId}`
}
},
6 years ago
})