bundle.js
2.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* @Author: Targaryen
* @Date: 2017-04-06 16:51:52
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-07 13:34:40
*/
const $ = require('yoho-jquery');
let tip = require('plugin/tip');
let bundle = {
init(handle) {
let self = this;
let $bundle = $('.bundle'); // 限定作用域
let activityId = $bundle.data('activityid');
self.handle = handle;
/**
* 减少套餐数量
*/
$bundle.on('click', '.bundle-nums .num-opt .btn-opt-minus', function(e) {
self.decrBundle({
activity_id: activityId
}, e);
});
/**
* 增加套餐数量
*/
$bundle.on('click', '.bundle-nums .num-opt .btn-opt-plus', function(e) {
self.incrBundle({
activity_id: activityId
}, e);
});
$bundle.on('click', '.bundle-title .opt .select', function(e) {
self.bundleCheckHandle(e);
});
},
/**
* 增加套餐数量
* @param {*} params
*/
incrBundle(params, e) {
let self = this;
$.post('/cart/index/new/incrbundle', params, function(result) {
let bundleNum = $(e.delegateTarget).find('.good-num');
let defaultValue = parseInt(bundleNum.val(), 10);
if (result.code === 200) {
bundleNum.val(defaultValue + 1);
self.handle.refreshPage();
} else {
tip.show(result.message);
}
});
},
/**
* 减少套餐数量
* @param {*} params
*/
decrBundle(params, e) {
let self = this;
$.post('/cart/index/new/decrbundle', params, function(result) {
let bundleNum = $(e.delegateTarget).find('.good-num');
let defaultValue = parseInt(bundleNum.val(), 10);
if (result.code === 200) {
bundleNum.val(defaultValue - 1);
self.handle.refreshPage();
} else {
tip.show(result.message);
}
});
},
/**
* 套餐选中
* @param {*} e
*/
bundleCheckHandle(e) {
$(e.delegateTarget).find('.select').toggleClass('checked');
let goodItem = $(e.delegateTarget).find('.good-item');
let skuData = [];
goodItem.each(function(index, element) {
skuData.push({
product_sku: $(element).data('id'),
buy_number: $(element).data('mnum'),
activity_id: $(e.delegateTarget).data('activityid'),
selected: 'Y'
});
});
$.ajax({
type: 'post',
url: '/cart/index/new/select',
data: {
skuList: JSON.stringify(skuData)
},
success: function(result) {
console.log(result);
}
});
}
};
module.exports = bundle;