|
1
|
import { postOrderErpOrderStagesPayWaySelect } from '@/services';
|
|
2
3
|
import type { ProColumns } from '@ant-design/pro-components';
import {
|
|
4
5
6
|
EditableProTable,
ProFormRadio,
ProFormUploadButton,
|
|
7
8
|
} from '@ant-design/pro-components';
import { message } from 'antd';
|
|
9
|
import React, { useEffect, useState } from 'react';
|
|
10
11
|
const waitTime = (time: number = 100) => {
|
|
12
13
14
15
16
|
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
|
|
17
18
19
|
};
type DataSourceType = {
|
|
20
21
22
23
24
25
26
27
|
id: number;
payStep?: string;
proportion?: string;
ossId?: number;
payPrice?: number;
payDate?: Date;
fileName?: string;
fileUrl?: string;
|
|
28
29
30
|
};
export default ({ payBody, thisId, currtSave }) => {
|
|
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
|
const defaultData: DataSourceType[] = [
{
id: 1,
payStep: '预付款',
proportion: undefined,
payPrice: undefined,
ossId: undefined,
payDate: undefined,
fileName: undefined,
fileUrl: undefined,
},
{
id: 2,
payStep: '发贷款',
proportion: undefined,
payPrice: undefined,
ossId: undefined,
payDate: undefined,
fileName: undefined,
fileUrl: undefined,
},
{
id: 3,
payStep: '验收款',
proportion: undefined,
payPrice: undefined,
ossId: undefined,
payDate: undefined,
fileName: undefined,
fileUrl: undefined,
},
{
id: 4,
payStep: '质保金',
proportion: undefined,
payPrice: undefined,
ossId: undefined,
payDate: undefined,
fileName: undefined,
fileUrl: undefined,
},
];
|
|
73
|
|
|
74
75
76
77
78
79
80
81
82
|
const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
const [position, setPosition] = useState<'top' | 'bottom' | 'hidden'>(
'hidden',
);
const [payWayDetailBody, setPayWayDetailBody] = useState<
readonly DataSourceType[]
>([...defaultData]);
const [isAccept] = useState(null);
// const [isCurrtSave, setIsCurrtSave] = useState(false);
|
|
83
|
|
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
async function getOther(value, arr) {
const res = await postOrderErpOrderStagesPayWaySelect({
data: { ossId: value },
});
if (res.data) {
const context = res.data;
const remake = arr.map((obj) => {
let currt = obj;
context.forEach((object) => {
if (object.number === obj.id) {
currt = {
...obj,
ossId: value,
payDate: object.dateRange,
fileName: object.fileName,
fileUrl: object.fileUrl,
};
return currt;
}
|
|
103
|
});
|
|
104
105
106
|
return currt;
});
setPayWayDetailBody(remake);
|
|
107
|
}
|
|
108
|
}
|
|
109
|
|
|
110
111
112
113
114
115
116
117
|
function setPayWay(value) {
const remakeData = payWayDetailBody.map((obj) => {
return {
...obj,
proportion: value[obj.id - 1]?.proportion,
payPrice: value[obj.id - 1]?.payPrice,
};
});
|
|
118
|
|
|
119
|
setPayWayDetailBody(remakeData);
|
|
120
|
|
|
121
122
|
if (thisId !== null) {
getOther(thisId, remakeData);
|
|
123
|
}
|
|
124
125
126
127
|
}
// useEffect(() => {
// getOther(thisId)
// }, [thisId])
|
|
128
|
|
|
129
130
131
|
useEffect(() => {
setPayWay(payBody);
}, [payBody]);
|
|
132
|
|
|
133
134
135
|
// function setCurrtSave(_value) {
// setIsCurrtSave(payWayDetailBody)
// }
|
|
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
|
const columns: ProColumns<DataSourceType>[] = [
{
title: '编号',
dataIndex: 'id',
hideInTable: true,
editable: false,
},
{
title: '付款信息',
dataIndex: 'payStep',
editable: false,
},
{
title: '付款比例',
dataIndex: 'proportion',
editable: false,
},
{
title: '付款金额',
dataIndex: 'payPrice',
editable: false,
},
{
title: '对应的订单',
dataIndex: 'ossId',
editable: false,
hideInTable: true,
},
{
title: '付款时间',
dataIndex: 'payDate',
editable: false,
render: (_text, record) => {
|
|
170
171
172
173
174
175
176
177
178
179
180
181
182
|
if (record.payDate) {
return (
<span>
{new Intl.DateTimeFormat('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(record.payDate)}
</span>
);
} else {
return <span></span>;
}
|
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
},
},
{
title: '付款单回执',
dataIndex: 'fileName',
render: (_text, record) => {
if (isAccept !== record.id) {
if (
typeof record.fileUrl === 'object' &&
record.fileUrl instanceof File
) {
return (
<a onClick={() => message.error('请先保存')}>{record.fileName}</a>
);
} else {
return <a href={record.fileUrl}>{record.fileName}</a>;
}
} else {
return (
<ProFormUploadButton
name={record.id}
onChange={(value) => {
let remakeBody = [];
let remakeBodyItem = {};
payWayDetailBody.forEach((item) => {
if (item.id === record.id) {
remakeBodyItem = {
...item,
fileUrl: value.file.originFileObj,
fileName: value.file.name,
};
} else {
remakeBodyItem = { ...item };
}
if (value.fileList.length === 0) {
remakeBodyItem = {
...item,
fileUrl: undefined,
fileName: undefined,
};
}
remakeBody.push(remakeBodyItem);
});
setPayWayDetailBody(remakeBody);
currtSave(remakeBody);
}}
width="md"
max={1}
/>
);
|
|
233
|
}
|
|
234
235
236
|
},
},
];
|
|
237
|
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
return (
<>
<EditableProTable<DataSourceType>
rowKey="id"
className="payway-detail-index"
toolbar={{ style: { display: 'none' } }}
ghost={true}
scroll={{
x: 960,
}}
recordCreatorProps={
position !== 'hidden'
? {
position: position as 'top',
record: () => ({ id: (Math.random() * 1000000).toFixed(0) }),
}
: false
}
loading={false}
toolBarRender={() => [
<ProFormRadio.Group
key="render"
fieldProps={{
value: position,
onChange: (e) => setPosition(e.target.value),
}}
/>,
]}
columns={columns}
request={payWayDetailBody}
value={payWayDetailBody}
onChange={(value) => {
setPayWayDetailBody(value);
// setCurrtSave(payWayDetailBody)
}}
editable={{
type: 'multiple',
editableKeys,
onSave: async () => {
await waitTime(2000);
},
onChange: setEditableRowKeys,
}}
/>
</>
);
};
|