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.
78 lines
1.8 KiB
78 lines
1.8 KiB
const homeApi = require('../../../../utils/home')
|
|
|
|
Page({
|
|
data: {
|
|
detailObj: {},
|
|
detailId: '',
|
|
detailObjContent: '',
|
|
residentValue: 0,
|
|
},
|
|
onLoad(option) {
|
|
if (option.id) {
|
|
this.setData({
|
|
detailId: option.id
|
|
})
|
|
this.getDetail()
|
|
this.getResidentConfig()
|
|
}
|
|
},
|
|
onUnload () {
|
|
clearInterval(this.data.timer)
|
|
},
|
|
// 加积分
|
|
browsePoints () {
|
|
let that = this
|
|
const para = {
|
|
newsId: that.data.detailId
|
|
}
|
|
homeApi.browsePoints(para).then(res => {
|
|
console.log("加积分成功",res)
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 获取默认配置, 阅读时间, 获取默认网格
|
|
getResidentConfig (){
|
|
let that = this
|
|
homeApi.getResidentConfig().then(res => {
|
|
if (res.code === 0 && res.msg === "success") {
|
|
res.data.forEach(item => {
|
|
if (item.residentCode === "news_browse_time") {
|
|
that.setData({
|
|
residentValue: parseInt(item.residentValue)
|
|
})
|
|
}
|
|
})
|
|
that.countDown()
|
|
}
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 倒计时
|
|
countDown () {
|
|
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)
|
|
},
|
|
getDetail() {
|
|
homeApi.contentDetail(this.data.detailId).then(res => {
|
|
console.log(res)
|
|
this.setData({
|
|
detailObj: res.data,
|
|
detailObjContent: res.data.noticeContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto"')
|
|
})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
}
|
|
})
|