InvoiceDetailTable.tsx
4.09 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
import InvoiceDetailImportModal from '@/pages/Invoice/components/InvoiceDetailImportModal';
import { InvoiceProjectSelect } from '@/pages/Invoice/components/InvoiceProjectSelect';
import {
ActionType,
EditableProTable,
ProColumns,
} from '@ant-design/pro-components';
import { useEffect, useRef, useState } from 'react';
export default ({ recordId, details, updateDetails, readOnly }) => {
const [editableKeys, setEditableRowKeys] = useState([]);
const [invoiceProject, setInvoiceProject] = useState({});
const ref = useRef<ActionType>();
useEffect(() => {
updateDetails(details);
}, []);
useEffect(() => {
setEditableRowKeys(details?.map((item) => item.tid));
}, [details]);
const columns: ProColumns[] = [
{
title: '项目名称',
dataIndex: 'projectName',
width: 200,
ellipsis: true,
readonly: readOnly,
renderFormItem: () => {
return (
<InvoiceProjectSelect
setInvoiceProject={setInvoiceProject}
readOnly={readOnly}
/>
);
},
},
{
title: '规格型号',
readonly: readOnly,
dataIndex: 'specification',
valueType: 'text',
ellipsis: true,
},
{
title: '单位',
readonly: readOnly,
dataIndex: 'unit',
valueType: 'text',
ellipsis: true,
},
{
title: '数量',
readonly: readOnly,
dataIndex: 'quantity',
valueType: 'digit',
ellipsis: true,
},
{
title: '单价',
readonly: readOnly,
dataIndex: 'price',
valueType: 'digit',
ellipsis: true,
},
{
title: '金额',
readonly: readOnly,
dataIndex: 'totalPrice',
valueType: 'digit',
ellipsis: true,
},
{
title: '税率/征收率',
readonly: true,
dataIndex: 'taxRate',
valueType: () => ({
type: 'percent',
}),
ellipsis: true,
},
{
title: '税额',
readonly: true,
dataIndex: 'taxPrice',
valueType: 'digit',
ellipsis: true,
},
{
title: '操作',
valueType: 'option',
width: 250,
render: () => {
return null;
},
},
];
return (
<>
<EditableProTable
columns={columns}
actionRef={ref}
rowKey="tid"
scroll={{
x: 960,
}}
value={details}
controlled={true}
recordCreatorProps={
readOnly
? false
: {
newRecordType: 'dataSource',
record: () => ({
tid: Date.now(),
}),
}
}
toolBarRender={() => {
return [
<InvoiceDetailImportModal key={'import'} recordId={recordId} />,
];
}}
editable={{
type: 'multiple',
editableKeys,
actionRender: (row, config, defaultDoms) => {
return [defaultDoms.delete];
},
onValuesChange: (record, recordList) => {
//修改recordList中tid为record.tid的元素,将它的specification属性设置为invoiceProject的specification属性
const records = recordList.map((item) => {
if (record && item.tid === record.tid) {
item.projectName =
'*' +
invoiceProject.productAndServiceCatagoryAbbreviation +
'*' +
invoiceProject?.name;
item.specification = invoiceProject?.specification;
item.unit = invoiceProject?.unit;
item.taxRate = invoiceProject?.taxRate * 100;
}
return item;
});
updateDetails(records);
},
}}
/>
{/*<ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
<ProFormField
ignoreFormItem
fieldProps={{
style: {
width: '100%',
},
}}
mode="read"
valueType="jsonCode"
text={JSON.stringify(details)}
/>
</ProCard>*/}
</>
);
};