favorite.js
1.07 KB
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
38
39
40
41
/**
* 品牌或店铺收藏
* @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 $banner = $(this).parents('.brand-banner');
var shopId = $banner.data('shop');
var brandId = $banner.data('brand');
var type = $banner.data('type');
var isAdd = $(this).hasClass('coled');
if (type === 'shop') {
_favShop(shopId, isAdd);
} else if (type === 'brand') {
_favBrand(brandId, isAdd);
} else {
_favBrand(brandId, isAdd);
}
});