order-ensure.js
5.02 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
import dialog from 'js/plugin/dialog';
import safeCheckBoxHbs from 'hbs/cart/order-ensure/safe-check-box.hbs';
import Page from 'js/yoho-page';
import tip from 'js/plugin/tip';
class OrderEnsure extends Page {
constructor(order) { // 参数为使用哪个 cookie
super();
this.order = order;
this.orderInfo = order.orderInfo;
this.selector = {
invoice: $('.invoice'),
invoiceType: $('.invoice-type'),
userMobile: $('.user-mobile'),
couponHelp: $('.coupon-help'),
conponDialogWrapper: $('#conponDialogWrapper'),
conponDialogCancel: $('#conponDialogCancel')
};
this.init();
this.bindEvents();
}
init() {
if (window.getUid() !== this.orderInfo('uid')) {
this.order.init();
window.location.reload();
}
}
bindEvents() {
this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
this.selector.couponHelp.on('click', this.showCouponHelp.bind(this));
this.selector.conponDialogCancel.on('click', this.cancelCouponHelp.bind(this));
}
/**
* 展示优惠券帮助弹窗
*/
showCouponHelp(e) {
this.selector.conponDialogWrapper.show();
e.preventDefault();
e.stopPropagation();
}
/**
* 关闭优惠券帮助弹窗
*/
cancelCouponHelp(e) {
this.selector.conponDialogWrapper.hide();
e.preventDefault();
e.stopPropagation();
}
/**
* 是否需要开发票
*/
needInvoice(event) {
let $this = $(event.currentTarget);
this.orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
this.selector.invoice.addClass('focus');
this.selector.invoiceType.html('电子发票(个人)<i class="iconfont"></i>');
this.orderInfo('receiverMobile', this.selector.userMobile.val());
this.orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
this.selector.invoice.removeClass('focus');
this.selector.invoiceType.html('');
this.orderInfo('invoices_title', null);
this.orderInfo('invoices_type', null);
this.orderInfo('receiverMobile', null);
this.orderInfo('buyerTaxNumber', null);
}
event.preventDefault();
event.stopPropagation();
}
/**
* 验证码弹窗
* @param {手机号} mobile
* @param {弹窗确定事件的回调} sureCallback
*/
showSafeCheckDialog(renderData, sureCallback) {
dialog.showDialog({
hasHeader: '安全验证',
dialogText: safeCheckBoxHbs(Object.assign({
mobile: this.selector.userMobile.val()
}, renderData)),
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
});
dialog.rewriteEvents().then(() => {
this.sckDialogClickHandle(sureCallback);
});
}
/**
* 验证码弹窗事件处理
*/
sckDialogClickHandle(sureCallback) {
let $dialogWrapper = $('#dialog-wrapper');
let $verifyCodeInput = $dialogWrapper.find('input[name=verifyCode]');
let $getVerifyCodeBtn = $('#getVerifyCodeBtn');
let $cancelBtn = $dialogWrapper.find('.dialog-left-btn');
let $sureBtn = $dialogWrapper.find('.dialog-right-btn');
this.countDown();
$verifyCodeInput.on('input', () => {
if ($(event.target).val()) {
$sureBtn.addClass('active');
} else {
$sureBtn.removeClass('active');
}
});
$getVerifyCodeBtn.on('click', () => {
if (!$getVerifyCodeBtn.hasClass('disable')) {
$verifyCodeInput.val('');
this.resendSms();
}
});
$cancelBtn.on('click', () => {
$dialogWrapper.fadeOut();
});
$sureBtn.on('click', () => {
if ($(event.target).hasClass('active')) {
sureCallback($verifyCodeInput.val());
}
});
}
/**
* 重发验证码
*/
resendSms() {
this.ajax({
url: '/cart/index/new/giftCardSendSms'
}).then(result => {
if (result.code === 200) {
this.countDown();
}
tip.show(result.message);
});
}
/**
* 获取验证码倒计时
*/
countDown() {
let count = 59;
let itime;
let $getVerifyCodeBtn = $('#getVerifyCodeBtn');
$getVerifyCodeBtn.addClass('disable');
itime = setInterval(() => {
if (count === 0) {
$getVerifyCodeBtn.text('重新获取').removeClass('disable');
clearInterval(itime);
} else {
$getVerifyCodeBtn.text('重新获取 (' + count-- + ')');
}
}, 1000);
}
}
module.exports = OrderEnsure;