good.js
5 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* 购物车商品
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/20
*/
var $ = require('jquery'),
ellipsis = require('mlellipsis'),
chosePanel = require('../shopping-cart/chose-panel'),
lazyLoad = require('yoho.lazyload');
var dialog = require('../me/dialog'),
tip = require('../plugin/tip');
var $names;
//var $curDelPanel;
////删除面板显示后任何点击行为都将触发隐藏面板
//function docTouchEvt() {
// $curDelPanel && $curDelPanel.addClass('hide');
//
// //
// $(document).off('touchstart', docTouchEvt);
//}
ellipsis.init();
lazyLoad({
try_again_css: 'order-failure'
});
$names = $('.name');
if ($names.length > 0) {
$names[0].mlellipsis(2);
}
//TIP:事件委托在.cart-goods,商品列表的容器统一需要有.cart-goods
$('.cart-goods').on('touchstart', '.checkbox', function() {
var $this = $(this),
id = $(this).closest('.shopping-cart-good').data('id');
$.ajax({
type: 'GET',
url: '/shoppingCart/select',
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
if ($this.hasClass('icon-cb-checked')) {
$this.removeClass('icon-cb-checked').addClass('icon-checkbox');
} else {
$this.removeClass('icon-checkbox').addClass('icon-cb-checked');
}
}
$.ajax({
type: 'GET',
url: '/shoppingCart/getCartData',
data: {
id: id
},
success: function(data) {
if (data) {
$('#good-totalprice').html('¥' + data.commonCart.price);
$('#good-activityPrice').html('¥' + data.commonCart.activityPrice);
$('#good-total').html(data.commonCart.count + '件总计:¥' + data.commonCart.sumPrice);
}
},
error: function() {
tip.show('网络错误');
}
});
}).fail(function() {
tip.show('网络错误');
});
}).on('touchstart', '.icon-edit', function() {
var $this = $(this),
$cartgood = $this.closest('.shopping-cart-good'),
$viewGood = $cartgood.find('.deps'),
$editGoot = $cartgood.find('.calculate-num');
if ($viewGood.hasClass('show')) {
$viewGood.removeClass('show').addClass('hide');
$editGoot.removeClass('hide').addClass('show');
} else {
$viewGood.removeClass('hide').addClass('show');
$editGoot.removeClass('show').addClass('hide');
}
}).on('touchstart', '.icon-del', function(e) {
var $this = $(this);
e.stopPropagation();
//手动触发docTouchEvt清除因点击到del按钮上而被阻止冒泡到doc上的事件从而清除已打开的删除面板
//docTouchEvt();
//
//$curDelPanel = $(this).closest('.shopping-cart-good').children('.opt-panel').removeClass('hide');
//
//$(document).on('touchstart', docTouchEvt);
dialog.showDialog({
dialogText: '您确定要从购物车中删除吗?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
var id = $this.closest('.shopping-cart-good').data('id');
$.ajax({
method: 'post',
url: '/shoppingCart/del',
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
dialog.showDialog({
dialogText: '删除成功',
autoHide: true,
fast: true
});
history.go(0);
}
}).fail(function() {
dialog.showDialog({
autoHide: true,
dialogText: '网络错误~'
});
});
});
});
// .on('touchstart', '.opt-panel', function() {
// var $this = $(this),
// id = $this.closest('.shopping-cart-good').data('id'),
// url;
//
// if ($this.closest('.put-in-favorite').length > 0) {
//
// //移入收藏夹
// url = '/shoppingCart/col';
// } else {
//
// //删除
// url = '/shoppingCart/del';
// }
//
// $.ajax({
// type: 'POST',
// url: url,
// data: {
// id: id
// }
// });
//})
$('.btn-balance').on('touchend', function() {
window.location.href = '/shoppingCart/orderEnsure?cartType=' + 'ordinary';
});
$('.down').on('touchend', function() {
chosePanel.show();
});
$('.cut').on('touchend', function() {
var id = $(this).closest('.shopping-cart-good').data('id');
$.ajax({
type: 'POST',
url: '/shoppingCart/modifyNum',
data: {
sku: id,
increaseNum: '0'
},
success: function(data) {
if (data.code === 200) {
// window.history.go(0);
}
},
error: function() {
tip.show('网络错误');
}
});
});