<!--
* 倒计时
-->
<template>
<span class="contDown-tip">{{countdownTxt}}</span>
</template>
<script>
export default {
name: "countDown",
data() {
return {
countdownTxt: "",
countdownTime: ""
};
},
props: {
auditExpiredTime: {
type: [String, Number],
default: 0
}
},
beforeDestroy() {
this.clearCountDown()
},
mounted() {
},
watch:{
auditExpiredTime: {
handler: function (val, oldVal){
this.clearCountDown()
this.countdownFun(val)
},
immediate: true
},
},
methods: {
countdownFun(endTime) {
endTime = endTime || 0
if (endTime) {
let diffTime = Math.floor((endTime - new Date().getTime()) / 1000);
if (diffTime > 0) {
this.countdownTime = setInterval(() => {
let diffM =
Math.floor(diffTime / 60) > 9
? Math.floor(diffTime / 60)
: `0${Math.floor(diffTime / 60)}`;
let diffS =
Math.floor(diffTime % 60) > 9
? Math.floor(diffTime % 60)
: `0${Math.floor(diffTime % 60)}`;
this.countdownTxt = `${diffM}:${diffS}`;
diffTime--;
if (diffTime <= 0) {
this.clearCountDown()
this.$emit("timeOver");
return;
}
}, 1000);
}
}else {
this.clearCountDown()
this.countdownTxt = ``;
}
},
clearCountDown(){
if(this.countdownTime){
clearTimeout(this.countdownTime);
this.countdownTime = ""
}
}
},
computed: {}
};
</script>
<style lang="less" scoped>
.contDown-tip {
display: inline-block;
color: #1f5cb6;
margin-left: 4px;
}
</style>
import countDown from "@/components/countDown";
<countDown :auditExpiredTime="scope.row.auditExpiredTime"
@timeOver="timeOver"
v-if="scope.row.auditExpiredTime > 0 && scope.row.auditStatus === 0" />
timeOver() {
this.list();
},