sale.page.js
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
product = require('../plugins/product');
var limitTime = [];
var $saleBox = $('.sale-box'),
$navItem = $('.sale-nav li');
require('../common');
require('./sale/banner');
require('../plugins/slider');
require('../plugins/filter');
require('../plugins/sort-pager');
product.init(4);
lazyLoad($('img.lazy'));
$('.slide-container').slider();
// 请求带导航的列表数据
function getNaviData(items) {
var location, url, goodItems, navTitle;
navTitle = items.attr('urlLocation');
location = '/product/sale/goods';
goodItems = items.parent().parent('.sale-box').find('.goods');
url = location + navTitle;
$.ajax({
type: 'GET',
url: url,
data: ''
}).then(function(res) {
goodItems.html('');
goodItems.append(res);
lazyLoad($('img.lazy'));
});
}
$navItem.on('click', function() {
$(this).siblings('.active').removeClass('active');
$(this).addClass('active');
getNaviData($(this));
});
// 初始化页面数据
(function() {
$saleBox.each(function() {
var item = $(this).find($navItem).eq(0);
getNaviData(item);
});
}());
function convertTime(time) {
var anHour = 3600000,
aMinute = 60000,
aSecond = 1000,
showTime = '',
d = 0,
h = 0,
m = 0,
s = 0;
if (time > 1000) {
d = Math.floor(time / anHour / 24);
h = Math.floor(time / anHour % 24);
m = Math.floor(time / aMinute % 60);
s = Math.floor(time / aSecond % 60);
showTime += d > 0 ? d + '天' : '';
showTime += h > 0 ? h + '小时' : '';
showTime += m > 0 ? m + '分钟' : '';
showTime += s > 0 ? s + '秒' : '';
}
return showTime;
}
function setPageTime() {
var i, showTime;
for (i = 0; i < limitTime.length; i++) {
limitTime[i].time -= 1000;
showTime = convertTime(limitTime[i].time);
$('.time-calculate').removeClass('hidden');
$('.time-calculate').text(showTime);
}
}
if (('.sale-discount-page').length > 0) {
$('.time-calculate').each(function() {
var data = $(this).attr('data');
if (data) {
limitTime.push({
dom: $(this),
time: data
});
}
});
setInterval(setPageTime, 1000);
}