diff --git a/pages/qianggou/productDetails.vue b/pages/qianggou/productDetails.vue index c3556b8..6eda17f 100644 --- a/pages/qianggou/productDetails.vue +++ b/pages/qianggou/productDetails.vue @@ -47,7 +47,7 @@ 立即抢购 - 还剩{{secondNum}}秒抢购 + 还剩{{finalSecondNum}}抢购 @@ -77,6 +77,7 @@ export default { }, secondNum:"", isDeadLine:true, + finalSecondNum:"", timer:null, }; }, @@ -104,32 +105,40 @@ export default { expire_time=parseInt(expire_time/1000);//过期时间 return expire_time-timestamp; }, - // dateCalculation (second) { //返回天、时、分 - // if (second > 0) { - // var day = 0; - // var hour = 0; - // var minute = 0; - // var secondNum = 0; - // var data = {}; - // minute = Math.floor(second / (60)) - // if (parseInt(secondNum) > 60) { - // minute = parseInt(secondNum / 60); - // minute %= 60; //算出有多分钟 - // } - // if (parseInt(minute) > 60) { - // hour = parseInt(minute / 60); - // minute %= 60; //算出有多分钟 - // } - // if (parseInt(hour) > 24) { - // day = parseInt(hour / 24); - // hour %= 24; //算出有多分钟 - // } - // data.day = day; - // data.hour = hour; - // data.minute = minute; - // return data; - // } - // }, + //秒数转化为时分秒 + formatSeconds(value) { + var secondTime = parseInt(value);// 秒 + var minuteTime = 0;// 分 + var hourTime = 0;// 小时 + if(secondTime > 60) {//如果秒数大于60,将秒数转换成整数 + //获取分钟,除以60取整数,得到整数分钟 + minuteTime = parseInt(secondTime / 60); + //获取秒数,秒数取余,得到整数秒数 + secondTime = parseInt(secondTime % 60); + //如果分钟大于60,将分钟转换成小时 + if(minuteTime > 60) { + //获取小时,获取分钟除以60,得到整数小时 + hourTime = parseInt(minuteTime / 60); + //获取小时后取余的分,获取分钟除以60取余的分 + minuteTime = parseInt(minuteTime % 60); + } + } + var result = "" + parseInt(secondTime) + "秒"; + + if(minuteTime > 0) { + result = "" + parseInt(minuteTime) + "分" + result; + }else{ + result = "00时" + "00" + "分" + result; + } + if(hourTime > 0) { + result = "" + parseInt(hourTime) + "时" + result; + }else{ + result = "00时" + result; + } + // console.log('result',result); + return result; + }, + timestampToTime(val) { var date = new Date(); var Y = date.getFullYear() + '-'; @@ -156,7 +165,9 @@ export default { let finishTime = this.dateDifference(new Date(time).getTime()) if(finishTime>0){ this.timer = setInterval(()=>{ - this.secondNum = finishTime-- + let secondNum = finishTime--; + this.secondNum = secondNum; + this.finalSecondNum = this.formatSeconds(this.secondNum) },1000) this.isDeadLine = false; }else{