Authored by 阿达

订单列表增加倒计时

... ... @@ -34,6 +34,67 @@ var orderHammer,
$reaMask = $('.reason-mask'),
reasonSwiper;
// 减少计时
function downCount(item) {
var hoursItem = item.find('.hours');
var difference = hoursItem.text(),// difference of dates
interval;
/**
* Main downCount function that calculates everything
*/
function countdown() {
// basic math variables
var _second = 1000,
_minute = _second * 60,
_hour = _minute * 60,
_day = _hour * 24,
days,
hours,
minutes,
seconds;
// calculate dates
days = Math.floor(difference / _day),
hours = Math.floor((difference % _day) / _hour),
minutes = Math.floor((difference % _hour) / _minute),
seconds = Math.floor((difference % _minute) / _second);
// fix dates so that it will show two digets
days = (String(days).length >= 2) ? days : '0' + days;
hours = (String(hours).length >= 2) ? hours : '0' + hours;
minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes;
seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds;
// set to DOM
item.removeClass('hide');
hoursItem.text('剩余' + hours + ':' + minutes + ':' + seconds);
difference -= 1000;
if (difference < 0) {
clearInterval(interval);// stop timer
return;
}
}
if (difference !== '' && difference > 0) {
interval = setInterval(countdown, 1000);// start
}
}
// 初始化时间
function setTime() {
$('.orders').each(function() {
var item = $(this).find('.count-down');
if (!$(this).hasClass('hide')) {
downCount(item);
}
});
}
//加载订单
function getOrders(option) {
var opt = {
... ... @@ -82,6 +143,7 @@ function getOrders(option) {
inAjax = false;
show && loading.hideLoadingMask();
setTime();
}
});
}
... ...
... ... @@ -121,6 +121,36 @@
border: none;
margin-left: 20px;
}
.count-down {
list-style: none;
padding: 0;
display: inline-block;
text-align: right;
font-size: 24px;
color:#b0b0b0;
float:left;
margin-left: 30px;
margin-top: 20px;
.count-down-icon {
margin-top: -8px;
font-size: 30px;
}
&.hide {
display: none;
}
li {
display: inline-block;
}
li span {
font-size: 24px;
line-height: 24px;
}
}
}
}
... ...
... ... @@ -26,6 +26,14 @@
{{#if unpaid}}
<div class="order-opt">
<ul class="count-down">
<li>
<span class="iconfont count-down-icon">&#xe64a;</span>
</li>
<li>
<span class="hours">{{leftTime}}</span>
</li>
</ul>
<span class="btn cancel">取消订单</span>
{{#if payUrl}}
<a class="locHref" href="{{payUrl}}">
... ...