search.js
5.91 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
function filterAction(options){
var params = new Object();
options = options || {};
params['brand']=options.brand||null;
params['color']=options.color||null;
params['msort']=options.msort||null;
params['misort']=options.misort||null;
params['day']=options.day||null;
params['discount']=options.discount||null;
params['price']=options.price||null;
params['size']=options.size||null;
params['gender']=options.gender||null;
params['query'] = options.query||null;
params['specialsale_id'] = options.specialsale_id||null;
var url = options.url||null;
var okbtn = options.okbtn || $('.filterBox .ok');
var style = $('.box')[0].style;
$('p.nav').bind("click",function(){
showNavList($(this));
})
$('.selectCon p').bind('click', function(){
selectAction($(this));
});
//点击清空按钮事件
$('.filterBox .clear').bind("click",function(){
$('.filterBox p').removeClass('selected');
$('.filterBox p.all').addClass('selected');
$('.brand p.all').removeClass('selected');
clearBrand();
$('p.nav .selected').text('全部');
deleteALl();
goUrl();
})
function deleteALl(){
delete params['brand'];
delete params['color'];
delete params['msort'];
delete params['misort'];
delete params['day'];
delete params['discount'];
delete params['price'];
delete params['size'];
delete params['query'];
}
//点击p.nav事件
function showNavList(ele){
ele.parent().children('.selectCon').toggleClass('hide');
ele.toggleClass('show').children().last().toggleClass('show');
}
//点击小分类选选中状态;
function selectAction(ele){
var cl = ele.parent().parent().attr('class');
var cl2 =ele.attr('name')
var text = '全部';
if(cl!="brand"){
ele.parent().children().removeClass('selected');
ele.addClass('selected');
if(!ele.hasClass('all')){
ele.css('background-position','235px');
text = ele.text();
}
showNavList(ele.parent().parent().children().first());
params[cl2] = ele.attr('value');
}else{
var text = selectBrand(ele);
}
changeAction(cl,text);
}
//修改选中条件
function changeAction(cl,text){
$('li.'+cl+' span.selected').text(text)
}
//选择品牌条件
function selectBrand(ele){
var brands='';
var span = ele.children();
var first = span.first();
var second = span.eq(1)
var cl = first.attr('class');
if(!ele.hasClass('all')){
if(cl == "check"){
first.removeClass("check").addClass('uncheck');
second.css('color','#767676');
}else{
first.removeClass("uncheck").addClass('check');
second.css('color','#f00');
}
}
var check = $('.brand span.check');
var length = check.length;
if(length>0){
if(length > 1){
var text = check.eq(0).parent().children().last().text()+'等'+length+'个';
}else{
var text = check.eq(0).parent().children().last().text();
}
}else{
var text = '全部';
}
$('.brand p.all').children().first().text("已选择:"+length+"个(可多选)")
return text;
}
//清楚品牌筛选条件
$('.brand p.all .delete').click(function(){
clearBrand();
showNavList($('ul li.brand p.nav'));
})
//清楚品类筛选条件
$('.category p.all').click(function(){
delete params['msort'];
delete params['misort'];
})
//点击大分类清除小分类
$('.category p.msort ').click(function(){
delete params['misort'];
})
//清除品牌条件方法
function clearBrand(){
$('.brand .selectCon span.check').removeClass('check').addClass('uncheck');
$('.brand .selectCon span').css('color','#767676');
$('.brand p.all').children().first().text("已选择:0个(可多选)");
delete params['brand'];
}
function getSelectBrand(){
var p = $('ul li.brand .selectCon p');
params['brand'] = ''
$.each(p,function(){
if($(this).children().first().hasClass('check')){
params['brand']+=$(this).attr('value');
params['brand']+=',';
}
})
return params['brand'];
}
//刷选面板移动事件
function scoll(width){
style.webkitTransitionDuration =
style.MozTransitionDuration =
style.msTransitionDuration =
style.OTransitionDuration =
style.transitionDuration = '400ms';
style.webkitTransform = 'translate(' + width + 'px,0)' + 'translateZ(0)';
style.msTransform =
style.MozTransform =
style.OTransform = 'translateX(' + width + 'px)';
}
//显示筛选面板事件
$("ul li.filter").on("click",function(){
scoll(-275);
createCover();
});
//关闭筛选面板事件
$(".close").on("click",function(){
delCover();
scoll(0);
})
//当滚动条滚动时
$(window).bind("scroll", function(){
var h = $(document).scrollTop();
if(h>45){
$('.filterHeader').css('top', h-45+'px');
}else{
$('.filterHeader').css('top', '0px');
}
})
//点击确定按钮事件
okbtn.on('touch click',function(){
goUrl();
});
//生成一蒙版
function createCover(){
var boarddiv = "<div class='cover' style='background:#000;width:100%;height:100%;z-index:999;position:absolute;top:0;opacity: 0.5;filter:alpha(opacity=50);-moz-opacity:0.5;-khtml-opacity: 0.5; '></div>";
$('.box').append(boarddiv);
var cover = $('.box .cover');
cover.on("click",function(){
delCover();
scoll(0);
});
}
//删除蒙版
function delCover(){
var cover = $('.box .cover');
cover.remove();
}
function goUrl(){
var query = '';
getSelectBrand();
for (var p in params) {
if (params[p]) {
query += '&' + p + '=' + params[p];
}
}
if(url == null){
location.href = 'http://'+window.location.host+window.location.pathname+'?'+query;
}else{
location.href = 'http://'+url+'?'+query;
}
}
}