Authored by 姜枫

fix bug

... ... @@ -227,6 +227,27 @@ const favorite = {
}).catch(next);
},
// 取消商品、店铺收藏
cancelMulti(req, res, next) {
let shops = req.body.shops;
let brands = req.body.brands;
let uid = req.user.uid;
let promises = [];
if (shops) {
promises.push(FavoriteData.cancelFavorite(uid, shops, 'shop'));
}
if (brands) {
promises.push(FavoriteData.cancelFavorite(uid, brands, 'brand'));
}
Promise.all(promises).then(() => {
res.json({code: 200});
}).catch(next);
},
// 取消资讯收藏
editorialCancel(req, res, next) {
let ids = req.body.ids;
... ...
... ... @@ -92,6 +92,7 @@ router.get('/collection', auth, favorite.goods);
router.get('/collection/brand', auth, favorite.brand);
router.get('/collection/editorial', auth, favorite.editorial);
router.post('/collection/cancel', auth, favorite.cancel);
router.post('/collection/cancel/multi', auth, favorite.cancelMulti);
router.post('/collection/editorial/cancel', auth, favorite.editorialCancel);
module.exports = router;
... ...
... ... @@ -9,7 +9,7 @@
<div class="check">
{{> icon/checkbox}}
</div>
<div class="brand-info" data-id="{{brandId}}">
<div class="brand-info" data-id="{{brandId}}" data-type="{{brandOrShopType}}">
<div class="brand-icon">
<img src="{{image brandIco 145 126}}" alt="" width="145" height="126">
</div>
... ...
... ... @@ -46,18 +46,24 @@ var FavoriteBrand = {
$('.btn.cancel', $root).click(function() {
var id = $(this).parents('.brand-info').data('id');
var type = $(this).parents('.brand-info').data('type');
FavoriteBrand.doCancel(id);
FavoriteBrand.doCancel(id, type);
});
$('.favorite-cancel', $root).click(function() {
var ids = [];
var shopId = [];
var brandId = [];
$('.brand-info.choose', $root).each(function() {
ids.push($(this).data('id'));
if ($(this).data('type') === 'shop') {
shopId.push($(this).data('id'));
} else if ($(this).data('type') === 'brand') {
brandId.push($(this).data('id'));
}
});
FavoriteBrand.doCancel(ids.join(','));
FavoriteBrand.doCancelMulti(shopId.join(','), brandId.join(','));
});
},
moveSlide: function(ele) {
... ... @@ -72,15 +78,25 @@ var FavoriteBrand = {
$(currLi).removeClass('show');
}
},
doCancel: function(ids) {
doCancel: function(ids, type) {
$.post('/me/collection/cancel', {
type: 'brand',
type: type || 'brand',
ids: ids
}, function(data) {
if (data.code === 200) {
location.href = '/me/collection/brand';
}
});
},
doCancelMulti: function(shops, brands) {
$.post('/me/collection/cancel/multi', {
shops: shops,
brands: brands
}, function(data) {
if (data.code === 200) {
location.href = '/me/collection/brand';
}
});
}
};
... ...