Authored by htoooth

fix

... ... @@ -108,6 +108,7 @@ const cancel = (req, res, next) => {
let uid = req.user.uid;
let id = req.query.id;
let type = req.query.type || 'product';
let group = req.query.group || {};
if (!uid || !id) {
return res.json({
... ... @@ -116,7 +117,7 @@ const cancel = (req, res, next) => {
});
}
favoriteService.cancelAsync(uid, id, type).then((result) => {
favoriteService.cancelAsync(uid, id, group, type).then((result) => {
return res.json(result);
}).catch(next);
};
... ...
... ... @@ -351,8 +351,29 @@ const disableNoticeAsync = (uid, id) => {
})();
};
const cancelAsync = (uid, id, type) => {
return favoriteApi.cancel[type](uid, id);
const cancelBrandAsync = co(function * (uid, ids ,group) {
if (group.bid) {
yield favoriteApi.cancel.brand(uid, group.bid);
}
if (group.sid) {
yield favoriteApi.cancel.shop(uid, group.sid);
}
let result = yield favoriteApi.cancel.brand(uid, ids);
return result;
});
/**
* ids 可能是 group
*/
const cancelAsync = (uid, ids, group, type) => {
if (type === 'brand') {
return cancelBrandAsync(uid, ids, group);
}
return favoriteApi.cancel[type](uid, ids);
};
module.exports = {
... ... @@ -364,5 +385,6 @@ module.exports = {
reductionAsync,
enableNoticeAsync,
disableNoticeAsync,
cancelAsync
cancelAsync,
cancelBrandAsync
};
... ...
... ... @@ -395,7 +395,6 @@ $('#me-checkall').click(function() {
// 删除收藏
$('.del-favorite').click(function(e) {
var id = $(this).closest('.fav-row').data('id'),
shopid = $(this).closest('.fav-row').data('shopid'),
brandorshoptype = $(this).closest('.fav-row').data('brandorshoptype');
e.preventDefault();
... ... @@ -405,9 +404,7 @@ $('.del-favorite').click(function(e) {
url: '/home/favorite/cancel',
data: {
id: id,
shopid: shopid,
brandorshoptype: brandorshoptype,
type: favType
type: brandorshoptype || favType
}
}).then(function(data) {
if (data.code === 200) {
... ... @@ -420,6 +417,7 @@ $('.del-favorite').click(function(e) {
$('#me-del-checked').click(function() {
var ids = [],
name = '商品';
var group = {};
if (favType === 'brand') {
name = '品牌';
... ... @@ -429,7 +427,17 @@ $('#me-del-checked').click(function() {
if (confirm('您确定要删除您收藏的' + name + '吗?')) {
$('.checkbox input[type="checkbox"]:checked').each(function() {
ids.push($(this).closest('.fav-row').data('id'));
var $favRow = $(this).closest('.fav-row'),
rdata = $favRow.data();
ids.push(rdata.id);
if (rdata.brandorshoptype) {
if (!group[rdata.brandorshoptype]) {
group[rdata.brandorshoptype] = [];
}
group[rdata.brandorshoptype].push(rdata.id);
}
});
if (ids.length === 0) {
... ... @@ -442,6 +450,10 @@ $('#me-del-checked').click(function() {
url: '/home/favorite/cancel',
data: {
id: ids.join(','),
group: {
bid: group.brand ? group.brand.join(',') : '',
sid: group.shop ? group.shop.join(',') : ''
},
type: favType
}
}).then(function() {
... ...