...
|
...
|
@@ -5,6 +5,7 @@ |
|
|
*/
|
|
|
var $ = require('yoho-jquery'),
|
|
|
IScroll = require('yoho-iscroll'),
|
|
|
tip = require('../plugin/tip'),
|
|
|
seckillObj = {};
|
|
|
|
|
|
seckillObj = {
|
...
|
...
|
@@ -40,7 +41,7 @@ seckillObj = { |
|
|
that.initNav();
|
|
|
|
|
|
if (focus.length && (focus.hasClass('now') || focus.hasClass('wait'))) {
|
|
|
that.initTick($('.nav-ul>li.focus'));
|
|
|
that.initTick($el.$navUl.find('>li.focus'));
|
|
|
}
|
|
|
},
|
|
|
|
...
|
...
|
@@ -53,7 +54,7 @@ seckillObj = { |
|
|
$el.timeWidth = ($el.$navUl.find('>li:not(.focus)').width() + 1);
|
|
|
$el.focusTimeWidth = ($el.$navUl.find('>li.focus').width() + 1);
|
|
|
|
|
|
$el.$navUl.width(($el.times - 1) * $el.timeWidth + $el.focusTimeWidth).removeClass('hide');
|
|
|
$el.$navUl.width($el.times * $el.timeWidth + $el.focusTimeWidth).removeClass('hide');
|
|
|
|
|
|
// 只有时间段大于3个才需要定位
|
|
|
if ($el.$navUl.find('>li').length > 3 && $el.$navUl.find('>li.focus').length) {
|
...
|
...
|
@@ -129,17 +130,24 @@ seckillObj = { |
|
|
}
|
|
|
}
|
|
|
|
|
|
if ($el.currentTick) {
|
|
|
clearTimeout($el.currentTick);
|
|
|
$el.currentTick = undefined;
|
|
|
}
|
|
|
|
|
|
if ($(elem).hasClass('now') || $(elem).hasClass('wait')) {
|
|
|
// 初始化倒计时并开始计时
|
|
|
that.initTick(elem);
|
|
|
}
|
|
|
// 刷新商品列表
|
|
|
that.refreshProductList($(elem).find('input.activityId').val());
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* [刷新状态]
|
|
|
*/
|
|
|
refreshList: function(elem) {
|
|
|
var $el = this.el, time, nowTime, nextTime;
|
|
|
var $el = this.el, that = this, time, nowTime, nextTime;
|
|
|
|
|
|
// 刷新时间段状态
|
|
|
$el.$navUl.find('>li').each(function() {
|
...
|
...
|
@@ -159,14 +167,32 @@ seckillObj = { |
|
|
} else { // 大于这个时间段但是后面没有秒抢时间端了,则依然显示抢购中
|
|
|
$(this).addClass('now');
|
|
|
}
|
|
|
} else if (!$(this).hasClass('nothing')) {
|
|
|
} else {
|
|
|
$(this).addClass('wait');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 刷新列表状态
|
|
|
console.log('刷新啊');
|
|
|
console.log(elem);
|
|
|
// 刷新商品列表
|
|
|
var focusElem = $el.$navUl.find('>li.focus');
|
|
|
if (focusElem.length) {
|
|
|
that.refreshProductList(focusElem.find('input.activityId').val());
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* [异步加载商品列表]
|
|
|
*/
|
|
|
refreshProductList: function(activityId) {
|
|
|
$.ajax({
|
|
|
url: '/product/seckill/get-product-list',
|
|
|
data: {
|
|
|
activityId: activityId
|
|
|
},
|
|
|
success: function(data) {
|
|
|
$('.product-list').html(data);
|
|
|
},
|
|
|
error: function(data) {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -178,14 +204,10 @@ seckillObj = { |
|
|
nowTime = Date.parse(new Date()) / 1000,
|
|
|
offsetTime;
|
|
|
|
|
|
if ($el.currentTick) {
|
|
|
clearTimeout($el.currentTick);
|
|
|
}
|
|
|
|
|
|
if ($(elem).hasClass('now')) {
|
|
|
time = Date.parse(new Date($(elem).next().find('input.date').val())) / 1000;
|
|
|
time = $(elem).next().find('input.date').val() / 1000;
|
|
|
} else {
|
|
|
time = Date.parse(new Date($(elem).find('input.date').val())) / 1000;
|
|
|
time = $(elem).find('input.date').val() / 1000;
|
|
|
}
|
|
|
offsetTime = time - nowTime;
|
|
|
that.startTick(elem, offsetTime);
|
...
|
...
|
@@ -196,20 +218,24 @@ seckillObj = { |
|
|
*/
|
|
|
startTick: function(elem, offsetTime) {
|
|
|
var that = this,
|
|
|
$el = this.el,
|
|
|
hour = parseInt(offsetTime / (60 * 60), 10),
|
|
|
minute = parseInt(offsetTime % (60 * 60) / 60, 10),
|
|
|
second = offsetTime % 60;
|
|
|
|
|
|
$(elem).find('.tick.hour').text(hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour));
|
|
|
$(elem).find('.tick.minute').text(minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute));
|
|
|
$(elem).find('.tick.second').text(second < 0 ? '00' : (second < 10 ? ('0' + second) : second));
|
|
|
if (offsetTime <= 0) { // 结束倒计时刷新状态
|
|
|
that.refreshList(elem);
|
|
|
} else {
|
|
|
setTimeout(function() {
|
|
|
that.startTick(elem, --offsetTime);
|
|
|
}, 1000);
|
|
|
if (offsetTime) {
|
|
|
$(elem).find('.tick.hour').text(hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour));
|
|
|
$(elem).find('.tick.minute').text(minute < 0 ? '00' : (minute < 10 ? ('0' + minute) : minute));
|
|
|
$(elem).find('.tick.second').text(second < 0 ? '00' : (second < 10 ? ('0' + second) : second));
|
|
|
if (offsetTime <= 0) { // 结束倒计时刷新状态
|
|
|
that.refreshList(elem);
|
|
|
} else {
|
|
|
$el.currentTick = setTimeout(function() {
|
|
|
that.startTick(elem, --offsetTime);
|
|
|
}, 1000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|