favorite.page.js
1.16 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
/**
*
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/7/19
*/
var lazyload = require('yoho-jquery-lazyload');
var $root = $('.favorite-products');
require('./me');
require('../plugins/check');
function doCancel(ids) {
$.post('/me/collection/cancel', {
type: 'product',
ids: ids
}, function(data) {
if (data.code === 200) {
location.href = '/me/collection';
}
});
}
function eventBind() {
$('.check-all', $root).check({
type: 'checkbox',
onChange: function(ele, checked) {
if (checked) {
$('.goods-info', $root).addClass('choose');
} else {
$('.goods-info', $root).removeClass('choose');
}
}
});
$('.btn.cancel', $root).click(function() {
var id = $(this).parents('.goods-info').data('id');
doCancel(id);
});
$('.favorite-cancel', $root).click(function() {
var ids = [];
$('.goods-info.choose', $root).each(function() {
ids.push($(this).data('id'));
});
doCancel(ids.join(','));
});
}
$(function() {
lazyload();
});
eventBind();