|
@@ -12,14 +12,10 @@ require('./shop/coupon'); |
|
@@ -12,14 +12,10 @@ require('./shop/coupon'); |
12
|
|
12
|
|
13
|
let Tab = require('plugin/tab');
|
13
|
let Tab = require('plugin/tab');
|
14
|
|
14
|
|
|
|
15
|
+let noResultHbs = require('product/search/no-result-new.hbs');
|
|
|
16
|
+
|
15
|
let $goodsContainer = $('#goods-container');
|
17
|
let $goodsContainer = $('#goods-container');
|
16
|
-let $fsgc = $goodsContainer.children('.firstscreen-goods');
|
|
|
17
|
-let $defaultgc = $goodsContainer.children('.default-goods');
|
|
|
18
|
-let $ngc = $goodsContainer.children('.new-goods');
|
|
|
19
|
-let $sgc = $goodsContainer.children('.sale-goods');
|
|
|
20
|
-let $pgc = $goodsContainer.children('.price-goods');
|
|
|
21
|
-let $dgc = $goodsContainer.children('.discount-goods');
|
|
|
22
|
-let $container = $defaultgc; // 承载商品列表的容器
|
18
|
+let $container = $goodsContainer.children('.default-goods'); // 承载商品列表的容器
|
23
|
let $listNav = $('#list-nav'); // 筛选项列表
|
19
|
let $listNav = $('#list-nav'); // 筛选项列表
|
24
|
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
|
20
|
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
|
25
|
let $filterBox = $('.filter-box');
|
21
|
let $filterBox = $('.filter-box');
|
|
@@ -99,37 +95,30 @@ function getGoodsList() { |
|
@@ -99,37 +95,30 @@ function getGoodsList() { |
99
|
withCredentials: true
|
95
|
withCredentials: true
|
100
|
},
|
96
|
},
|
101
|
beforeSend: function() {
|
97
|
beforeSend: function() {
|
|
|
98
|
+ if ($('.no-result-new').length > 0) {
|
|
|
99
|
+ $('.no-result-new').remove();
|
|
|
100
|
+ }
|
102
|
$container.append('<div class="search-divide">正在加载...</div>');
|
101
|
$container.append('<div class="search-divide">正在加载...</div>');
|
103
|
},
|
102
|
},
|
104
|
success: function(result) {
|
103
|
success: function(result) {
|
|
|
104
|
+ // 去掉正在加载
|
|
|
105
|
+ $('.search-divide').remove();
|
105
|
|
106
|
|
106
|
- switch (navType) {
|
|
|
107
|
- case 'new':
|
|
|
108
|
- $container = $ngc;
|
|
|
109
|
- break;
|
|
|
110
|
- case 'price':
|
|
|
111
|
- $container = $pgc;
|
|
|
112
|
- break;
|
|
|
113
|
- case 'discount':
|
|
|
114
|
- $container = $dgc;
|
|
|
115
|
- break;
|
|
|
116
|
- case 'default':
|
|
|
117
|
- $container = $defaultgc;
|
|
|
118
|
- break;
|
|
|
119
|
- case 'sale':
|
|
|
120
|
- $container = $sgc;
|
|
|
121
|
- break;
|
|
|
122
|
- default:
|
|
|
123
|
- break;
|
107
|
+ // 没有结果输出没有结果页面
|
|
|
108
|
+ if (!result || result.length < 1) {
|
|
|
109
|
+ $container.html(noResultHbs());
|
|
|
110
|
+ onSearching = false;
|
|
|
111
|
+ return false;
|
124
|
}
|
112
|
}
|
125
|
|
113
|
|
126
|
- $('.search-divide').remove();
|
|
|
127
|
if (isScrollLoad) {
|
114
|
if (isScrollLoad) {
|
128
|
$container.append(result);
|
115
|
$container.append(result);
|
129
|
} else {
|
116
|
} else {
|
130
|
$container.html(result);
|
117
|
$container.html(result);
|
131
|
}
|
118
|
}
|
132
|
- lazyLoad($container.find('.lazy'));
|
119
|
+
|
|
|
120
|
+ lazyLoad($container.find('img[class=lazy]').not('img[src]'));
|
|
|
121
|
+
|
133
|
onSearching = false;
|
122
|
onSearching = false;
|
134
|
},
|
123
|
},
|
135
|
error: function() {
|
124
|
error: function() {
|
|
@@ -150,7 +139,7 @@ function getGoodsList() { |
|
@@ -150,7 +139,7 @@ function getGoodsList() { |
150
|
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
|
139
|
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
|
151
|
*/
|
140
|
*/
|
152
|
function scrollHandler() {
|
141
|
function scrollHandler() {
|
153
|
- if ($filterBox.is(':visible') && $(window).scrollTop() > $goodsContainer.height() * 0.5) {
|
142
|
+ if ($filterBox.is(':visible') && $(window).scrollTop() > $goodsContainer.height() * 0.9) {
|
154
|
isScrollLoad = true;
|
143
|
isScrollLoad = true;
|
155
|
getGoodsList();
|
144
|
getGoodsList();
|
156
|
}
|
145
|
}
|
|
@@ -240,7 +229,7 @@ $listNav.on('touchend touchcancel', function(e) { |
|
@@ -240,7 +229,7 @@ $listNav.on('touchend touchcancel', function(e) { |
240
|
|
229
|
|
241
|
// 默认、最新无排序切换
|
230
|
// 默认、最新无排序切换
|
242
|
if ($this.hasClass('default') || $this.hasClass('new')) {
|
231
|
if ($this.hasClass('default') || $this.hasClass('new')) {
|
243
|
- return;
|
232
|
+ return false;
|
244
|
}
|
233
|
}
|
245
|
|
234
|
|
246
|
if ($this.hasClass('price') || $this.hasClass('discount')) {
|
235
|
if ($this.hasClass('price') || $this.hasClass('discount')) {
|
|
@@ -260,35 +249,6 @@ $listNav.on('touchend touchcancel', function(e) { |
|
@@ -260,35 +249,6 @@ $listNav.on('touchend touchcancel', function(e) { |
260
|
|
249
|
|
261
|
// 若之前active项为筛选,则隐藏筛选面板
|
250
|
// 若之前active项为筛选,则隐藏筛选面板
|
262
|
filter.hideFilter();
|
251
|
filter.hideFilter();
|
263
|
- } else {
|
|
|
264
|
-
|
|
|
265
|
- // 切换container显示
|
|
|
266
|
- $goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
267
|
-
|
|
|
268
|
- switch (navType) {
|
|
|
269
|
- case 'new':
|
|
|
270
|
- $ngc.removeClass('hide');
|
|
|
271
|
- break;
|
|
|
272
|
-
|
|
|
273
|
- case 'price':
|
|
|
274
|
- $pgc.removeClass('hide');
|
|
|
275
|
- break;
|
|
|
276
|
-
|
|
|
277
|
- case 'discount':
|
|
|
278
|
- $dgc.removeClass('hide');
|
|
|
279
|
- break;
|
|
|
280
|
-
|
|
|
281
|
- case 'default':
|
|
|
282
|
- $defaultgc.removeClass('hide');
|
|
|
283
|
- $fsgc.removeClass('hide');
|
|
|
284
|
- break;
|
|
|
285
|
-
|
|
|
286
|
- case 'sale':
|
|
|
287
|
- $sgc.removeClass('hide');
|
|
|
288
|
- break;
|
|
|
289
|
- default:
|
|
|
290
|
- break;
|
|
|
291
|
- }
|
|
|
292
|
}
|
252
|
}
|
293
|
|
253
|
|
294
|
$active.removeClass('active');
|
254
|
$active.removeClass('active');
|
|
@@ -310,5 +270,5 @@ getFilter(); |
|
@@ -310,5 +270,5 @@ getFilter(); |
310
|
|
270
|
|
311
|
// srcoll to load more
|
271
|
// srcoll to load more
|
312
|
$(window).scroll(function() {
|
272
|
$(window).scroll(function() {
|
313
|
- scrollHandler();
|
273
|
+ window.requestAnimationFrame(scrollHandler);
|
314
|
}); |
274
|
}); |