list-common.js
1.72 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
/**
* 星潮教室-列表公共部分
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/7
*/
let $ = require('yoho-jquery'),
tip = require('js/plugin/tip');
require('js/common');
window.setCookie('guangStarUid', window.queryString.uid);
// 星搭配收藏请求
$('.collocation-list,.detail-list').on('click', '.collection', function() {
let $that = $(this),
$icon = $that.find('.collected-ico');
let type, pageType, tag;
if ($icon.hasClass('collected')) {
type = 'del';
} else {
type = 'fav';
}
if ($(this).parents('.collocation-list').length > 0) {
pageType = '1';
tag = '';
} else {
pageType = '2';
tag = $('.detail-list').data('name');
}
$.ajax({
type: 'POST',
url: '/guang/star/setFavorite',
data: {
articleId: $that.parents('li').attr('articleId'),
type: type,
pageType: pageType,
tag: tag
},
success: function(data) {
let code = data.code;
if (code === 200) {
if ($icon.hasClass('collected')) {
$icon.removeClass('collected');
} else {
$icon.addClass('collected');
}
}
if (code === 400) {
if ($('#collocation-link').length <= 0) {
$('body').append('<a href=\'' + data.data + '\' style="display:none;" id="collocation-link">' +
'<span class="collocation-link"></span></a>');
}
$('.collocation-link').click();
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});