favorite.brand.page.js
2.36 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
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/20
*/
var FavoriteBrand = {
init: function() {
var $root = $('.favorite-brands');
require('./me');
require('../plugins/check');
$('.brand-products ul').each(function() {
var lis = $('li', this);
$(lis[0]).addClass('show');
});
$('.slide-switch a').click(function() {
FavoriteBrand.moveSlide(this);
});
$('.check', $root).check({
type: 'checkbox',
onChange: function(ele, checked) {
if (checked) {
$(ele).next('.brand-info').addClass('choose');
} else {
$(ele).next('.brand-info').removeClass('choose');
}
}
});
$('.check-all', $root).check({
type: 'checkbox',
onChange: function(ele, checked) {
if (checked) {
$('.check', $root).check('checkAll');
} else {
$('.check', $root).check('unCheckAll');
}
}
});
$('.btn.cancel', $root).click(function() {
var id = $(this).parents('.brand-info').data('id');
FavoriteBrand.doCancel(id);
});
$('.favorite-cancel', $root).click(function() {
var ids = [];
$('.brand-info.choose', $root).each(function() {
ids.push($(this).data('id'));
});
FavoriteBrand.doCancel(ids.join(','));
});
},
moveSlide: function(ele) {
var wrap = $(ele).parent().next('.slide-wrap');
var currLi = $('ul li.show', wrap);
if ($(ele).hasClass('next') && $(currLi).next('li').length > 0) {
$(currLi).next('li').addClass('show');
$(currLi).removeClass('show');
} else if ($(ele).hasClass('prev') && $(currLi).prev('li').length > 0) {
$(currLi).prev('li').addClass('show');
$(currLi).removeClass('show');
}
},
doCancel: function(ids) {
$.post('/me/collection/cancel', {
type: 'brand',
ids: ids
}, function(data) {
if (data.code === 200) {
location.href = '/me/collection/brand';
}
});
}
};
$(function() {
FavoriteBrand.init();
});