CreateModal.tsx
1.67 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
import React, { useEffect, useState } from "react";
import { Modal, Form, Input, message } from "antd";
import { WorkTypeListVO, saveWorkType } from "../api";
interface Props {
visible: boolean;
onCancel: () => void;
onRefreshing: () => void;
item: WorkTypeListVO;
}
export default function CreateModal({
visible,
onCancel,
item,
onRefreshing,
}: Props) {
const [form] = Form.useForm();
const [saveLoading, setSaveLoading] = useState(false);
useEffect(() => {
if (visible) {
form.setFieldsValue({
...item,
});
}
}, [visible]);
function handleSave(feildValue: any) {
setSaveLoading(true);
const params = {
...feildValue,
id: item.id,
name: (feildValue.name || "").trim(),
};
setSaveLoading(false);
saveWorkType(params)
.then((res) => {
message.success("保存成功!");
onCancel && onCancel();
})
.catch((e) => {
message.error(e.message);
})
.finally(() => setSaveLoading(false));
}
return (
<Modal
visible={visible}
onCancel={onCancel}
onOk={form.submit}
title={`${item.name ? "编辑" : "新增"}工作类型`}
confirmLoading={saveLoading}
maskClosable={false}
afterClose={() => {
form.resetFields();
}}
>
<Form
form={form}
onFinish={handleSave}
wrapperCol={{ span: 18 }}
labelCol={{ span: 6 }}
>
<Form.Item
label="工作类型名称"
name="name"
rules={[{ required: true }]}
>
<Input placeholder="请输入工作类型名称" />
</Form.Item>
</Form>
</Modal>
);
}