Authored by 周少峰

Merge branch 'feature/shopFavAsync'

... ... @@ -124,9 +124,26 @@ const collectShop = (req, res, next) => {
}
};
const isFavShop = (req, res, next) => {
let uid = req.user.uid;
let shopId = req.body.shopId;
if (!uid || !shopId) {
res.json({
code: 400,
message: '未收藏'
});
}
fav.getFavStatus(uid, shopId, 'shop').then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
changeFavoriteBrand,
collectProduct,
collectShop,
isFavShop,
isFavoriteBrand
};
... ...
... ... @@ -9,6 +9,23 @@
const api = global.yoho.API;
/**
* 是否收藏API
* @function cancelFavAsync
* @param { number } uid 用户uid
* @param { number } id 收藏id
* @param { string } type 类型 product--商品 brand--品牌 shop--店铺
* @return { Object } 收藏状态
*/
const isFavAsync = (uid, id, type) => {
return api.get('', {
method: 'app.favorite.isFavorite',
id: id,
uid: uid,
type: type
});
};
/**
* 收藏API
* @function addFavAsync
* @param { number } uid 用户uid
... ... @@ -43,6 +60,7 @@ const cancelFavAsync = (uid, id, type) => {
};
module.exports = {
isFavAsync, // 是否收藏
addFavAsync, // 收藏
cancelFavAsync // 取消收藏
};
... ...
... ... @@ -56,7 +56,12 @@ const toggleFavShop = (shopId, uid, isadd) => {
}
};
const getFavStatus = (uid, id, type) => {
return favAPI.isFavAsync(uid, id, type);
};
module.exports = {
getFavStatus, // 收藏状态
toggleFavProduct, // 收藏商品
toggleFavBrand, // 收藏品牌
toggleFavShop // 收藏店铺
... ...
... ... @@ -85,6 +85,7 @@ router.get('/index/about', list.brandAbout);
router.get('/shoplist', list.shopList); // 店铺列表页
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
// 品牌页水牌
router.post('/index/getNodeContent', list.getNodeContent);
... ...
... ... @@ -72,3 +72,22 @@ if ($brandFavor && $brandFavor.length) {
}
});
}
// 页面进入更新收藏状态
if ($shopFavor && $shopFavor.length) {
$.ajax({
type: 'POST',
url: '/product/index/isFavoriteShop',
data: {
shopId: shopId
}
}).then(function(data) {
if (data.code === 200 && data.data) {
// 已收藏
$shopFavor.find('i').addClass('coled');
return;
}
$shopFavor.find('i').removeClass('coled');
});
}
... ...
... ... @@ -11,12 +11,16 @@ var product = require('./index/product');
var $shopIntro = $('.shop-intro'),
$shopCollect = $('.shop-collect'),
$colloectIcon = $shopCollect.find('.shop-collect-ico'),
$colloectText = $shopCollect.find('.shop-collect-text'),
$searchForm = $('#shop-search-form'),
$sliderLeft = $('.slider-left'),
$allGoods = $('.all-goods'),
$fixedArea = $allGoods.find('.fixed-area'),
fixedAreaTop = $fixedArea.offset() ? $fixedArea.offset().top : 0;
var shopId = $shopCollect.data('id');
// Pjax
require('yoho-jquery-pjax');
... ... @@ -36,6 +40,26 @@ if ($sliderLeft.length) {
$sliderLeft.slider();
}
if ($shopCollect && $shopCollect.length) {
$.ajax({
type: 'POST',
url: '/product/index/isFavoriteShop',
data: {
shopId: shopId
}
}).then(function(data) {
if (data.code === 200 && data.data) {
// 已收藏
$colloectIcon.addClass('on');
$colloectText.html('已收藏');
return;
}
$colloectIcon.removeClass('on');
$colloectText.html('收藏');
});
}
$shopIntro.on('click', function() {
$('.pop-shop-intro').show();
$('.mask').show();
... ... @@ -53,9 +77,7 @@ $('.shop-query-submit').on('click', function() {
// 收藏店铺
function colloectAction() {
var $colloectIcon = $shopCollect.find('.shop-collect-ico'),
$colloectText = $shopCollect.find('.shop-collect-text'),
isFavorite = $colloectIcon.hasClass('on'),
var isFavorite = $colloectIcon.hasClass('on'),
needColloect = window.cookie('needColloect');
$.ajax({
... ... @@ -64,7 +86,7 @@ function colloectAction() {
data: {
isFavorite: isFavorite ? 0 : 1,
needColloect: needColloect,
shopId: $shopCollect.data('id')
shopId: shopId
},
success: function(res) {
if (res.code === 200) {
... ...