90 lines
2.4 KiB
JavaScript
90 lines
2.4 KiB
JavaScript
// packageE/member/component/timeOver/timeOver.js
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
datas: {
|
|
type: null,
|
|
},
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {},
|
|
observers: {
|
|
datas: function (b) {
|
|
let that = this;
|
|
console.log(b);
|
|
if (b.project_shell_type == 3) {
|
|
console.log(`${b.lock_update_at}000`);
|
|
let istime = Number(`${b.lock_update_at}000`);
|
|
let time = that.formatDate(istime);
|
|
this.data.timeOver = setInterval(() => {
|
|
const nowDaytime = new Date().getTime();
|
|
// let lastTime = (istime - nowDaytime) /1000
|
|
that._countDown(istime, nowDaytime);
|
|
}, 1000);
|
|
that.setData({
|
|
nowtime: time,
|
|
});
|
|
console.log(time);
|
|
}
|
|
},
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
_countDown(istime, nowDaytime) {
|
|
if (istime - nowDaytime < 0) {
|
|
clearInterval(this.data.timeOver);
|
|
this.setData({
|
|
lastTime: "0",
|
|
});
|
|
return;
|
|
}
|
|
let time = (istime - nowDaytime) / 1000;
|
|
// 获取天、时、分、秒
|
|
let day = parseInt(time / (60 * 60 * 24));
|
|
let hou = parseInt((time % (60 * 60 * 24)) / 3600);
|
|
let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
|
|
let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
|
|
let obj = {
|
|
day: this._timeFormat(day),
|
|
hou: this._timeFormat(hou),
|
|
min: this._timeFormat(min),
|
|
sec: this._timeFormat(sec),
|
|
};
|
|
this.setData({
|
|
lastTime: `${obj.day}天${obj.hou}时${obj.min}分${obj.sec}秒`,
|
|
});
|
|
},
|
|
//小于10的格式化函数
|
|
_timeFormat(param) {
|
|
//小于10的格式化函数
|
|
return param < 10 ? "0" + param : param;
|
|
},
|
|
formatDate(date) {
|
|
console.log(date);
|
|
// var date = new Date(date);
|
|
var YY = date.getFullYear() + "-";
|
|
var MM =
|
|
(date.getMonth() + 1 < 10
|
|
? "0" + (date.getMonth() + 1)
|
|
: date.getMonth() + 1) + "-";
|
|
var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
|
var hh =
|
|
(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
|
|
var mm =
|
|
(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
|
|
":";
|
|
var ss =
|
|
date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
|
|
return YY + MM + DD + " " + hh + mm + ss;
|
|
},
|
|
},
|
|
});
|