index.page.js
8.61 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
var $ = require('yoho-jquery'),
phone,
reg,
orderCode = $('#orderCode').html(),
oldUserCouponPic = $('#oldUserCouponPic').html(),
newUserCouponPic = $('#newUserCouponPic').html(),
tipMessage = $('#tipMessage').html();
$('#phone').bind('input propertychange', function() {
if ($(this).val().length === 11) {
$('.input-content div').eq('0').addClass('verification-code');
} else {
$('.input-content div').eq('0').removeClass();
if ($(this).val().length >= 1) {
$('.input-content i').eq('0').removeClass('hidden');
} else {
$('.input-content i').eq('0').addClass('hidden');
}
}
});
$('#verification').bind('input propertychange', function() {
if ($(this).val().length === 4) {
$('.input-content div').eq('1').addClass('get');
} else {
$('.input-content div').eq('1').removeClass();
if ($(this).val().length >= 1) {
$('.input-content i').eq('1').removeClass('hidden');
} else {
$('.input-content i').eq('1').addClass('hidden');
}
}
});
if ($('#activityEnded').html()) {
$('.tip-wrap').removeClass('hidden');
$('.tip-wrap .title').html(tipMessage);
}
if (!$('#newUser').html()) {
$('.gain-coupon-centent .coupon img').attr('src', oldUserCouponPic);
}
$('.input-content').on('click', '.verification-code', function() {
$('.input-content div').eq('0').removeClass('verification-code');
phone = $(this).siblings('input').val();
reg = /[0-9]{11}/;
if (!reg.test(phone)) {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">手机号错误,请重新输入。<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
return;
}
$.ajax({
url: '/coupon/phone',
data: {
mobile: $('#phone').val(),
ordercode: orderCode
},
dataType: 'json',
success: function(data) {
if (data.result.code === 200) {
if (!data.result.newUser) {
$('.gain-coupon-centent .coupon img').attr('src', oldUserCouponPic);
} else {
$('.gain-coupon-centent .coupon img').attr('src', newUserCouponPic);
}
if (data.result.ended) {
$('.tip-wrap').removeClass('hidden');
$('.tip-wrap .title').html(data.result.message);
} else if (data.result.geted) {
$('.page .gain-coupon-centent').removeClass('hidden');
$('.page .coupon-centent').addClass('hidden');
$('#mobile').html('优惠券已发放至账户' + data.result.mobile);
} else if (data.result.newUser) {
$('.coupon-centent .phone-input-content').addClass('hidden');
$('.coupon-centent .vertify-input-content').removeClass('hidden');
} else if (data.result.wrongNumb) {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">手机号错误,请重新输入。<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
return;
}
} else {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">网络错误<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
}
},
error: function(data) {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">网络错误,稍后再试!<p>');
console.log(data);
}
});
});
$('.input-content').on('click', '.get', function() {
$('.input-content div').eq('1').removeClass('get');
if ($(this).siblings('input').val().length === 4) {
$.ajax({
url: '/coupon/verify',
data: {
identifycode: $('#verification').val(),
mobile: $('#phone').val(),
ordercode: orderCode
},
dataType: 'json',
success: function(data) {
if (data.result.code === 200) {
if (!data.result.newUser) {
$('.gain-coupon-centent .coupon img').attr('src', oldUserCouponPic);
} else {
$('.gain-coupon-centent .coupon img').attr('src', newUserCouponPic);
}
if (data.result.ended) {
$('.tip-wrap').removeClass('hidden');
$('.tip-wrap .title').html(data.result.message);
} else if (data.result.geted) {
$('.page .gain-coupon-centent').removeClass('hidden');
$('.page .coupon-centent').addClass('hidden');
$('#mobile').html('优惠券已发放至账户' + data.result.mobile);
} else if (data.result.newUser) {
$('.coupon-centent .phone-input-content').addClass('hidden');
$('.coupon-centent .vertify-input-content').removeClass('hidden');
} else if (data.result.wrongNumb) {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">手机号错误,请重新输入。<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
return;
}
} else {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">' + data.result.message + '<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
}
},,
error: function(data) {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">网络错误,稍后再试!<p>');
console.log(data);
}
});
} else {
$('#dialog').removeClass('hidden');
$('.keep-out').removeClass('hidden');
$('#dialog .content').html('<p class="phone-error">验证码错误,请重新输入。<p>');
setTimeout(function() {
$('.messages').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
}, 1400);
}
});
$('.close').on('click', function() {
$('.dialog').addClass('hidden');
$('.keep-out').addClass('hidden');
$('#dialog .content').html(' ');
});
$('.coupon-description span').on('click', function() {
$('#message').removeClass('hidden');
$('.keep-out').removeClass('hidden');
});
$('.description').on('click', function() {
$('#message').removeClass('hidden');
$('.keep-out').removeClass('hidden');
});
$('.input-content').on('click', '.get', function() {
if (window._yas) {
window._yas.sendCustomInfo({
receiveCoupon: 'Y'
}, true);
}
});
$('.input-content .clear-mobile').on('click', function() {
$('.input-content input').eq('0').val('');
$(this).addClass('hidden');
$('.input-content div').eq('0').removeClass();
});
$('.input-content .clear-verify').on('click', function() {
$('.input-content input').eq('1').val('');
$(this).addClass('hidden');
$('.input-content div').eq('1').removeClass();
});