select-invoice.page.js
5.53 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
/**
* 发票信息
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/14
*/
require('cart/select-invoice.page.css');
let $ = require('yoho-jquery'),
tip = require('plugin/tip'),
dialog = require('plugin/dialog'),
order = require('./order-info');
let $invoiceNotice = $('.invoice-notice'),
$companyArea = $('.company-area'),
$editFlag = $('.edit-flag'),
$chooseCont = $('.choose-cont'),
$invoiceType = $('.invoice-type'),
$tel = $('.tel'),
$company = $('.company'),
$telArea = $('.tel-area'),
orderInfo = order.orderInfo,
linkUrl = document.referrer,
$chooseContLi = $('.invoice-cont').find('.icon-cb-radio').parent(),
$copyTel = $('.copy-tel'),
isModifyTel = false;
let myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
let C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
require('common');
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
function goToBack() {
if (linkUrl) {
window.location.href = linkUrl;
} else {
history.go(-1);
}
}
// 单选效果
function chooseAction(pDom, dom) {
if (dom.hasClass('icon-cb-radio')) {
return;
} else {
pDom.find('.choose').removeClass('icon-cb-radio icon-radio').addClass('icon-radio');
dom.removeClass('icon-radio').addClass('icon-cb-radio');
dom.parent().addClass('on');
dom.parent().siblings().removeClass('on');
$editFlag.val('true');
}
}
// 确认表单事件
function confirmAction() {
let type = $invoiceType.find('.on').data('id'),
title = $('.invoice-top').find('.on').text(),
tel = $tel.attr('data-tel'),
company = $company.val(),
cont = $chooseCont.data('id');
if ($editFlag.val() === 'true') {
if (type === 2 && !myreg.test($tel.attr('data-tel'))) {
tip.show('请输入正确手机号');
$tel.focus();
return false;
} else if (title === '单位' && company.length === 0) {
tip.show('请填写发票抬头');
$company.focus();
return false;
} else if (title === '单位' && company.length > 30) {
tip.show('发票抬头不得超过30个汉字');
$company.focus();
return false;
} else {
dialog.showDialog({
dialogText: '确认保存修改内容?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
orderInfo('invoiceText', (title === '单位' ? company : ''));
orderInfo('invoiceType', cont);
orderInfo('receiverMobile', tel);
orderInfo('invoicesType', type);
orderInfo('invoiceTitle', title);
if (isModifyTel && $copyTel !== tel) {
orderInfo('isModifyTel', true);
} else {
orderInfo('isModifyTel', false);
}
dialog.showDialog({
dialogText: '保存成功',
autoHide: true,
fast: true
});
goToBack();
}, function() {
goToBack();
});
}
} else {
goToBack();
}
}
$chooseCont.html($chooseContLi.text()).attr('data-id', $chooseContLi.find('span').data('id'));
// 发票抬头、发票内容选择
$('.invoice-top span, .invoice-cont li').not('.invoice-cont .cont-title').on('touchstart', function() {
chooseAction($(this).parent(), $(this).find('.choose'));
if ($(this).parent().hasClass('invoice-cont')) {
$chooseCont.html($(this).text()).attr('data-id', $(this).find('span').data('id'));
}
if ($(this).text() === '单位') {
$companyArea.slideDown();
}
if ($(this).text() === '个人') {
$companyArea.slideUp();
}
});
// 发票类型选择
$('.invoice-type span').on('touchstart', function() {
if ($(this).hasClass('on')) {
return;
} else {
$(this).addClass('on').siblings().removeClass('on');
$editFlag.val('true');
// 纸质发票不显示手机号
if ($(this).index() === 1) {
$telArea.slideUp();
} else {
$telArea.slideDown();
}
}
});
// 发票须知
$('.invoice-btn').on('touchstart', function() {
$invoiceNotice.fadeIn();
return false;
});
// 关闭发票须知弹框
$('.think-ok, .mask-bg').on('touchstart', function() {
$invoiceNotice.fadeOut();
});
// 电话清空
$('.istel').one('input', function() {
$(this).val('').removeClass('istel');
});
$tel.on('input', function() {
$(this).attr('data-tel', $(this).val());
$editFlag.val('true');
isModifyTel = true;
});
$company.on('input', function() {
$editFlag.val('true');
});
// 确认及返回事件
$('.confirm-btn, .nav-back').on('touchstart', function(e) {
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_SC_INVOICE_INFO_SAVE',
param: JSON.stringify({
C_ID: C_ID,
INVOICE_TYPE: $invoiceType.find('.on').data('id'),
INVOICE_TITLE: $('.invoice-top').find('.on').text(),
INVOICE_CONTENT: $chooseCont.data('id')
})
}, true);
}
}, 200);
e.preventDefault();
confirmAction();
});
// initData();