...
|
...
|
@@ -12,14 +12,10 @@ require('./shop/coupon'); |
|
|
|
|
|
let Tab = require('plugin/tab');
|
|
|
|
|
|
let noResultHbs = require('product/search/no-result-new.hbs');
|
|
|
|
|
|
let $goodsContainer = $('#goods-container');
|
|
|
let $fsgc = $goodsContainer.children('.firstscreen-goods');
|
|
|
let $defaultgc = $goodsContainer.children('.default-goods');
|
|
|
let $ngc = $goodsContainer.children('.new-goods');
|
|
|
let $sgc = $goodsContainer.children('.sale-goods');
|
|
|
let $pgc = $goodsContainer.children('.price-goods');
|
|
|
let $dgc = $goodsContainer.children('.discount-goods');
|
|
|
let $container = $defaultgc; // 承载商品列表的容器
|
|
|
let $container = $goodsContainer.children('.default-goods'); // 承载商品列表的容器
|
|
|
let $listNav = $('#list-nav'); // 筛选项列表
|
|
|
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
|
|
|
let $filterBox = $('.filter-box');
|
...
|
...
|
@@ -99,37 +95,30 @@ function getGoodsList() { |
|
|
withCredentials: true
|
|
|
},
|
|
|
beforeSend: function() {
|
|
|
if ($('.no-result-new').length > 0) {
|
|
|
$('.no-result-new').remove();
|
|
|
}
|
|
|
$container.append('<div class="search-divide">正在加载...</div>');
|
|
|
},
|
|
|
success: function(result) {
|
|
|
// 去掉正在加载
|
|
|
$('.search-divide').remove();
|
|
|
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
$container = $ngc;
|
|
|
break;
|
|
|
case 'price':
|
|
|
$container = $pgc;
|
|
|
break;
|
|
|
case 'discount':
|
|
|
$container = $dgc;
|
|
|
break;
|
|
|
case 'default':
|
|
|
$container = $defaultgc;
|
|
|
break;
|
|
|
case 'sale':
|
|
|
$container = $sgc;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
// 没有结果输出没有结果页面
|
|
|
if (!result || result.length < 1) {
|
|
|
$container.html(noResultHbs());
|
|
|
onSearching = false;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$('.search-divide').remove();
|
|
|
if (isScrollLoad) {
|
|
|
$container.append(result);
|
|
|
} else {
|
|
|
$container.html(result);
|
|
|
}
|
|
|
lazyLoad($container.find('.lazy'));
|
|
|
|
|
|
lazyLoad($container.find('img[class=lazy]').not('img[src]'));
|
|
|
|
|
|
onSearching = false;
|
|
|
},
|
|
|
error: function() {
|
...
|
...
|
@@ -150,7 +139,7 @@ function getGoodsList() { |
|
|
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
|
|
|
*/
|
|
|
function scrollHandler() {
|
|
|
if ($filterBox.is(':visible') && $(window).scrollTop() > $goodsContainer.height() * 0.5) {
|
|
|
if ($filterBox.is(':visible') && $(window).scrollTop() > $goodsContainer.height() * 0.9) {
|
|
|
isScrollLoad = true;
|
|
|
getGoodsList();
|
|
|
}
|
...
|
...
|
@@ -240,7 +229,7 @@ $listNav.on('touchend touchcancel', function(e) { |
|
|
|
|
|
// 默认、最新无排序切换
|
|
|
if ($this.hasClass('default') || $this.hasClass('new')) {
|
|
|
return;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('price') || $this.hasClass('discount')) {
|
...
|
...
|
@@ -260,35 +249,6 @@ $listNav.on('touchend touchcancel', function(e) { |
|
|
|
|
|
// 若之前active项为筛选,则隐藏筛选面板
|
|
|
filter.hideFilter();
|
|
|
} else {
|
|
|
|
|
|
// 切换container显示
|
|
|
$goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
$ngc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'price':
|
|
|
$pgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'discount':
|
|
|
$dgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'default':
|
|
|
$defaultgc.removeClass('hide');
|
|
|
$fsgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'sale':
|
|
|
$sgc.removeClass('hide');
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$active.removeClass('active');
|
...
|
...
|
@@ -310,5 +270,5 @@ getFilter(); |
|
|
|
|
|
// srcoll to load more
|
|
|
$(window).scroll(function() {
|
|
|
scrollHandler();
|
|
|
window.requestAnimationFrame(scrollHandler);
|
|
|
}); |
...
|
...
|
|