锦水志愿者去哪小程序
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.
 

110 lines
2.6 KiB

const app = getApp()
import getStartupPageV2 from "../../api/index"
Page({
data: {
deviceHeight: 0,
countdownNum: 0,
bgImage: "",
timer: "",
scene: "",
imgList: [],
datanum: 0, //第几个数组
datalength: 0, //数组长度
allTime:0,//总时间
},
onLoad (options) {
if (options.scene) {
this.data.scene = options.scene
}
this.setData({
deviceHeight: app.globalData.height
})
this.getStartupPage()
},
// 倒计时进入
countDown () {
this.data.timer = setInterval(() => {
if (this.data.countdownNum > 1) {
this.data.allTime--
this.data.countdownNum--
this.setData({
countdownNum: this.data.countdownNum,
allTime: this.data.allTime
})
} else {
this.data.allTime--
this.setData({
datanum: this.data.datanum + 1,
allTime: this.data.allTime
})
clearInterval(this.data.timer)
if (this.data.datalength > this.data.datanum) {
this.getloop()
} else {
if (this.data.scene) {
wx.reLaunch({
url: `/pages/heartNew/heartNew?scene=${this.data.scene}`
})
} else {
wx.reLaunch({
url: "/pages/heartNew/heartNew"
})
}
}
}
}, 1000)
},
// 立即进入
immeEnter () {
clearInterval(this.data.timer)
if (this.data.scene) {
wx.reLaunch({
url: `/pages/heartNew/heartNew?scene=${this.data.scene}`
})
} else {
wx.reLaunch({
url: "/pages/heartNew/heartNew"
})
}
},
// 获取启动页信息
getStartupPage () {
wx.showLoading({
title: "获取中..."
})
getStartupPageV2().then(res => {
wx.hideLoading()
console.log("获取启动页信息", res)
if (res.data.length > 0) {
res.data.forEach(item => {
// this.data.allTime = this.data.allTime + item.duration
this.setData({
allTime: this.data.allTime + item.duration
})
})
this.setData({
datalength: res.data.length,
imgList: res.data
})
this.getloop()
} else {
this.immeEnter()
}
}).catch(() => {
wx.hideLoading()
this.immeEnter()
})
},
//数组循环
getloop () {
if (this.data.imgList[this.data.datanum].duration > 0) {
this.setData({
bgImage: this.data.imgList[this.data.datanum].imgUrl,
countdownNum: this.data.imgList[this.data.datanum].duration
})
this.countDown()
}
}
})