|
@@ -0,0 +1,103 @@
|
|
|
|
+import {OrderPayStatus} from "$utils/control/order/const/order";
|
|
|
|
+
|
|
|
|
+export default {
|
|
|
|
+
|
|
|
|
+ // 倒计时
|
|
|
|
+ data(){
|
|
|
|
+ return {
|
|
|
|
+ timeFormat:'',
|
|
|
|
+ format:['天','时','分','秒'],
|
|
|
|
+ OrderPayStatus
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ watch:{
|
|
|
|
+ item:{
|
|
|
|
+ handler(){
|
|
|
|
+ this.createdStatusTime(this.item)
|
|
|
|
+ },
|
|
|
|
+ immediate:true
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ methods:{
|
|
|
|
+
|
|
|
|
+ createdStatusTime(item){
|
|
|
|
+ this.statusConfig && clearTimeout(this.statusConfig.callTime);
|
|
|
|
+ // 如果为进行中触发
|
|
|
|
+ if (item.oid && item.status === OrderPayStatus.have) {
|
|
|
|
+
|
|
|
|
+ let localTime = Math.floor(new Date().getTime() / 1000);
|
|
|
|
+
|
|
|
|
+ let receive_time = item.receive_time;
|
|
|
|
+ if (receive_time === 0) {
|
|
|
|
+ receive_time = localTime;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.statusConfig = {
|
|
|
|
+ callTime:null,
|
|
|
|
+ endTime:receive_time + (item.num * 3600),
|
|
|
|
+ localTime: Math.floor(new Date().getTime() / 1000),
|
|
|
|
+ };
|
|
|
|
+ this.triggerCallTime();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ triggerCallUseTime() {
|
|
|
|
+ this.statusConfig.callTime = setTimeout(()=> this.triggerCallTime(),1000);
|
|
|
|
+ return true;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ triggerCallTime(){
|
|
|
|
+
|
|
|
|
+ // 获取差值
|
|
|
|
+ let diff = this.statusConfig.endTime - this.statusConfig.localTime;
|
|
|
|
+
|
|
|
|
+ // 当前时间
|
|
|
|
+ this.statusConfig.localTime = Math.floor(new Date().getTime() / 1000);
|
|
|
|
+ if(diff > 0) {
|
|
|
|
+ let useTimeData = [];
|
|
|
|
+ // 计算 天
|
|
|
|
+ useTimeData.push(Math.floor(diff / 60 / 60 / 24));
|
|
|
|
+ // 计算小时
|
|
|
|
+ useTimeData.push(Math.floor(diff / 60 / 60 % 24));
|
|
|
|
+ // 计算分钟
|
|
|
|
+ useTimeData.push(Math.floor(diff/ 60 % 60));
|
|
|
|
+ // 计算秒
|
|
|
|
+ useTimeData.push(Math.floor(diff % 60));
|
|
|
|
+
|
|
|
|
+ let timeFormat = '';
|
|
|
|
+
|
|
|
|
+ this.format.map((item,index)=>{
|
|
|
|
+
|
|
|
|
+ if (index ===0 && useTimeData[index] <=0) return;
|
|
|
|
+ else {
|
|
|
|
+ timeFormat+= (useTimeData[index]<10?'0'+useTimeData[index]:useTimeData[index])+item;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ this.timeFormat = timeFormat;
|
|
|
|
+
|
|
|
|
+ return this.triggerCallUseTime();
|
|
|
|
+ } else {
|
|
|
|
+ return this.triggerEndCall();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ triggerEndCall(){
|
|
|
|
+ this.timeFormat = '';
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ beforeUnmount() {
|
|
|
|
+ this.statusConfig && clearTimeout(this.statusConfig.callTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|