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 ( { form.resetFields(); }} >
); }