brand.js
2.32 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* 品牌页面
* @auhtor: bikai<kai.bi@yoho.cn>
* @date: 2016/1/21
*/
var $ = require('yoho-jquery');
var $brandFavor = $('#brand-favor'),
$shopFavor = $('#shop-favor'),
shopId = $shopFavor.data('id'),
id = $brandFavor.data('id');
var BRAND_FAV = {
add: 'add',
cancel: 'cancel'
};
/**
* 品牌收藏
*/
$brandFavor.on('click', function() {
$.ajax({
type: 'post',
url: '/product/index/favoriteBrand',
data: {
brandId: id,
type: $brandFavor.find('i').hasClass('coled') ? BRAND_FAV.cancel : BRAND_FAV.add
}
}).then(function(res) {
if (res.code === 200) {
$brandFavor.find('i').toggleClass('coled');
} else if (res.code === 403) {
location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
}
});
});
/**
* 店铺收藏
*/
$shopFavor.on('click', function() {
var $dom = $shopFavor.find('i');
$.ajax({
type: 'post',
url: '/product/shop/togglecollect',
data: {
isFavorite: $dom.hasClass('coled') ? 0 : 1,
shopId: shopId
}
}).then(function(res) {
if (res.code === 200) {
$dom.toggleClass('coled');
} else if (res.code === 401) {
location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
}
});
});
// 页面进入更新收藏状态
if ($brandFavor && $brandFavor.length) {
$.ajax({
type: 'POST',
url: '/product/index/isFavoriteBrand',
data: {
brandId: id
}
}).then(function(data) {
if (data.code === 200) {
// 已收藏
$brandFavor.find('i').addClass('coled');
} else if (data.code === 404) {
// 未收藏
$brandFavor.find('i').removeClass('coled');
}
});
}
// 页面进入更新收藏状态
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');
});
}