order-ensure.js
4.32 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
import dialog from 'plugin/dialog';
import safeCheckBoxHbs from 'cart/order-ensure/safe-check-box.hbs';
import Page from 'yoho-page';
import tip from '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')
};
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));
}
/**
* 是否需要开发票
*/
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;