// 换算时间 将时间换算为距当前时间 [还剩/超出] 多少分,小时,天
getDistanceTime (dateTime ) {
const _target = new Date(dateTime),
_now = new Date(),
_status = _target > _now ? 1 : -1,
_diff = Math.abs(_target - _now);
return {
status: _status,
d: Math.floor(_diff / 1000 / 60 / 60 / 24),
h: Math.floor(_diff / 1000 / 60 / 60 % 24),
m: Math.floor(_diff / 1000 / 60 % 60),
s: Math.floor(_diff / 1000 % 60)
}
}
table表格
<el-table-column
prop="title"
label="标题"
min-width="620">
<template slot-scope="scope">
<i
v-if="scope.row.title && scope.row.title != ''"
:class="scope.row.title | getDateDiffStatusClass"
>[{{ scope.row.title | getDateDiffText }}]</i
>
</template>
</el-table-column>
filters: {
getDateDiffText(val) {
let _rt = "";
if (val && val != "") {
const _dt = this.getDistanceTime(val);
let _text = _dt.status > 0 ? "截止:" : "超时:";
if (_dt.d > 0) {
_text += _dt.d + "天";
} else if (_dt.h > 0) {
_text += _dt.h + "小时";
} else if (_dt.m > 0) {
_text += _dt.m + "分";
} else if (_dt.s > 0) {
_text += _dt.s + "秒";
}
_rt = _text;
}
return _rt;
},
getDateDiffStatusClass(val) {
let _rs = 1;
if (val && val != "") {
const _dt = this.getDistanceTime(val);
_rs = _dt.status;
}
return _rs > 0 ? "before-time" : "over-time";
},
// return _rt;
},