Authored by htoooth

add brand fav

... ... @@ -17,10 +17,10 @@ const changeFavoriteBrand = (req, res, next) => {
if (uid && brandId) {
brandService.changeAsync(uid, brandId).then(result => {
res.json(result);
return res.json(result);
}).catch(next);
} else if (!uid) {
res.json({
return res.json({
code: 403,
message: '用户ID不存在',
data: {
... ... @@ -28,13 +28,29 @@ const changeFavoriteBrand = (req, res, next) => {
}
});
} else {
res.json({
return res.json({
code: 400,
message: '操作失败'
});
}
};
const isFavoriteBrand = (req, res, next) => {
let uid = req.user.uid || '';
let brandId = req.query.brandId;
if (uid && brandId) {
brandService.isFavoriteAsync(uid, brandId).then(result => {
return res.json(result);
}).catch(next);
} else {
return res.json({
code: 400,
message: '状态失败'
});
}
};
const collectProduct = (req, res, next) => {
let uid = req.user.uid || '';
let pid = req.body.productId;
... ... @@ -43,8 +59,7 @@ const collectProduct = (req, res, next) => {
if (uid && pid) {
switch (type) {
case 'add':
{
productService.createAsync(uid, pid)
productService.createAsync(uid, pid)
.then(result => {
if (result.code === 413) {
result.message = '该商品已经收藏';
... ... @@ -53,22 +68,17 @@ const collectProduct = (req, res, next) => {
res.json(result);
})
.catch(next);
break;
}
break;
case 'cancel':
{
productService.deleteAsync(uid, pid)
productService.deleteAsync(uid, pid)
.then(result => res.json(result))
.catch(next);
break;
}
break;
default:
{
res.json({
code: 400,
message: '错误类型'
});
}
res.json({
code: 400,
message: '错误类型'
});
}
} else if (!uid) {
res.json({
... ... @@ -117,5 +127,6 @@ const collectShop = (req, res, next) => {
module.exports = {
changeFavoriteBrand,
collectProduct,
collectShop
collectShop,
isFavoriteBrand
};
... ...
... ... @@ -67,7 +67,7 @@ const _getProductIntroAsync = (productId, productSkn) => {
* pid : product id
* bid : brand id
*/
const _getProductFavoriteDataAsync = (uid, pid, bid) => {
const _getProductFavoriteDataAsync = (uid, pid) => {
return co(function*() {
let result = {
product: false,
... ... @@ -84,23 +84,14 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => {
requestApi.product = favoriteProductService.isFavoriteAsync(uid, pid);
}
if (bid) {
requestApi.brand = favoriteBrandService.isFavoriteAsync(uid, bid);
}
let requestData = yield Promise.props(requestApi);
let productData = requestData.product;
let brandData = requestData.brand;
if (productData) {
result.product = productData.code === 200 && productData.data ? true : false;
}
if (brandData) {
result.brand = brandData.code && brandData.code === 200 ? true : false;
}
return result;
})();
};
... ... @@ -1076,7 +1067,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
let requestApi = {
addition: _getProductAdditionInfoAsync(origin), // 预处理所有的数据
fav: _getProductFavoriteDataAsync(uid, result.productId, brandId), // 处理收藏喜欢数据
fav: _getProductFavoriteDataAsync(uid, result.productI), // 处理收藏喜欢数据
promotion: productAPI.getPromotionAsync(result.skn) // 打折信息
};
... ...
... ... @@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品
router.post('/item/togglecollect', favorite.collectProduct); // 收藏商品
router.get('/detail/header', detail.productHeader); // 价格数据重新获取接口
router.get('/detail/return', detail.detailReturn);// 特殊商品退换货
router.get('/index/isfav', favorite.isFavoriteBrand);// 品牌收藏状态
// 搜索
router.get('/search/index', search.index);
... ...
... ... @@ -809,6 +809,20 @@ window.fetchReturn = fetchReturn;
$('.main').html(result);
bindEvent.fire();
});
$.ajax({
type: 'GET',
url: '/product/index/isfav',
dataType: 'html',
data: {
brandId: $('#brand-favour').data('id')
}
}).then(function(result) {
if (result.code === 200) {
$('#brand-favour').toggleClass('coled');
}
});
}());
// 数据懒加载
... ...