ticket.page.js
2.88 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
/**
* Created by TaoHuang on 2017/6/22.
*/
var $ = require('jquery');
var yas = require('../common/data-yas'),
dialog = require('../common/dialog');
var $orderPrice = $('#order-price');
var order = {};
var yohoCoin;
var submitting = false;
function validateUserInfo(info) {
var errTip = '';
if (!info.mobile) {
errTip = '您还没有填写手机号';
}
if (errTip) {
new dialog.Alert((errTip)).show();
return false;
}
return true;
}
function handleOrderInfo(info) {
var $goods = $('.goods-item');
info.sku = $goods.data('sku');
info.count = $goods.data('num');
info.mobile = $('.ticket-mobile-input').val();
return info;
}
function compute(coin) {
var req;
order = handleOrderInfo(order);
req = $.extend({}, order, {
coin: coin || 0
});
$.ajax({
type: 'POST',
url: '/cart/ticketcompute',
data: req
}).then((result) => {
if (result.code === 200) {
order.coin = result.data.usedCoinNum;
yohoCoin.maxCoin = result.data.canUseCoinNum;
$orderPrice.html('¥ ' + result.data.last_order_amount);
}
});
}
// 有货币
yohoCoin = {
$el: $('#yoho-coin-box'),
init: function() {
var data;
if (!this.$el.length) {
return;
}
data = this.$el.data();
if (data) {
order.coin = data.coin || 0;
this.maxCoin = data.max;
this.totalCoin = data.total;
}
this.eventBind();
},
eventBind: function() {
var that = this;
this.$el.on('click', '.coin-use-btn', function() {
if (order.coin * 1 !== this.maxCoin * 1) {
compute(that.maxCoin);
}
that.close();
}).on('click', '.coin-cancel-btn', function() {
if (order.coin * 1 !== 0) {
order.coin = 0;
compute();
}
that.close();
});
},
close: function() {
this.$el.prev().children('.locker-switch').trigger('click');
}
};
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
$par.toggleClass('open');
});
$('#order-submit').on('click', function() {
if (submitting) {
return;
}
order = handleOrderInfo(order);
if (!validateUserInfo(order)) {
return;
}
submitting = true;
$.ajax({
type: 'POST',
url: '/cart/ticketSubmit',
data: order
}).then(function(data) {
if (data.code === 200) {
window.location.href = data.data.refer;
}
}).always(function() {
submitting = false;
});
});
yohoCoin.init();
// 获取用户是否新客(品众统计)写cookie
$.ajax({type: 'GET', url: '/home/newuser'});
// 订单确认页默认埋点
yas.givePoint('YB_SC_ORDER_ENSURE');