Authored by 郭成尧

add-a-bug

... ... @@ -19,6 +19,7 @@ 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 $listNav = $('#list-nav'); // 筛选项列表
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
let $filterBox = $('.filter-box');
... ... @@ -56,8 +57,12 @@ let navInfo = {
end: false
}
};
let navType = 'default'; // 目前激活的导航页面
let defaultOpt = navInfo.default; // 默认参数
let onSearching = false; // 是否正在搜索
let isScrollLoad = false; // 是否是滚动加载
let page = 0; // 页码
/**
* 处理筛选参数
... ... @@ -76,40 +81,74 @@ function handleChoseFilter() {
*/
function getGoodsList() {
handleChoseFilter();
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/search',
data: defaultOpt,
xhrFields: {
withCredentials: true
},
success: function(result) {
let $container = $defaultgc;
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 (!onSearching) {
onSearching = true;
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/search',
data: defaultOpt,
xhrFields: {
withCredentials: true
},
beforeSend: function() {
$container.append('<div class="search-divide">正在加载...</div>');
},
success: function(result) {
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;
}
$('.search-divide').remove();
if (isScrollLoad) {
$container.append(result);
} else {
$container.html(result);
}
lazyLoad($container.find('.lazy'));
onSearching = false;
},
error: function() {
let $divide = $('.search-divide');
$divide.text('加载失败,点击重试');
$divide.one('click', function() {
$divide.text('正在加载...');
getGoodsList();
});
onSearching = false;
}
});
}
}
$container.html(result);
lazyLoad($container.find('.lazy'));
}
});
/**
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
*/
function scrollHandler() {
if ($filterBox.is(':visible') && $(window).scrollTop() > $goodsContainer.height() * 0.5) {
isScrollLoad = true;
Object.assign(defaultOpt, {page: page++});
getGoodsList();
}
}
/**
... ... @@ -139,7 +178,7 @@ function getFilter() {
});
}
Tab.prototype.getgoodslist = getGoodsList; // 获取商品列表
Tab.prototype.getgoodslist = getGoodsList; // 获取商品列表,点击全部商品 Tab 时获取
Tab.prototype.filterhide = function() { // 隐藏筛选 TAB
$filterBox.css('display', 'none');
};
... ... @@ -152,10 +191,11 @@ $listNav.bind('contextmenu', function() {
});
$listNav.on('touchend touchcancel', function(e) {
isScrollLoad = false;
let $this = $(e.target).closest('li'); // 被点击的 Tab
let $active;
let nav;
let bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || '';
if ($this.hasClass('filter')) {
... ... @@ -254,9 +294,15 @@ $listNav.on('touchend touchcancel', function(e) {
}
if (nav.reload) {
$(document).trigger('shouldSendBpData', [bpIdData]);
getGoodsList({filtering: true});
getGoodsList();
}
}
});
// 页面打开直接加载筛选项
getFilter();
// srcoll to load more
$(window).scroll(function() {
scrollHandler();
});
... ...