me-gift.page.js~RF1671ead5.TMP
9.86 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
var $ = require('yoho-jquery'),
Hbs = require('yoho-handlebars'),
dialog = require('../common/dialog'),
Captcha = require('../plugins/captcha');
var meGift;
require('../common');
meGift = {
isFlag: false, //防止用户频繁点击
// 验证邮箱模板
emailTpl: Hbs.compile($('#verify-email-tpl').html()),
// 绑定手机模板
mobileTpl: Hbs.compile($('#verify-mobile-tpl').html()),
// 激活礼品卡模板
giftTpl: Hbs.compile($('#activate-gift-tpl').html()),
// 消费明细模板
detailGiftTpl: Hbs.compile($('#detail-gift-tpl').html()),
// 添加礼品卡按钮
$addGift: $('.add-gift'),
// 是否绑定手机
isBinMobile: +$('.me-content').data('is-bin-mobile'),
// 用户邮箱
userEmail: $('.me-content').data('email'),
init: function() {
var that = this;
// 添加礼品卡
this.$addGift.click(function() {
if (that.isBinMobile) {
that.activateGift();
} else {
that.getMobileCode();
}
});
// 消费明细
$('.me-gift-table').on('click', '.info-list', function() {
that.infoList($(this).closest('.me-gift-tr').data('card-code'));
});
// 显示手机区号或类型下拉列表
$('body').on('click', '.mobile-area,.gift-filter', function() {
$(this).find('.ul-list').toggle();
});
// 选择手机区号
$('body').on('click', '.mobile-area-list', function(event) {
var $li = $(event.target).closest('li');
$('.mobile-area').find('em').text($li.data('cc'));
});
// 选择类型筛选
$('body').on('click', '.gift-filter ul', function(event) {
var $li = $(event.target).closest('li');
$('.gift-filter').find('em').text($li.text());
});
},
postAjax: function(url, data, verifyData, captcha) {
var that = this;
var deferred = $.Deferred();
var x;
if (that.isFlag) {
return deferred.resolve({
code: 401,
message: '数据请求中...'
});
}
if (verifyData) {
for(x in verifyData) {
if (!data[x]) {
that.meAlert(verifyData[x], false);
return deferred.resolve({
code: 401,
message: verifyData[x]
});
}
}
}
that.isFlag = true;
return $.ajax({
url: url,
type: 'post',
data: data
}).then(function(res) {
captcha && captcha.hideTip();
if (res.code === 405) {
captcha && captcha.showTip(res.message);
} else {
that.meAlert(res.message, false);
}
that.isFlag = false;
return res;
}, function() {
that.isFlag = false;
});
},
// 礼品卡详情列表
detailList: function() {
},
intTimer: function($dom) {
var intTime = 60;
var intval = setInterval(function() {
if (intTime-- <= 0) {
clearInterval(intval);
$dom.removeClass('intTimer').val('获取短信验证码');
return false;
}
$dom.val(intTime + ' S');
}, 1000);
$dom.addClass('intTimer');
$dom.val(intTime + ' S');
},
// 获取邮箱验证码
getEmailCode: function(captcha) {
this.postAjax('/home/megift/sendEmailCode', {
email: this.userEmail,
verifyCode: captcha.getResults()
}).then(function(res) {
if (res.code === 200) {
that.intTimer($('.email-btn'));
}
});
},
// 效验邮箱验证码
verifyEmailCode: function() {
var that = this;
var captcha;
var dg = new dialog.Dialog({
content: that.emailTpl({}),
className: 'me-gift-confirm',
btns: [{
id: 'confirm-email-btn',
name: '绑定手机号',
btnClass: ['alert-sure'],
cb: function() {
var emailCode = $('.email-code').val();
var verifyData = {code: '验证码不能为空'};
that.postAjax('/home/megift/verifyEmail', {
email: that.userEmail,
code: emailCode
}, verifyData, captcha).then(function(res) {
if (res.code === 200) {
dg.close();
that.getMobileCode();
}
});
}
}]
}).show();
captcha = new Captcha('#captcha').init();
//发送邮箱验证码
$('.me-gift-confirm').find('.email-btn').unbind('click').bind('click', function() {
if (!$(this).hasClass('intTimer')) {
that.getEmailCode(captcha);
}
});
},
// 获取手机验证码
getMobileCode: function() {
var that = this;
var captcha;
var dg = new dialog.Dialog({
content: that.mobileTpl({}),
className: 'me-gift-confirm',
btns: [{
id: 'confirm-mobile-cancel',
name: '取消',
btnClass: ['confirm-cancel'],
cb: function() {
dg.close();
}
}, {
id: 'confirm-mobile-sure',
name: '激活',
btnClass: ['confirm-sure'],
cb: function() {
var verifyData = {
area: '请选择手机区号',
mobile: '手机号不能为空',
code: '手机验证码不能为空',
};
that.postAjax('/home/megift/changeMobile', {
area: ($('.mobile-area').find('em').text() || '').replace(/^\+/, ''),
mobile: $('.mobile').val(),
code: $('.mobile-code').val()
}, verifyData, captcha).then(function(res) {
if (res.code === 200) {
dg.close();
that.activateGift();
}
});
}
}]
}).show();
captcha = new Captcha('#captcha').init();
//发送邮箱验证码
$('.me-gift-confirm').find('.mobile-btn').unbind('click').bind('click', function() {
if (!$(this).hasClass('intTimer')) {
that.smsBind(captcha);
}
});
},
// 发送手机验证码
smsBind: function(captcha) {
var that = this;
var area = ($('.mobile-area').find('em').text() || '').replace(/^\+/, '');
var mobile = $('.mobile').val();
var verifyData = {
area: '请选择手机区号',
mobile: '手机号不能为空'
};
this.postAjax('/home/megift/smsBind', {
area: area,
mobile: mobile,
verifyCode: captcha.getResults()
}, verifyData, captcha).then(function(res) {
if (res.code === 200) {
that.intTimer($('.email-btn'));
}
});
},
// 激活礼品卡
activateGift: function() {
var that = this;
var captcha;
var dg = new dialog.Dialog({
content: that.giftTpl({}),
className: 'me-gift-confirm',
btns: [{
id: 'confirm-gift-cancel',
name: '取消',
btnClass: ['confirm-cancel'],
cb: function() {
dg.close();
}
}, {
id: 'confirm-gift-sure',
name: '激活',
btnClass: ['confirm-sure'],
cb: function() {
var $confirm = $('.me-gift-confirm');
var verifyData = {
cardCode: '礼品卡卡号不能为空',
cardPwd: '礼品卡卡密不能为空'
};
that.postAjax('/home/meGift/activateGift', {
cardCode: $confirm.find('.card-code').val(),
cardPwd: $confirm.find('.card-pwd').val(),
verifyCode: captcha.getResults()
}, verifyData, captcha).then(function(res) {
if (res.code === 200) {
dg.close();
that.meAlert('<p>您的礼品卡激活成功</p><p>请尽情享用</p>', false);
}
});
}
}]
}).show();
captcha = new Captcha('#captcha').init();
},
// 消费明细
infoList: function(cardCode) {
var that = this;
new dialog.Dialog({
content: that.detailGiftTpl({}),
className: 'me-gift-page me-gift-confirm detail-gift-list'
}).show();
$.get('/home/megift/detail', {
cardCode: cardCode
}).then(function(res) {
if (!res) {
return false;
}
$('.detail-gift-content').html(res)
});
},
// 我的弹框
meAlert: function(content, mask) {
var dg = new dialog.Dialog({
content: content,
className: 'me-gift-alert',
mask: mask || true,
btns: [{
name: '我知道了',
btnClass: ['btn-close', 'alert-sure'],
cb: function() {
dg.close();
}
}]
}).show();
}
};
$(function() {
meGift.init();
});