...
|
...
|
@@ -12,26 +12,43 @@ var diaLog = require('./dialog'); |
|
|
|
|
|
var $navLi = $('#fav-tab > li'),
|
|
|
$favContainer = $('.fav-content > .fav-type'),
|
|
|
$swiperList = $('.swiper-container'),
|
|
|
$swiperList = '',
|
|
|
swiperObj = {},
|
|
|
favTabHammer,
|
|
|
favContentHammer;
|
|
|
favContentHammer,
|
|
|
footerH = $('#yoho-footer').height(),
|
|
|
$loadMore = $('.fav-load-more'),
|
|
|
$brandLoadMore = $('.fav-brand-load-more'),
|
|
|
winH = $(window).height(),
|
|
|
$favProductList = $('.fav-product-list'),
|
|
|
$favBrandList = $('.fav-brand-swiper'),
|
|
|
pageId = 1,
|
|
|
brandPageId = 1, //收藏品牌的当前页数
|
|
|
lockId = true,
|
|
|
brandLockId = true, //收藏品牌是否可下拉加载更多
|
|
|
brandTab = false; //当前是否停留在收藏品牌页
|
|
|
|
|
|
function showFavTab(index) {
|
|
|
var i,
|
|
|
id;
|
|
|
|
|
|
$navLi.filter('.active').removeClass('active');
|
|
|
$navLi.eq(index).addClass('active');
|
|
|
|
|
|
$favContainer.filter('.show').removeClass('show');
|
|
|
$favContainer.eq(index).addClass('show');
|
|
|
}
|
|
|
|
|
|
if (index === 1) {
|
|
|
//初始化swiper
|
|
|
function initSwiper() {
|
|
|
var i,
|
|
|
id;
|
|
|
|
|
|
//导航
|
|
|
$swiperList = $('.swiper-container');
|
|
|
for (i = 0; i < $swiperList.length; i++) {
|
|
|
id = $swiperList.eq(i).attr('data-id');
|
|
|
console.log(id);
|
|
|
|
|
|
if (!!swiperObj[id]) {
|
|
|
swiperObj[id].destroy(true, true);
|
|
|
}
|
|
|
swiperObj[id] = new Swiper('#swiper-container-' + id, {
|
|
|
slidesPerView: 'auto',
|
|
|
grabCursor: true,
|
...
|
...
|
@@ -41,15 +58,71 @@ function showFavTab(index) { |
|
|
watchSlidesVisibility: true
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 上拉加载更多
|
|
|
function loadData($parent, url, page) {
|
|
|
if (url === 'favBrand') {
|
|
|
brandLockId = true;
|
|
|
} else {
|
|
|
lockId = true;
|
|
|
}
|
|
|
$.ajax({
|
|
|
method: 'post',
|
|
|
url: '/home/' + url,
|
|
|
data: {
|
|
|
page: page
|
|
|
},
|
|
|
success: function(data) {
|
|
|
|
|
|
//setTimeout(function() { //模拟延时
|
|
|
|
|
|
if (url === 'favBrand') {
|
|
|
$brandLoadMore.addClass('hide');
|
|
|
} else {
|
|
|
$loadMore.addClass('hide');
|
|
|
}
|
|
|
|
|
|
if (data === ' ') {
|
|
|
$parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
|
|
|
} else if (data === 'end') {
|
|
|
$parent.closest('.fav-type').find('.fav-load-background')
|
|
|
.removeClass('fav-load-background').html('没有更多了');
|
|
|
|
|
|
} else if (data.length > 10) {
|
|
|
$parent.append(data);
|
|
|
|
|
|
if (url === 'favBrand') {
|
|
|
initSwiper();//如果是收藏品牌需要初始化swiper
|
|
|
|
|
|
brandLockId = false;//请求成功后解锁品牌收藏page++
|
|
|
} else {
|
|
|
lockId = false;//请求成功后解锁商品收藏page++
|
|
|
}
|
|
|
|
|
|
window.rePosFooter();
|
|
|
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
window.rePosFooter();
|
|
|
|
|
|
//},1000);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 如果从品牌收藏入口进入
|
|
|
if ($('#fav-tab').hasClass('brand-tab')) {
|
|
|
showFavTab(1);
|
|
|
loadData($favBrandList, 'favBrand', 1);
|
|
|
brandTab = true;
|
|
|
window.rePosFooter();
|
|
|
} else {
|
|
|
showFavTab(0);
|
|
|
loadData($favProductList, 'favProduct', 1);
|
|
|
brandTab = false;
|
|
|
window.rePosFooter();
|
|
|
}
|
|
|
|
|
|
favTabHammer = new Hammer(document.getElementById('fav-tab'));
|
...
|
...
|
@@ -62,7 +135,20 @@ favTabHammer.on('tap', function(e) { |
|
|
}
|
|
|
|
|
|
index = $cur.index();
|
|
|
|
|
|
if (index === 0) {
|
|
|
if ($favProductList.find('li').length === 0 &&
|
|
|
$favProductList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) {
|
|
|
loadData($favProductList, 'favProduct', 1);
|
|
|
}
|
|
|
} else {
|
|
|
if ($favBrandList.find('div').length === 0 &&
|
|
|
$favBrandList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) {
|
|
|
loadData($favBrandList, 'favBrand', 1);
|
|
|
}
|
|
|
}
|
|
|
showFavTab(index);
|
|
|
window.rePosFooter();
|
|
|
|
|
|
});
|
|
|
|
...
|
...
|
@@ -118,3 +204,30 @@ favContentHammer.on('tap', function(e) { |
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 上拉加载更多
|
|
|
$(document).scroll(function() {
|
|
|
|
|
|
if ($(window).scrollTop() + winH >= $(document).height() - footerH) {
|
|
|
|
|
|
if (brandTab) {
|
|
|
|
|
|
$brandLoadMore.filter('.hide').removeClass('hide');
|
|
|
|
|
|
if (!brandLockId) {
|
|
|
|
|
|
brandPageId++;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$loadMore.filter('.hide').removeClass('hide');
|
|
|
|
|
|
if (!lockId) {
|
|
|
console.log(222);
|
|
|
pageId++;
|
|
|
loadData($favProductList, 'favProduct', pageId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}); |
|
|
\ No newline at end of file |
...
|
...
|
|