import React, { useState } from 'react'; import { Form, Input, notification } from 'antd'; import SiteModal from '@/components/Modal/SiteModa'; import { addStation } from '@/services/userCenter/siteManage/api'; const { Item } = Form; const AddModal = props => { const [form] = Form.useForm(); const [formLayout, setFormLayout] = useState('horizontal'); const [loading, setLoading] = useState(false); const { confirmModal } = props; const onSubmit = () => { form .validateFields() .then(res => { console.log(res, 'res'); setLoading(true); addStation({ stationName: res.stationName, description: res.description, _version: 9999, _dc: new Date().getTime(), }) .then(res => { setLoading(false); if (res.success) { form.resetFields(); notification.success({ message: '通知', duration: 3, description: '新增成功', }); confirmModal(); } else { notification.error({ message: '提示', duration: 3, description: res.message, }); } }) .catch(err => { setLoading(false); notification.error({ message: '提示', duration: 3, description: err, }); }); }) .catch(err => { console.error(err); }); }; const onFinish = value => {}; return ( <SiteModal {...props} title="新增角色" bodyStyle={{ width: '100%', minHeight: '100px' }} style={{ top: 200, borderRadius: '20px' }} width="600px" destroyOnClose cancelText="取消" okText="确认选择" onOk={() => onSubmit()} confirmLoading={loading} > <Form form={form} layout={formLayout} onFinish={onFinish} labelCol={{ span: 4 }} > <Item label="角色名称" name="stationName" rules={[ { required: true, message: '请输入角色名称', }, ]} > <Input placeholder="请输入角色名称" /> </Item> <Item label="角色类别">all</Item> <Item label="角色描述" name="description"> <Input placeholder="请输入角色描述" /> </Item> </Form> </SiteModal> ); }; export default AddModal;