favorite.js
990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* 品牌或店铺收藏
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/19
*/
function _favBack(data) {
if (data && data.code === 200) {
$('#brand-fav').toggleClass('coled');
} else if (data && data.data && data.data.refer) {
location.href = data.data.refer;
}
}
function _favShop(shopId, isAdd) {
$.post('/product/shop/togglecollect', {shopId: shopId, type: isAdd ? '' : 'add'}, function(data) {
_favBack(data);
});
}
function _favBrand(brandId, isAdd) {
$.post('/product/brand/togglecollect', {brandId: brandId, type: isAdd ? '' : 'add'}, function(data) {
_favBack(data);
});
}
$('#brand-fav').click(function() {
var shopId = $(this).parents('.brand-banner').data('shop');
var brandId = $(this).parents('.brand-banner').data('brand');
var isAdd = $(this).hasClass('coled');
if (shopId) {
_favShop(shopId, isAdd);
} else if (brandId) {
_favBrand(brandId, isAdd);
}
});