|
@@ -7,9 +7,33 @@ var $ = require('yoho.jquery'); |
|
@@ -7,9 +7,33 @@ var $ = require('yoho.jquery'); |
7
|
|
7
|
|
8
|
var dialog = require('../common/dialog');
|
8
|
var dialog = require('../common/dialog');
|
9
|
|
9
|
|
|
|
10
|
+var accMul = function(arg1, arg2) {
|
|
|
11
|
+ var m = 0,
|
|
|
12
|
+ s1 = arg1.toString(),
|
|
|
13
|
+ s2 = arg2.toString();
|
|
|
14
|
+
|
|
|
15
|
+ try {
|
|
|
16
|
+ m += s1.split('.')[1].length;
|
|
|
17
|
+ } catch (e) {
|
|
|
18
|
+ }
|
|
|
19
|
+ try {
|
|
|
20
|
+ m += s2.split('.')[1].length;
|
|
|
21
|
+ } catch (e) {
|
|
|
22
|
+ }
|
|
|
23
|
+ return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
|
|
|
24
|
+};
|
|
|
25
|
+
|
10
|
//立即购买-门票
|
26
|
//立即购买-门票
|
11
|
var TicketCat = {
|
27
|
var TicketCat = {
|
12
|
el: {
|
28
|
el: {
|
|
|
29
|
+ $pan: $('.pan'),
|
|
|
30
|
+ $biok: $('#bisubmit'),
|
|
|
31
|
+ $loading: $('.loading'),
|
|
|
32
|
+ $payTotal: $('.play-total'),
|
|
|
33
|
+ $toPay: $('.to-play em'),
|
|
|
34
|
+ $errorTip: $('.errbitip'),
|
|
|
35
|
+ $tbody: $('table tbody', '.pay-wapper'),
|
|
|
36
|
+ //门票js
|
13
|
$showTicketMobile: $('.show-ticket-mobile'),
|
37
|
$showTicketMobile: $('.show-ticket-mobile'),
|
14
|
$ticketMobile: $('.ticket-mobile'),
|
38
|
$ticketMobile: $('.ticket-mobile'),
|
15
|
$ticketModifyBtn: $('.ticket-modify-btn'),
|
39
|
$ticketModifyBtn: $('.ticket-modify-btn'),
|
|
@@ -17,8 +41,64 @@ var TicketCat = { |
|
@@ -17,8 +41,64 @@ var TicketCat = { |
17
|
$ticketMobileBtn: $('.ticket-mobile-btn'),
|
41
|
$ticketMobileBtn: $('.ticket-mobile-btn'),
|
18
|
$ticketMobileInput: $('.ticket-mobile-input')
|
42
|
$ticketMobileInput: $('.ticket-mobile-input')
|
19
|
},
|
43
|
},
|
|
|
44
|
+ Common: {
|
|
|
45
|
+ enterNUM: function(str1, str2) {
|
|
|
46
|
+ str1 = str1.replace(/[^\d]/g, '');
|
|
|
47
|
+ if (str1 && str2) {
|
|
|
48
|
+ str1 = parseInt(str1);
|
|
|
49
|
+ str2 = parseInt(str2);
|
|
|
50
|
+ if (str1 > str2) {
|
|
|
51
|
+ str1 = str2;
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
|
|
54
|
+ return str1;
|
|
|
55
|
+ },
|
|
|
56
|
+ winShow: function(pan) {
|
|
|
57
|
+ pan.find('dt').show();
|
|
|
58
|
+ pan.find('dd').show();
|
|
|
59
|
+ if (pan.attr('class').match(/(-bi-)|(-juan-)/g)) {
|
|
|
60
|
+ pan.find('dt').hide();
|
|
|
61
|
+ }
|
|
|
62
|
+ },
|
|
|
63
|
+ winHide: function(pan) {
|
|
|
64
|
+ pan.find('dt').show();
|
|
|
65
|
+ pan.find('dd').hide();
|
|
|
66
|
+ },
|
|
|
67
|
+ strFixed: function(str) {
|
|
|
68
|
+ return parseFloat(str).toFixed(2);
|
|
|
69
|
+ }
|
|
|
70
|
+ },
|
20
|
init: function() {
|
71
|
init: function() {
|
21
|
- var el = this.el;
|
72
|
+ var _this = this,
|
|
|
73
|
+ el = this.el,
|
|
|
74
|
+ c = this.Common,
|
|
|
75
|
+ productSubtotal = 0;
|
|
|
76
|
+
|
|
|
77
|
+ //初始化产品价格(表格中的价格)
|
|
|
78
|
+ el.$tbody.find('tr').each(function(index) {
|
|
|
79
|
+ var td = $(this).find('td');
|
|
|
80
|
+ var len = el.$tbody.find('tr').length;
|
|
|
81
|
+ var subtotal = parseFloat(td.eq(1).html()) * parseInt(td.eq(3).html());
|
|
|
82
|
+
|
|
|
83
|
+ td.eq(1).html('¥' + td.eq(1).html());
|
|
|
84
|
+
|
|
|
85
|
+ if (td.hasClass('xforone')) {
|
|
|
86
|
+ td.eq(4).find('del').html('¥' + c.strFixed(subtotal));
|
|
|
87
|
+ subtotal = 0;
|
|
|
88
|
+ } else {
|
|
|
89
|
+ td.eq(4).html('¥' + c.strFixed(subtotal));
|
|
|
90
|
+ }
|
|
|
91
|
+ productSubtotal += subtotal;
|
|
|
92
|
+ if (!index) {
|
|
|
93
|
+ td.last().attr('rowspan', len);
|
|
|
94
|
+ } else {
|
|
|
95
|
+ td.last().remove();
|
|
|
96
|
+ }
|
|
|
97
|
+ if (index === len - 1) {
|
|
|
98
|
+ el.$tbody.find('tr').eq(0).find('td').last().html('<strong>¥' +
|
|
|
99
|
+ c.strFixed(productSubtotal) + '</strong>');
|
|
|
100
|
+ }
|
|
|
101
|
+ });
|
22
|
|
102
|
|
23
|
//修改手机号按钮
|
103
|
//修改手机号按钮
|
24
|
el.$ticketModifyBtn.click(function() {
|
104
|
el.$ticketModifyBtn.click(function() {
|
|
@@ -39,6 +119,153 @@ var TicketCat = { |
|
@@ -39,6 +119,153 @@ var TicketCat = { |
39
|
el.$setTicketMobile.addClass('hide');
|
119
|
el.$setTicketMobile.addClass('hide');
|
40
|
el.$ticketMobile.text(val);
|
120
|
el.$ticketMobile.text(val);
|
41
|
});
|
121
|
});
|
|
|
122
|
+
|
|
|
123
|
+ // 使用优惠券、使用yoho币点击展开
|
|
|
124
|
+ el.$pan.find('dt').click(function() {
|
|
|
125
|
+ var pan = $(this).parent('dl.pan');
|
|
|
126
|
+
|
|
|
127
|
+ if (pan.find('dd').is(':hidden')) {
|
|
|
128
|
+ c.winShow(pan);
|
|
|
129
|
+ $(this).addClass('active');
|
|
|
130
|
+ } else {
|
|
|
131
|
+ c.winHide(pan);
|
|
|
132
|
+ $(this).removeClass('active');
|
|
|
133
|
+ }
|
|
|
134
|
+ });
|
|
|
135
|
+
|
|
|
136
|
+ el.$biok.click(function() {
|
|
|
137
|
+ var pan = $(this).parents('dl.pan');
|
|
|
138
|
+ var selectData = {};
|
|
|
139
|
+
|
|
|
140
|
+ $('#biprice').addClass('is-select');
|
|
|
141
|
+ selectData = _this.getSelectData();
|
|
|
142
|
+
|
|
|
143
|
+ if (!/^\d+$/.test(selectData.yohoCoin + '') || selectData.yohoCoin * 1 === 0) {
|
|
|
144
|
+ $('.errbitip').html('请输入一个正整数');
|
|
|
145
|
+ $('#biprice').removeClass('is-select');
|
|
|
146
|
+ } else if (selectData.yohoCoin * 1 > $('.play-pan em').text() * 1) {
|
|
|
147
|
+ $('.errbitip').html('您的YOHO币不足');
|
|
|
148
|
+ $('#biprice').removeClass('is-select');
|
|
|
149
|
+ } else {
|
|
|
150
|
+ el.$loading.show();
|
|
|
151
|
+ $.ajax({
|
|
|
152
|
+ type: 'POST',
|
|
|
153
|
+ url: '/cart/index/orderCompute',
|
|
|
154
|
+ data: selectData,
|
|
|
155
|
+ success: function(data) {
|
|
|
156
|
+ el.$loading.hide();
|
|
|
157
|
+ if (data.code === 200) {
|
|
|
158
|
+ _this.render(data.data);
|
|
|
159
|
+ c.winHide(pan);
|
|
|
160
|
+ } else {
|
|
|
161
|
+ $('.errbitip').html(data.message);
|
|
|
162
|
+ $('#biprice').removeClass('is-select');
|
|
|
163
|
+ }
|
|
|
164
|
+ }
|
|
|
165
|
+ });
|
|
|
166
|
+ }
|
|
|
167
|
+ });
|
|
|
168
|
+
|
|
|
169
|
+ // 修改yoho币
|
|
|
170
|
+ $(document).on('click', '.bi-modify', function() {
|
|
|
171
|
+ var $pan = $('.play-bi-pan');
|
|
|
172
|
+
|
|
|
173
|
+ c.winShow($pan);
|
|
|
174
|
+ });
|
|
|
175
|
+
|
|
|
176
|
+ //键盘事件,计算有币货抵多少钱
|
|
|
177
|
+ $('#biprice').keyup(function() {
|
|
|
178
|
+ var val = $(this).val();
|
|
|
179
|
+
|
|
|
180
|
+ if (!/^\d+$/.test(val + '')) {
|
|
|
181
|
+ el.$errorTip.html('请输入一个正整数');
|
|
|
182
|
+ } else if (val * 1 > $(this).data('bi') * 1) {
|
|
|
183
|
+ el.$errorTip.html('您的YOHO币不足');
|
|
|
184
|
+ } else {
|
|
|
185
|
+ el.$errorTip.html('抵扣' + (val / 100).toFixed(2) + '元');
|
|
|
186
|
+ }
|
|
|
187
|
+ });
|
|
|
188
|
+
|
|
|
189
|
+ // 取消yoho 币
|
|
|
190
|
+ $('.cancel-bi').click(function() {
|
|
|
191
|
+ var $pan = $('.play-bi-pan'),
|
|
|
192
|
+ selectData = {};
|
|
|
193
|
+
|
|
|
194
|
+ $('.errbitip').html('');
|
|
|
195
|
+ el.$loading.show();
|
|
|
196
|
+ selectData = _this.getSelectData();
|
|
|
197
|
+ selectData.yohoCoin = 0;
|
|
|
198
|
+ $.ajax({
|
|
|
199
|
+ type: 'POST',
|
|
|
200
|
+ url: '/cart/index/setTicket',
|
|
|
201
|
+ data: selectData,
|
|
|
202
|
+ success: function(data) {
|
|
|
203
|
+ el.$loading.hide();
|
|
|
204
|
+ if (data.code === 200) {
|
|
|
205
|
+ _this.render(data.data);
|
|
|
206
|
+ c.winHide($pan);
|
|
|
207
|
+
|
|
|
208
|
+ $('#biprice').val('0');
|
|
|
209
|
+ $('#biprice').removeClass('is-select');
|
|
|
210
|
+ $('.errbitip').html('');
|
|
|
211
|
+ } else {
|
|
|
212
|
+ $('.errbitip').html(data.message);
|
|
|
213
|
+ }
|
|
|
214
|
+ }
|
|
|
215
|
+ });
|
|
|
216
|
+ });
|
|
|
217
|
+ },
|
|
|
218
|
+ //渲染价格明细
|
|
|
219
|
+ render: function(data) {
|
|
|
220
|
+ // 下面这段是在服务端算价格
|
|
|
221
|
+ var e = this.el,
|
|
|
222
|
+ i,
|
|
|
223
|
+ dArr = data.promotion_formula_list,
|
|
|
224
|
+ str = '',
|
|
|
225
|
+ isExpress = '';
|
|
|
226
|
+
|
|
|
227
|
+ for (i = 0; i < dArr.length; i++) {
|
|
|
228
|
+
|
|
|
229
|
+ if (dArr[i].promotion === 'YOHO币:') {
|
|
|
230
|
+ dArr[i].promotion = 'YOHO币<span class="bi-modify">[修改]</span>:';
|
|
|
231
|
+ }
|
|
|
232
|
+
|
|
|
233
|
+ if (dArr[i].isExpress) {
|
|
|
234
|
+ isExpress = 'total-express-w';
|
|
|
235
|
+ } else {
|
|
|
236
|
+ isExpress = '';
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ str += '<li class="' + isExpress + '">' +
|
|
|
240
|
+ '<label>' + dArr[i].promotion + '</label>' +
|
|
|
241
|
+ '<em>' + dArr[i].promotion_amount + '</em>' +
|
|
|
242
|
+ '</li>';
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ e.$payTotal.html(str);
|
|
|
246
|
+ e.$toPay.html((data.last_order_amount).toFixed(2));
|
|
|
247
|
+
|
|
|
248
|
+ //有货币清零状态更新
|
|
|
249
|
+ $('#biprice').val(accMul(100, data.use_yoho_coin));
|
|
|
250
|
+ if (data.use_yoho_coin === 0) {
|
|
|
251
|
+ $('.errbitip').text('');
|
|
|
252
|
+ } else {
|
|
|
253
|
+ $('.errbitip').text('抵扣' + data.use_yoho_coin.toFixed(2) + '元');
|
|
|
254
|
+ }
|
|
|
255
|
+
|
|
|
256
|
+ },
|
|
|
257
|
+ getSelectData: function() {
|
|
|
258
|
+ var expressVal = $('.express-list input[name="carriagegroup"]:checked').val();
|
|
|
259
|
+ var biVal = $('#biprice.is-select').val();
|
|
|
260
|
+ var cartType = $('.address-manage').attr('cart-type');
|
|
|
261
|
+ var resultData;
|
|
|
262
|
+
|
|
|
263
|
+ resultData = {
|
|
|
264
|
+ cartType: cartType,
|
|
|
265
|
+ deliveryWay: expressVal,
|
|
|
266
|
+ yohoCoin: biVal
|
|
|
267
|
+ };
|
|
|
268
|
+ return resultData;
|
42
|
}
|
269
|
}
|
43
|
};
|
270
|
};
|
44
|
|
271
|
|