凌世锦
authored
|
1
|
import {
|
凌世锦
authored
|
2
3
4
5
6
7
8
9
10
11
12
13
|
postOrderErpOrderStagesPayWaySaveOrUpdate,
postOrderErpOrderStagesSaveOrUpdate,
postOrderErpOrderStagesSearch,
postOrderErpOrderStagesUpload,
} from '@/services';
import {
ModalForm,
ProCard,
ProForm,
ProFormDatePicker,
ProFormText,
ProFormTextArea,
|
凌世锦
authored
|
14
|
} from '@ant-design/pro-components';
|
凌世锦
authored
|
15
|
import { Form, message } from 'antd';
|
凌世锦
authored
|
16
|
import { RcFile } from 'antd/es/upload';
|
凌世锦
authored
|
17
18
19
|
import { useEffect, useState } from 'react';
import PayWayDetail from './readPayWay';
import ProductDetail from './readProduct';
|
凌世锦
authored
|
20
21
|
const waitTime = (time: number = 100) => {
|
凌世锦
authored
|
22
23
24
25
26
|
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
|
凌世锦
authored
|
27
28
29
|
};
export default ({ currentContract }) => {
|
凌世锦
authored
|
30
31
32
33
34
35
|
const [form] = Form.useForm<{ name: string; company: string }>();
const [contextBody, setContextBody] = useState({});
const [, setEditProductBody] = useState([]);
const [total, setTotal] = useState(0);
const [payWayBody, setPayWayBody] = useState([]);
const [otherBody, setOtherBody] = useState([]);
|
凌世锦
authored
|
36
|
|
凌世锦
authored
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
type OrderStagesWithListItem = {
//文件编号
id: number;
//合同编号
contract: string;
//供应商名称
vendor: string;
//签合同日期
dateRange: Date;
//终端名称
terminal: string;
orderStagesDeviceVoList: orderStagesDevice[];
//合同总金额
totalPrice: number;
//付款方式
payWay: string;
//附件
annex: string;
//备注
remark: string;
};
|
凌世锦
authored
|
58
|
|
凌世锦
authored
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
type orderStagesDevice = {
//设备id
dId: number;
//设备名称
deviceName: string;
//设备型号
deviceModel: string;
//数量
count: number;
//单价
unitPrice: number;
//总价
price: number;
};
|
凌世锦
authored
|
73
|
|
凌世锦
authored
|
74
75
76
77
|
async function refresh() {
const res = await postOrderErpOrderStagesSearch({
data: { contract: currentContract },
});
|
凌世锦
authored
|
78
|
const context = res?.data?.data[0];
|
凌世锦
authored
|
79
|
|
凌世锦
authored
|
80
|
if (context?.contract !== null) {
|
凌世锦
authored
|
81
|
setContextBody(context);
|
凌世锦
authored
|
82
83
|
setTotal(context?.totalPrice);
form.setFieldValue('totalPrice', context?.totalPrice);
|
凌世锦
authored
|
84
|
}
|
凌世锦
authored
|
85
|
}
|
凌世锦
authored
|
86
|
|
凌世锦
authored
|
87
88
89
|
function setSave(value) {
setOtherBody(value);
}
|
凌世锦
authored
|
90
|
|
凌世锦
authored
|
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
|
useEffect(() => {
setContextBody({ ...contextBody, totalPrice: total });
form.setFieldValue('totalPrice', total);
}, [total]);
const handleInputChange = (value: string, no: number, priceNow?: number) => {
let totalPay = 0;
const payValue: string[] = value.split('/');
let body:
| ((prevState: never[]) => never[])
| { proportion: string; payPrice: number }[] = [];
if (no === 1) {
if (payValue.length !== 4) {
message.warning('比例个数总和不为4个!');
} else {
payValue.forEach((item) => {
totalPay += Number(item);
});
}
if (totalPay !== 100) {
message.warning('比例总和不为100!');
} else {
message.success('输入有效!');
const price = total;
payValue.forEach((item) => {
body.push({
proportion: item + '%',
payPrice: (Number(item) * price) / 100,
});
});
setPayWayBody(body);
}
} else {
payValue.forEach((item) => {
totalPay += Number(item);
});
payValue.forEach((item) => {
body.push({
proportion: item + '%',
payPrice: (Number(item) * priceNow) / 100,
});
});
setPayWayBody(body);
|
凌世锦
authored
|
134
|
}
|
凌世锦
authored
|
135
|
};
|
凌世锦
authored
|
136
|
|
凌世锦
authored
|
137
138
139
140
|
async function getBody() {
const res = await postOrderErpOrderStagesSearch({
data: { contract: currentContract },
});
|
凌世锦
authored
|
141
|
const context = res.data.data[0];
|
凌世锦
authored
|
142
|
|
凌世锦
authored
|
143
|
if (context?.contract !== null) {
|
凌世锦
authored
|
144
|
setContextBody(context);
|
凌世锦
authored
|
145
146
|
setTotal(context?.totalPrice);
form.setFieldValue('totalPrice', context?.totalPrice);
|
凌世锦
authored
|
147
|
}
|
凌世锦
authored
|
148
|
handleInputChange(context?.payWay, 0, context?.totalPrice);
|
凌世锦
authored
|
149
|
}
|
凌世锦
authored
|
150
|
|
凌世锦
authored
|
151
152
153
|
useEffect(() => {
getBody();
}, []);
|
凌世锦
authored
|
154
|
|
凌世锦
authored
|
155
156
157
158
159
160
161
162
|
function getEditProductBody(value) {
setEditProductBody(value);
let price = 0;
value.map((obj) => (price += obj.count * obj.unitPrice));
setTotal(price);
setContextBody({ ...contextBody, orderStagesDeviceVoList: value });
handleInputChange(contextBody.payWay, 0, price);
}
|
凌世锦
authored
|
163
|
|
凌世锦
authored
|
164
165
|
return (
<ModalForm<OrderStagesWithListItem>
|
凌世锦
authored
|
166
|
title="查看"
|
凌世锦
authored
|
167
168
169
170
171
172
|
trigger={<a onClick={refresh}>查看</a>}
form={form}
autoFocusFirstInput
modalProps={{
destroyOnClose: true,
}}
|
凌世锦
authored
|
173
174
175
176
177
178
179
180
|
submitter={{
resetButtonProps: {},
submitButtonProps: {
style: {
display: 'none',
},
},
}}
|
凌世锦
authored
|
181
182
183
184
185
|
submitTimeout={2000}
onFinish={async (values) => {
let remakeValue = [];
// 创建一个用于存储所有异步操作的Promise数组
const promises = [];
|
凌世锦
authored
|
186
|
|
凌世锦
authored
|
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
|
otherBody.forEach((item) => {
let remakeItem = {
ossId: item.ossId,
number: item.id,
dataRange: item.payDate,
fileName: item.fileName,
};
if (
typeof item.fileUrl === 'object' &&
item.fileUrl instanceof File
) {
const formData = new FormData();
formData.append('file', item.fileUrl as RcFile);
const uploadPromise = async () => {
const res = await postOrderErpOrderStagesUpload({
data: formData,
headers: {
'Content-Type':
'multipart/form-data; boundary=----WebKitFormBoundarynl6gT1BKdPWIejNq',
},
});
if (res.data) {
remakeItem.fileUrl = res.data;
}
};
promises.push(uploadPromise());
}
remakeValue.push(remakeItem);
});
|
凌世锦
authored
|
216
|
|
凌世锦
authored
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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
|
// 使用Promise.all等待所有异步操作完成后再执行保存操作
Promise.all(promises).then(async () => {
await postOrderErpOrderStagesPayWaySaveOrUpdate({
data: remakeValue,
});
});
const formData = new FormData();
// let toSendEdit={...values,orderStagesDeviceVoList:contextBody.orderStagesDeviceVoList};
let toSendEdit = {
id: values.id || contextBody.id,
contract: values.contract || contextBody.contract,
vendor: values.vendor || contextBody.vendor,
dateRange: values.dateRange || contextBody.dateRange,
terminal: values.terminal || contextBody.terminal,
orderStagesDeviceDoList:
values.orderStagesDeviceVoList ||
contextBody.orderStagesDeviceVoList,
totalPrice: values.totalPrice || contextBody.totalPrice,
payWay: values.payWay || contextBody.payWay,
annex: contextBody.annex,
remark: values.remark || contextBody.remark,
};
if (values.annex) {
formData.append('file', values.annex[0].originFileObj as RcFile);
const res = await postOrderErpOrderStagesUpload({
data: formData,
headers: {
'Content-Type':
'multipart/form-data; boundary=----WebKitFormBoundarynl6gT1BKdPWIejNq',
},
});
if (res.data) {
toSendEdit.annex = res.data;
}
}
const isSaveOrUpdate = await postOrderErpOrderStagesSaveOrUpdate({
data: { ...toSendEdit },
});
if (isSaveOrUpdate) {
getBody();
}
await waitTime(2000);
message.success('提交成功');
return true;
}}
>
<ProCard title="基本信息" headerBordered bordered>
<ProForm.Group>
<ProFormText
width="md"
name="vendor"
label="供应商名称"
placeholder="请输入"
|
凌世锦
authored
|
270
|
initialValue={contextBody?.vendor}
|
凌世锦
authored
|
271
272
|
readonly
/>
|
凌世锦
authored
|
273
|
|
凌世锦
authored
|
274
275
276
277
278
|
<ProFormText
width="md"
name="terminal"
label="终端名称"
placeholder="请输入"
|
凌世锦
authored
|
279
|
initialValue={contextBody?.terminal}
|
凌世锦
authored
|
280
281
|
readonly
/>
|
凌世锦
authored
|
282
|
|
凌世锦
authored
|
283
284
285
286
287
288
289
290
|
<ProFormDatePicker
name="dateRange"
width="md"
label="签合同日期"
placeholder="请选择日期"
fieldProps={{
format: (value) => value.format('YYYY-MM-DD'),
}}
|
凌世锦
authored
|
291
|
initialValue={contextBody?.dateRange}
|
凌世锦
authored
|
292
293
|
readonly
/>
|
凌世锦
authored
|
294
|
|
凌世锦
authored
|
295
296
297
298
299
|
<ProFormText
width="md"
name="payWay"
label="付款比例"
placeholder="请输入"
|
凌世锦
authored
|
300
|
initialValue={contextBody?.payWay}
|
凌世锦
authored
|
301
302
303
304
305
|
readonly
onBlur={(e) => {
handleInputChange(e.target.value, 1);
}}
/>
|
凌世锦
authored
|
306
|
|
凌世锦
authored
|
307
308
309
310
311
|
<ProFormText
width="md"
name="contract"
label="合同编号"
placeholder="请输入"
|
凌世锦
authored
|
312
|
initialValue={contextBody?.contract}
|
凌世锦
authored
|
313
314
|
readonly
/>
|
凌世锦
authored
|
315
|
|
凌世锦
authored
|
316
|
{/* <ProFormText
|
凌世锦
authored
|
317
318
319
320
321
322
323
324
|
width="md"
name="annex"
label="合同附件"
placeholder="请输入"
initialValue={contextBody.fileUrl}
readonly
/> */}
|
凌世锦
authored
|
325
326
327
328
329
330
331
332
333
|
<ProFormText
width="md"
name="totalPrice"
label="合同金额"
placeholder="请输入"
disabled
readonly
// rules={[{ required: true, message: '此项为必填项' }]}
// value={contextBody.totalPrice}
|
凌世锦
authored
|
334
|
initialValue={contextBody?.totalPrice}
|
凌世锦
authored
|
335
336
337
338
339
340
341
342
343
344
|
/>
</ProForm.Group>
</ProCard>
<ProCard
title="产品明细"
style={{ marginTop: 10 }}
headerBordered
bordered
>
<ProductDetail
|
凌世锦
authored
|
345
|
productBody={contextBody?.orderStagesDeviceVoList}
|
凌世锦
authored
|
346
347
348
|
EditProductBody={getEditProductBody}
></ProductDetail>
</ProCard>
|
凌世锦
authored
|
349
|
|
凌世锦
authored
|
350
351
352
353
354
355
356
357
|
<ProCard
title="付款信息"
style={{ marginTop: 10 }}
headerBordered
bordered
>
<PayWayDetail
payBody={payWayBody}
|
凌世锦
authored
|
358
|
thisId={contextBody?.id}
|
凌世锦
authored
|
359
360
361
|
currtSave={setSave}
></PayWayDetail>
</ProCard>
|
凌世锦
authored
|
362
|
|
凌世锦
authored
|
363
364
365
366
|
<ProCard style={{ marginTop: 10 }} headerBordered bordered>
<ProFormTextArea
label="备注"
name="remark"
|
凌世锦
authored
|
367
|
initialValue={contextBody?.remark}
|
凌世锦
authored
|
368
369
370
371
372
373
|
readonly
/>
</ProCard>
</ModalForm>
);
};
|