曾国涛
authored
10 months ago
1
2
import InvoiceDetailImportModal from '@/pages/Invoice/InvoiceRecord/components/InvoiceDetailImportModal';
import { InvoiceProjectSelect } from '@/pages/Invoice/InvoiceRecord/components/InvoiceProjectSelect';
曾国涛
authored
11 months ago
3
4
5
import {
ActionType,
EditableProTable,
曾国涛
authored
10 months ago
6
ProCard,
曾国涛
authored
11 months ago
7
ProColumns,
曾国涛
authored
10 months ago
8
ProFormField,
曾国涛
authored
11 months ago
9
10
} from '@ant-design/pro-components';
import { useEffect, useRef, useState } from 'react';
曾国涛
authored
12 months ago
11
曾国涛
authored
12 months ago
12
export default ({ recordId, details, updateDetails, readOnly }) => {
曾国涛
authored
12 months ago
13
const [editableKeys, setEditableRowKeys] = useState([]);
曾国涛
authored
11 months ago
14
const ref = useRef<ActionType>();
曾国涛
authored
12 months ago
15
16
17
18
19
20
21
22
23
24
25
useEffect(() => {
updateDetails(details);
}, []);
useEffect(() => {
setEditableRowKeys(details?.map((item) => item.tid));
}, [details]);
const columns: ProColumns[] = [
{
title: '项目名称',
dataIndex: 'projectName',
曾国涛
authored
11 months ago
26
width: 200,
曾国涛
authored
11 months ago
27
ellipsis: true,
曾国涛
authored
11 months ago
28
29
readonly: readOnly,
renderFormItem: () => {
曾国涛
authored
10 months ago
30
return <InvoiceProjectSelect readOnly={readOnly} />;
曾国涛
authored
11 months ago
31
},
曾国涛
authored
12 months ago
32
33
34
35
36
37
},
{
title: '规格型号',
readonly: readOnly,
dataIndex: 'specification',
valueType: 'text',
曾国涛
authored
11 months ago
38
ellipsis: true,
曾国涛
authored
12 months ago
39
40
41
42
43
44
},
{
title: '单位',
readonly: readOnly,
dataIndex: 'unit',
valueType: 'text',
曾国涛
authored
11 months ago
45
ellipsis: true,
曾国涛
authored
12 months ago
46
47
48
49
50
51
},
{
title: '数量',
readonly: readOnly,
dataIndex: 'quantity',
valueType: 'digit',
曾国涛
authored
11 months ago
52
ellipsis: true,
曾国涛
authored
12 months ago
53
54
55
56
57
58
},
{
title: '单价',
readonly: readOnly,
dataIndex: 'price',
valueType: 'digit',
曾国涛
authored
11 months ago
59
ellipsis: true,
曾国涛
authored
12 months ago
60
61
62
63
},
{
title: '金额',
readonly: readOnly,
曾国涛
authored
12 months ago
64
dataIndex: 'totalPrice',
曾国涛
authored
12 months ago
65
valueType: 'digit',
曾国涛
authored
11 months ago
66
ellipsis: true,
曾国涛
authored
12 months ago
67
68
69
},
{
title: '税率/征收率',
曾国涛
authored
11 months ago
70
readonly: true,
曾国涛
authored
12 months ago
71
72
73
74
dataIndex: 'taxRate',
valueType: () => ({
type: 'percent',
}),
曾国涛
authored
11 months ago
75
ellipsis: true,
曾国涛
authored
12 months ago
76
77
78
},
{
title: '税额',
曾国涛
authored
11 months ago
79
readonly: true,
曾国涛
authored
12 months ago
80
81
dataIndex: 'taxPrice',
valueType: 'digit',
曾国涛
authored
11 months ago
82
ellipsis: true,
曾国涛
authored
12 months ago
83
84
85
86
},
{
title: '操作',
valueType: 'option',
曾国涛
authored
11 months ago
87
width: 100,
曾国涛
authored
12 months ago
88
89
90
91
92
93
94
95
96
97
render: () => {
return null;
},
},
];
return (
<>
<EditableProTable
columns={columns}
曾国涛
authored
11 months ago
98
actionRef={ref}
曾国涛
authored
12 months ago
99
100
101
102
103
rowKey="tid"
scroll={{
x: 960,
}}
value={details}
曾国涛
authored
11 months ago
104
controlled={true}
曾国涛
authored
12 months ago
105
106
107
108
109
110
111
112
113
114
115
116
recordCreatorProps={
readOnly
? false
: {
newRecordType: 'dataSource',
record: () => ({
tid: Date.now(),
}),
}
}
toolBarRender={() => {
return [
曾国涛
authored
12 months ago
117
<InvoiceDetailImportModal key={'import'} recordId={recordId} />,
曾国涛
authored
12 months ago
118
119
120
121
122
123
124
125
126
127
];
}}
editable={{
type: 'multiple',
editableKeys,
actionRender: (row, config, defaultDoms) => {
return [defaultDoms.delete];
},
onValuesChange: (record, recordList) => {
曾国涛
authored
11 months ago
128
129
130
131
132
//修改recordList中tid为record.tid的元素,将它的specification属性设置为invoiceProject的specification属性
const records = recordList.map((item) => {
return item;
});
updateDetails(records);
曾国涛
authored
12 months ago
133
134
135
},
}}
/>
曾国涛
authored
10 months ago
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
<ProCard title="表格数据" headerBordered collapsible defaultCollapsed>
<ProFormField
ignoreFormItem
fieldProps={{
style: {
width: '100%',
},
}}
mode="read"
valueType="jsonCode"
text={JSON.stringify(details)}
/>
</ProCard>
}
曾国涛
authored
12 months ago
151
152
153
</>
);
};