sale.page.js
2.96 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* sale页面
* @author: da<abel.wang@yoho.cn>
* @date: 2016/05/31
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
product = require('./index/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');
require('./detail/latest-walk');
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(items.closest('.sale-box').find('.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, text, showTime;
for (i = 0; i < limitTime.length; i++) {
if (limitTime[i].time < 0) {
$('.time').addClass('hide');
return;
}
limitTime[i].time -= 1000;
showTime = convertTime(limitTime[i].time);
if (showTime) {
text = showTime;
if (limitTime[i].pre) {
text = limitTime[i].pre + ' ' + text;
}
$('.time-calculate').removeClass('hide');
$('.time-calculate').text(showTime);
} else {
text = '活动已结束';
$('.time').addClass('hide');
}
}
if (limitTime.length === 0) {
$('.time').addClass('hide');
}
}
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);
}