Authored by zhangxiaoru

favorite

... ... @@ -35,10 +35,15 @@ let favProduct = (req, res, next) => {
let limit = 10;
favoriteModel.favProduct(uid, page, limit).then((result) => {
if (typeof(result.total) === "undefined") {
res.render('favorite/favorite-product', {
layout: false,
hasFavProduct: result
hasFavProduct: result.hasFavProduct
});
} else {
res.json(result);
}
}).catch(next);
};
... ... @@ -48,10 +53,16 @@ let favfavBrand = (req, res, next) => {
let limit = 10;
favoriteModel.favfavBrand(uid, page, limit).then((result) => {
if (typeof(result.total) === "undefined") {
res.render('favorite/favorite-brand', {
layout: false,
hasFavBrand: result
hasFavBrand: result.hasFavBrand
});
} else {
res.json(result);
}
}).catch(next);
};
... ...
... ... @@ -23,7 +23,7 @@ const favProduct = (uid, page, limit) => {
page: page,
limit: limit
}).then((result) => {
// console.log(result)
let resu = {
hasFavProduct: []
};
... ... @@ -34,7 +34,10 @@ const favProduct = (uid, page, limit) => {
if (page > 1 && list === []) {
resu.end = true;
return;
}
if (list.data.total === 0) {
resu.total = 0;
}
if (page <= list.data.pageTotal) {
... ... @@ -101,12 +104,10 @@ const favProduct = (uid, page, limit) => {
});
} else {
resu.push({
end: true
});
resu.end = true;
}
return resu.hasFavProduct;
return resu;
} else {
logger.error('收藏商品 cood 不是 200');
}
... ... @@ -121,16 +122,20 @@ const favfavBrand = (uid, page, limit) => {
page: page,
limit: limit
}).then((result) => {
let hasFavBrand = [];
console.log(result)
let resu = {
hasFavBrand: []
}
if (result && result.code === 200) {
let list = camelCase(result);
if (page > 1 && list === []) {
hasFavBrand.push({
end: true
});
return;
resu.end = true;
}
if (list.data.total === 0) {
resu.total = 0;
}
if (page <= list.data.pageTotal) {
... ... @@ -179,17 +184,15 @@ const favfavBrand = (uid, page, limit) => {
}
});
hasFavBrand.push(obj);
resu.hasFavBrand.push(obj);
});
// console.log(hasFavBrand);
return hasFavBrand;
} else {
hasFavBrand.push({
end: true
});
resu.end = true;
}
console.log(resu);
return resu;
} else {
logger.error('收藏品牌 cood 不是 200');
}
... ...
... ... @@ -23,10 +23,10 @@ var $navLi = $('#fav-tab > li'),
$favProductList = $('.fav-product-list'),
$favBrandList = $('.fav-brand-swiper-wrapper'),
pageId = 1,
brandPageId = 1, // 收藏品牌的当前页数
brandPageId = 1, //收藏品牌的当前页数
lockId = true,
brandLockId = true, // 收藏品牌是否可下拉加载更多
brandTab = false; // 当前是否停留在收藏品牌页
brandLockId = true, //收藏品牌是否可下拉加载更多
brandTab = false; //当前是否停留在收藏品牌页
require('../common');
... ... @@ -38,7 +38,7 @@ function showFavTab(index) {
$favContainer.eq(index).addClass('show');
}
// 初始化swiper
//初始化swiper
function initSwiper(data) {
var i,
idStrReg = /container-(\d+)['"]{1}/gi,
... ... @@ -47,10 +47,10 @@ function initSwiper(data) {
idArrLen = idArr.length,
containerId;
// $swiperList = $('.swiper-container');
//$swiperList = $('.swiper-container');
for (i = 0; i < idArrLen; i++) {
/* id = $swiperList.eq(i).attr('data-id');
/*id = $swiperList.eq(i).attr('data-id');
if (!!swiperObj[id]) {
swiperObj[id].destroy(true, true);
... ... @@ -91,17 +91,18 @@ function loadData($parent, url, page) {
$loadMore.addClass('hide');
}
if (data === ' ') {
if (data.total === 0) {
$loadingMask.addClass('hide');
$parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
window.rePosFooter();
} else if (data === 'end') {
} else if (data.end === true) {
// 处理data等于end时如果loadingMask存在且没有hide样式的情况
//处理data等于end时如果loadingMask存在且没有hide样式的情况
if ($loadingMask && !$loadingMask.hasClass('hide')) {
$loadingMask.addClass('hide');
// $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
//$parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
}
$parent.closest('.fav-type').find('.fav-load-background')
... ... @@ -113,14 +114,14 @@ function loadData($parent, url, page) {
} else if (data.length > 10) {
$parent.append(data);
// 如果有数据loadingMask会被remove掉
//如果有数据loadingMask会被remove掉
$loadingMask.remove();
if (url === 'favBrand') {
initSwiper(data);// 如果是收藏品牌需要初始化swiper
initSwiper(data);//如果是收藏品牌需要初始化swiper
brandLockId = false;// 请求成功后解锁品牌收藏page++
brandLockId = false;//请求成功后解锁品牌收藏page++
} else {
lockId = false;// 请求成功后解锁商品收藏page++
lockId = false;//请求成功后解锁商品收藏page++
}
}
window.rePosFooter();
... ... @@ -170,7 +171,7 @@ favTabHammer.on('tap', function(e) {
});
// 删除收藏的商品
//删除收藏的商品
favContentHammer = new Hammer(document.getElementById('fav-content'));
favContentHammer.on('tap', function(e) {
... ... @@ -218,7 +219,7 @@ favContentHammer.on('tap', function(e) {
}
}).fail(function() {
// TODO
//TODO
diaLog.showDialog({
autoHide: true,
... ... @@ -230,7 +231,7 @@ favContentHammer.on('tap', function(e) {
function scrollHandler() {
// 距离底部未1/4列表高度+底部高度的时候加载更多
//距离底部未1/4列表高度+底部高度的时候加载更多
if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $favBrandList.height() - footerH) {
if (brandTab) {
$brandLoadMore.filter('.hide').removeClass('hide');
... ... @@ -252,7 +253,7 @@ function scrollHandler() {
}
}
// srcoll to load more
//srcoll to load more
$(window).scroll(scrollHandler);
$(document).on('touchend', '.swiper-header', function() {
... ...