1
|
-var $ = require('yoho-jquery'),
|
|
|
2
|
- Hbs = require('yoho-handlebars'),
|
|
|
3
|
- dialog = require('../common/dialog'),
|
|
|
4
|
- Captcha = require('../plugins/captcha');
|
|
|
5
|
-
|
|
|
6
|
-var meGift;
|
|
|
7
|
-
|
|
|
8
|
-require('../common');
|
|
|
9
|
-
|
|
|
10
|
-meGift = {
|
|
|
11
|
- isFlag: false, //防止用户频繁点击
|
|
|
12
|
- // 验证邮箱模板
|
|
|
13
|
- emailTpl: Hbs.compile($('#verify-email-tpl').html()),
|
|
|
14
|
-
|
|
|
15
|
- // 绑定手机模板
|
|
|
16
|
- mobileTpl: Hbs.compile($('#verify-mobile-tpl').html()),
|
|
|
17
|
-
|
|
|
18
|
- // 激活礼品卡模板
|
|
|
19
|
- giftTpl: Hbs.compile($('#activate-gift-tpl').html()),
|
|
|
20
|
-
|
|
|
21
|
- // 消费明细模板
|
|
|
22
|
- detailGiftTpl: Hbs.compile($('#detail-gift-tpl').html()),
|
|
|
23
|
-
|
|
|
24
|
- // 添加礼品卡按钮
|
|
|
25
|
- $addGift: $('.add-gift'),
|
|
|
26
|
-
|
|
|
27
|
- // 是否绑定手机
|
|
|
28
|
- isBinMobile: +$('.me-content').data('is-bin-mobile'),
|
|
|
29
|
-
|
|
|
30
|
- // 用户邮箱
|
|
|
31
|
- userEmail: $('.me-content').data('email'),
|
|
|
32
|
-
|
|
|
33
|
- init: function() {
|
|
|
34
|
- var that = this;
|
|
|
35
|
-
|
|
|
36
|
- // 添加礼品卡
|
|
|
37
|
- this.$addGift.click(function() {
|
|
|
38
|
- if (that.isBinMobile) {
|
|
|
39
|
- that.activateGift();
|
|
|
40
|
- } else {
|
|
|
41
|
- that.getMobileCode();
|
|
|
42
|
- }
|
|
|
43
|
- });
|
|
|
44
|
-
|
|
|
45
|
- // 消费明细
|
|
|
46
|
- $('.me-gift-table').on('click', '.info-list', function() {
|
|
|
47
|
- that.infoList($(this).closest('.me-gift-tr').data('card-code'));
|
|
|
48
|
- });
|
|
|
49
|
-
|
|
|
50
|
- // 显示手机区号或类型下拉列表
|
|
|
51
|
- $('body').on('click', '.mobile-area,.gift-filter', function() {
|
|
|
52
|
- $(this).find('.ul-list').toggle();
|
|
|
53
|
- });
|
|
|
54
|
-
|
|
|
55
|
- // 选择手机区号
|
|
|
56
|
- $('body').on('click', '.mobile-area-list', function(event) {
|
|
|
57
|
- var $li = $(event.target).closest('li');
|
|
|
58
|
-
|
|
|
59
|
- $('.mobile-area').find('em').text($li.data('cc'));
|
|
|
60
|
- });
|
|
|
61
|
-
|
|
|
62
|
- // 选择类型筛选
|
|
|
63
|
- $('body').on('click', '.gift-filter ul', function(event) {
|
|
|
64
|
- var $li = $(event.target).closest('li');
|
|
|
65
|
-
|
|
|
66
|
- $('.gift-filter').find('em').text($li.text());
|
|
|
67
|
- });
|
|
|
68
|
- },
|
|
|
69
|
-
|
|
|
70
|
- postAjax: function(url, data, verifyData, captcha) {
|
|
|
71
|
- var that = this;
|
|
|
72
|
- var deferred = $.Deferred();
|
|
|
73
|
- var x;
|
|
|
74
|
-
|
|
|
75
|
- if (that.isFlag) {
|
|
|
76
|
- return deferred.resolve({
|
|
|
77
|
- code: 401,
|
|
|
78
|
- message: '数据请求中...'
|
|
|
79
|
- });
|
|
|
80
|
- }
|
|
|
81
|
-
|
|
|
82
|
- if (verifyData) {
|
|
|
83
|
- for(x in verifyData) {
|
|
|
84
|
- if (!data[x]) {
|
|
|
85
|
- that.meAlert(verifyData[x], false);
|
|
|
86
|
- return deferred.resolve({
|
|
|
87
|
- code: 401,
|
|
|
88
|
- message: verifyData[x]
|
|
|
89
|
- });
|
|
|
90
|
- }
|
|
|
91
|
- }
|
|
|
92
|
- }
|
|
|
93
|
-
|
|
|
94
|
- that.isFlag = true;
|
|
|
95
|
-
|
|
|
96
|
- return $.ajax({
|
|
|
97
|
- url: url,
|
|
|
98
|
- type: 'post',
|
|
|
99
|
- data: data
|
|
|
100
|
- }).then(function(res) {
|
|
|
101
|
- captcha && captcha.hideTip();
|
|
|
102
|
-
|
|
|
103
|
- if (res.code === 405) {
|
|
|
104
|
- captcha && captcha.showTip(res.message);
|
|
|
105
|
- } else {
|
|
|
106
|
- that.meAlert(res.message, false);
|
|
|
107
|
- }
|
|
|
108
|
-
|
|
|
109
|
- that.isFlag = false;
|
|
|
110
|
- return res;
|
|
|
111
|
- }, function() {
|
|
|
112
|
- that.isFlag = false;
|
|
|
113
|
- });
|
|
|
114
|
- },
|
|
|
115
|
-
|
|
|
116
|
- // 礼品卡详情列表
|
|
|
117
|
- detailList: function() {
|
|
|
118
|
-
|
|
|
119
|
- },
|
|
|
120
|
-
|
|
|
121
|
- intTimer: function($dom) {
|
|
|
122
|
- var intTime = 60;
|
|
|
123
|
- var intval = setInterval(function() {
|
|
|
124
|
-
|
|
|
125
|
- if (intTime-- <= 0) {
|
|
|
126
|
- clearInterval(intval);
|
|
|
127
|
- $dom.removeClass('intTimer').val('获取短信验证码');
|
|
|
128
|
- return false;
|
|
|
129
|
- }
|
|
|
130
|
-
|
|
|
131
|
- $dom.val(intTime + ' S');
|
|
|
132
|
- }, 1000);
|
|
|
133
|
-
|
|
|
134
|
- $dom.addClass('intTimer');
|
|
|
135
|
- $dom.val(intTime + ' S');
|
|
|
136
|
- },
|
|
|
137
|
- // 获取邮箱验证码
|
|
|
138
|
- getEmailCode: function(captcha) {
|
|
|
139
|
- this.postAjax('/home/megift/sendEmailCode', {
|
|
|
140
|
- email: this.userEmail,
|
|
|
141
|
- verifyCode: captcha.getResults()
|
|
|
142
|
- }).then(function(res) {
|
|
|
143
|
- if (res.code === 200) {
|
|
|
144
|
- that.intTimer($('.email-btn'));
|
|
|
145
|
- }
|
|
|
146
|
- });
|
|
|
147
|
- },
|
|
|
148
|
-
|
|
|
149
|
- // 效验邮箱验证码
|
|
|
150
|
- verifyEmailCode: function() {
|
|
|
151
|
- var that = this;
|
|
|
152
|
- var captcha;
|
|
|
153
|
- var dg = new dialog.Dialog({
|
|
|
154
|
- content: that.emailTpl({}),
|
|
|
155
|
- className: 'me-gift-confirm',
|
|
|
156
|
- btns: [{
|
|
|
157
|
- id: 'confirm-email-btn',
|
|
|
158
|
- name: '绑定手机号',
|
|
|
159
|
- btnClass: ['alert-sure'],
|
|
|
160
|
- cb: function() {
|
|
|
161
|
- var emailCode = $('.email-code').val();
|
|
|
162
|
- var verifyData = {code: '验证码不能为空'};
|
|
|
163
|
-
|
|
|
164
|
- that.postAjax('/home/megift/verifyEmail', {
|
|
|
165
|
- email: that.userEmail,
|
|
|
166
|
- code: emailCode
|
|
|
167
|
- }, verifyData, captcha).then(function(res) {
|
|
|
168
|
- if (res.code === 200) {
|
|
|
169
|
- dg.close();
|
|
|
170
|
- that.getMobileCode();
|
|
|
171
|
- }
|
|
|
172
|
- });
|
|
|
173
|
- }
|
|
|
174
|
- }]
|
|
|
175
|
- }).show();
|
|
|
176
|
-
|
|
|
177
|
- captcha = new Captcha('#captcha').init();
|
|
|
178
|
-
|
|
|
179
|
- //发送邮箱验证码
|
|
|
180
|
- $('.me-gift-confirm').find('.email-btn').unbind('click').bind('click', function() {
|
|
|
181
|
- if (!$(this).hasClass('intTimer')) {
|
|
|
182
|
- that.getEmailCode(captcha);
|
|
|
183
|
- }
|
|
|
184
|
- });
|
|
|
185
|
- },
|
|
|
186
|
-
|
|
|
187
|
- // 获取手机验证码
|
|
|
188
|
- getMobileCode: function() {
|
|
|
189
|
- var that = this;
|
|
|
190
|
- var captcha;
|
|
|
191
|
- var dg = new dialog.Dialog({
|
|
|
192
|
- content: that.mobileTpl({}),
|
|
|
193
|
- className: 'me-gift-confirm',
|
|
|
194
|
- btns: [{
|
|
|
195
|
- id: 'confirm-mobile-cancel',
|
|
|
196
|
- name: '取消',
|
|
|
197
|
- btnClass: ['confirm-cancel'],
|
|
|
198
|
- cb: function() {
|
|
|
199
|
- dg.close();
|
|
|
200
|
- }
|
|
|
201
|
- }, {
|
|
|
202
|
- id: 'confirm-mobile-sure',
|
|
|
203
|
- name: '激活',
|
|
|
204
|
- btnClass: ['confirm-sure'],
|
|
|
205
|
- cb: function() {
|
|
|
206
|
- var verifyData = {
|
|
|
207
|
- area: '请选择手机区号',
|
|
|
208
|
- mobile: '手机号不能为空',
|
|
|
209
|
- code: '手机验证码不能为空',
|
|
|
210
|
- };
|
|
|
211
|
-
|
|
|
212
|
- that.postAjax('/home/megift/changeMobile', {
|
|
|
213
|
- area: ($('.mobile-area').find('em').text() || '').replace(/^\+/, ''),
|
|
|
214
|
- mobile: $('.mobile').val(),
|
|
|
215
|
- code: $('.mobile-code').val()
|
|
|
216
|
- }, verifyData, captcha).then(function(res) {
|
|
|
217
|
- if (res.code === 200) {
|
|
|
218
|
- dg.close();
|
|
|
219
|
- that.activateGift();
|
|
|
220
|
- }
|
|
|
221
|
- });
|
|
|
222
|
- }
|
|
|
223
|
- }]
|
|
|
224
|
- }).show();
|
|
|
225
|
-
|
|
|
226
|
- captcha = new Captcha('#captcha').init();
|
|
|
227
|
-
|
|
|
228
|
- //发送邮箱验证码
|
|
|
229
|
- $('.me-gift-confirm').find('.mobile-btn').unbind('click').bind('click', function() {
|
|
|
230
|
- if (!$(this).hasClass('intTimer')) {
|
|
|
231
|
- that.smsBind(captcha);
|
|
|
232
|
- }
|
|
|
233
|
- });
|
|
|
234
|
- },
|
|
|
235
|
-
|
|
|
236
|
- // 发送手机验证码
|
|
|
237
|
- smsBind: function(captcha) {
|
|
|
238
|
- var that = this;
|
|
|
239
|
- var area = ($('.mobile-area').find('em').text() || '').replace(/^\+/, '');
|
|
|
240
|
- var mobile = $('.mobile').val();
|
|
|
241
|
- var verifyData = {
|
|
|
242
|
- area: '请选择手机区号',
|
|
|
243
|
- mobile: '手机号不能为空'
|
|
|
244
|
- };
|
|
|
245
|
-
|
|
|
246
|
- this.postAjax('/home/megift/smsBind', {
|
|
|
247
|
- area: area,
|
|
|
248
|
- mobile: mobile,
|
|
|
249
|
- verifyCode: captcha.getResults()
|
|
|
250
|
- }, verifyData, captcha).then(function(res) {
|
|
|
251
|
- if (res.code === 200) {
|
|
|
252
|
- that.intTimer($('.email-btn'));
|
|
|
253
|
- }
|
|
|
254
|
- });
|
|
|
255
|
- },
|
|
|
256
|
- // 激活礼品卡
|
|
|
257
|
- activateGift: function() {
|
|
|
258
|
- var that = this;
|
|
|
259
|
- var captcha;
|
|
|
260
|
- var dg = new dialog.Dialog({
|
|
|
261
|
- content: that.giftTpl({}),
|
|
|
262
|
- className: 'me-gift-confirm',
|
|
|
263
|
- btns: [{
|
|
|
264
|
- id: 'confirm-gift-cancel',
|
|
|
265
|
- name: '取消',
|
|
|
266
|
- btnClass: ['confirm-cancel'],
|
|
|
267
|
- cb: function() {
|
|
|
268
|
- dg.close();
|
|
|
269
|
- }
|
|
|
270
|
- }, {
|
|
|
271
|
- id: 'confirm-gift-sure',
|
|
|
272
|
- name: '激活',
|
|
|
273
|
- btnClass: ['confirm-sure'],
|
|
|
274
|
- cb: function() {
|
|
|
275
|
- var $confirm = $('.me-gift-confirm');
|
|
|
276
|
- var verifyData = {
|
|
|
277
|
- cardCode: '礼品卡卡号不能为空',
|
|
|
278
|
- cardPwd: '礼品卡卡密不能为空'
|
|
|
279
|
- };
|
|
|
280
|
-
|
|
|
281
|
- that.postAjax('/home/meGift/activateGift', {
|
|
|
282
|
- cardCode: $confirm.find('.card-code').val(),
|
|
|
283
|
- cardPwd: $confirm.find('.card-pwd').val(),
|
|
|
284
|
- verifyCode: captcha.getResults()
|
|
|
285
|
- }, verifyData, captcha).then(function(res) {
|
|
|
286
|
- if (res.code === 200) {
|
|
|
287
|
- dg.close();
|
|
|
288
|
- that.meAlert('<p>您的礼品卡激活成功</p><p>请尽情享用</p>', false);
|
|
|
289
|
- }
|
|
|
290
|
- });
|
|
|
291
|
- }
|
|
|
292
|
- }]
|
|
|
293
|
- }).show();
|
|
|
294
|
-
|
|
|
295
|
- captcha = new Captcha('#captcha').init();
|
|
|
296
|
- },
|
|
|
297
|
-
|
|
|
298
|
- // 消费明细
|
|
|
299
|
- infoList: function(cardCode) {
|
|
|
300
|
- var that = this;
|
|
|
301
|
-
|
|
|
302
|
- new dialog.Dialog({
|
|
|
303
|
- content: that.detailGiftTpl({}),
|
|
|
304
|
- className: 'me-gift-page me-gift-confirm detail-gift-list'
|
|
|
305
|
- }).show();
|
|
|
306
|
-
|
|
|
307
|
- $.get('/home/megift/detail', {
|
|
|
308
|
- cardCode: cardCode
|
|
|
309
|
- }).then(function(res) {
|
|
|
310
|
- if (!res) {
|
|
|
311
|
- return false;
|
|
|
312
|
- }
|
|
|
313
|
-
|
|
|
314
|
- $('.detail-gift-content').html(res)
|
|
|
315
|
- });
|
|
|
316
|
- },
|
|
|
317
|
-
|
|
|
318
|
- // 我的弹框
|
|
|
319
|
- meAlert: function(content, mask) {
|
|
|
320
|
- var dg = new dialog.Dialog({
|
|
|
321
|
- content: content,
|
|
|
322
|
- className: 'me-gift-alert',
|
|
|
323
|
- mask: mask || true,
|
|
|
324
|
- btns: [{
|
|
|
325
|
- name: '我知道了',
|
|
|
326
|
- btnClass: ['btn-close', 'alert-sure'],
|
|
|
327
|
- cb: function() {
|
|
|
328
|
- dg.close();
|
|
|
329
|
- }
|
|
|
330
|
- }]
|
|
|
331
|
- }).show();
|
|
|
332
|
- }
|
|
|
333
|
-};
|
|
|
334
|
-
|
|
|
335
|
-$(function() {
|
|
|
336
|
- meGift.init();
|
|
|
337
|
-}); |
|
|