reSetPeopleModal.tsx
2.24 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
import {
postOrderErpTicketsUpdate,
postServiceOrderQuerySalesCode,
} from '@/services';
import { ModalForm, ProCard, ProFormSelect } from '@ant-design/pro-components';
import { Button, Form } from 'antd';
import { useEffect, useState } from 'react';
type Ticket = {
assignPeople?: string;
};
const waitTime = (time = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
export default ({ ids, toReload }) => {
const [form] = Form.useForm<Ticket>();
const [assignPeopleOptions, setAssignPeopleOptions] = useState([]);
useEffect(() => {
const fetchAssignPeopleOptions = async () => {
try {
const res = await postServiceOrderQuerySalesCode();
const options = res.data?.map((item) => ({
label: item.userName,
value: item.userName,
}));
setAssignPeopleOptions(options || []);
} catch (error) {
console.error('Failed to fetch assign people options:', error);
}
};
fetchAssignPeopleOptions();
}, []);
const reSet = async () => {
console.log(ids);
ids.forEach(async (id) => {
let requestBody = {
id: id,
assignPeople: form.getFieldValue('assignPeople'),
};
await postOrderErpTicketsUpdate({
data: { ...requestBody },
});
});
};
return (
<ModalForm
title="重新指派"
width={660}
form={form}
trigger={<Button type="primary">重新指派</Button>}
modalProps={{
okText: '确定',
cancelText: '取消',
destroyOnClose: true,
}}
onFinish={async () => {
reSet();
await waitTime(2000);
toReload();
return true;
}}
>
<ProCard split="horizontal" bordered>
<ProCard>
<ProCard.Group direction="column">
<Form.Item label="指派人员" name="assignPeople">
<ProFormSelect
name="assignPeople"
options={assignPeopleOptions}
placeholder="请选择指派人员"
rules={[{ required: true, message: '此项为必填项' }]}
/>
</Form.Item>
</ProCard.Group>
</ProCard>
</ProCard>
</ModalForm>
);
};