invoice.js
2.43 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
import Yas from '../../../common/yas';
let yas;
Page({
data: {
invocesType: 2
},
onLoad(options) {
if (!options.skey) {
return;
}
this.tryToDo(() => {
let invoice = wx.getStorageSync(options.skey) || {};
this.setData(invoice);
this.defaultReceiver = invoice.receiver;
});
this.tryToDo(() => {
wx.removeStorage({key: options.skey});
});
yas = new Yas();
yas.pageOpenReport();
},
tryToDo(fn) {
try {
fn();
} catch (e) {
console.log(JSON.stringify(e));
}
},
validateInvoceInfo() {
const info = this.data || {};
const receiver = this.defaultReceiver;
let isPass = true;
if (info.invoiceCompany && (!info.invoiceTitle || !info.taxNumber)) {
isPass = false;
}
if (isPass && info.invocesType * 1 === 2) {
if (!info.receiver) {
isPass = false;
} else if (info.receiver !== receiver && !/^[0-9]{11,18}$/.test(info.receiver)) {
isPass = false;
}
}
if (isPass !== this.data.canSubmit) {
this.setData({canSubmit: isPass});
}
return isPass;
},
showInvoceNotice() {
wx.showModal({
title: '发票须知',
content: '1、发票金额不含优惠券/有货币/红包/优惠券/优惠码/运费,只包含商品实付金额;\r\n2、电子发票是税务局认可的、有效的收付款凭证,其法律效力、基本用途及使用规则同纸质发票,如需纸质发票可自行下载打印;', // eslint-disable-line
confirmText: '我知道了',
showCancel: false
});
},
changeTitleType(e) {
let isCompany = e.currentTarget.dataset.type === 'company';
if (isCompany !== this.data.invoiceCompany) {
this.setData({invoiceCompany: isCompany});
this.validateInvoceInfo();
}
},
changeTitle(e) {
this.data.invoiceTitle = e.detail.value;
this.validateInvoceInfo();
},
changeTaxNumber(e) {
this.data.taxNumber = e.detail.value;
this.validateInvoceInfo();
},
changeReceiver(e) {
this.data.receiver = e.detail.value;
this.validateInvoceInfo();
},
invoiceSubmit() {
if (!this.validateInvoceInfo()) {
return;
}
let currentPages = getCurrentPages();
if (currentPages.length > 1 && currentPages[currentPages.length - 2].changeInvoiceCallback) {
currentPages[currentPages.length - 2].changeInvoiceCallback(this.data);
}
wx.navigateBack({delta: 1});
}
});