|
@@ -1,20 +1,83 @@
|
|
|
+import {
|
|
|
+ getActivities
|
|
|
+} from '~/api/global'
|
|
|
Component({
|
|
|
- properties: {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
+ properties: {},
|
|
|
/**
|
|
|
* 组件的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
//,2:邀新榜,3:热播榜,4:挑战pk榜,5,朗读赛
|
|
|
- type: '4'
|
|
|
+ type: '4',
|
|
|
+ activityList: [{
|
|
|
+ id: 1,
|
|
|
+ name: '新学期限时充值活动',
|
|
|
+ closing: '2023-1-29 16:38:00',
|
|
|
+ }, {
|
|
|
+ id: 2,
|
|
|
+ name: '入学限时充值活动',
|
|
|
+ closing: '2023-1-30 16:38:00',
|
|
|
+ }],
|
|
|
+ dsqList: []
|
|
|
+ },
|
|
|
+ lifetimes: {
|
|
|
+ attached() {
|
|
|
+ this.getActivities()
|
|
|
+ },
|
|
|
+ detached() {
|
|
|
+ this.data.dsqList.forEach(item => {
|
|
|
+ clearInterval(item)
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 组件的方法列表
|
|
|
*/
|
|
|
methods: {
|
|
|
-
|
|
|
+ async getActivities() {
|
|
|
+ let res = await getActivities()
|
|
|
+ this.data.activityList.forEach((item, index) => {
|
|
|
+ this.activityTimeOut(item.closing, index)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ activityTimeOut(oTime,index) {
|
|
|
+ let inputTime = new Date(oTime)
|
|
|
+ let dsq = setInterval(() => {
|
|
|
+ console.log('执行呢');
|
|
|
+ var nowTime = new Date();
|
|
|
+ //把剩余时间毫秒数转化为秒
|
|
|
+ var times = (inputTime - nowTime) / 1000;
|
|
|
+ if (times <= 0) {
|
|
|
+ this.setData({
|
|
|
+ [`activityList[${index}].hour`]: '00',
|
|
|
+ [`activityList[${index}].minute`]: '00',
|
|
|
+ [`activityList[${index}].second`]: '00',
|
|
|
+ })
|
|
|
+ return clearInterval(dsq)
|
|
|
+ }
|
|
|
+ console.log(times);
|
|
|
+ //计算小时数 转化为整数
|
|
|
+ var h = parseInt(times / 60 / 60 % 24);
|
|
|
+ //如果小时数小于 10,要变成 0 + 数字的形式 赋值给盒子
|
|
|
+ let hour = h < 10 ? "0" + h : h;
|
|
|
+ //计算分钟数 转化为整数
|
|
|
+ var m = parseInt(times / 60 % 60);
|
|
|
+ //如果分钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
|
|
|
+ let minute = m < 10 ? "0" + m : m;
|
|
|
+ //计算描述 转化为整数
|
|
|
+ var s = parseInt(times % 60);
|
|
|
+ //如果秒钟数小于 10,要变成 0 + 数字的形式 赋值给盒子
|
|
|
+ let second = s < 10 ? "0" + s : s;
|
|
|
+ this.setData({
|
|
|
+ [`activityList[${index}].hour`]: hour,
|
|
|
+ [`activityList[${index}].minute`]: minute,
|
|
|
+ [`activityList[${index}].second`]: second,
|
|
|
+ })
|
|
|
+ times = --times;
|
|
|
+ }, 1000);
|
|
|
+ this.setData({
|
|
|
+ dsqList: [...this.data.dsqList, dsq]
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
})
|