AccountModal.tsx
1.59 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
import React, { useEffect } from 'react';
import { Form, Button, Modal, Input } from 'antd';
const Item = Form.Item;
interface Props {
visible?: boolean,
onCancel: Function,
onOk: Function,
accounts: string[]
}
export default function Index(props: Props) {
const { visible, onCancel, onOk, accounts } = props;
const [form] = Form.useForm();
useEffect(() => {
if (!visible) {
form.resetFields();
}
}, [visible]);
const onSave = () => {
form.validateFields().then(files => {
onOk(files.account);
onCancel();
});
};
return (
<Modal
title="发单账号"
open={visible}
maskClosable={false}
onCancel={() => onCancel()}
footer={[
<Button onClick={() => onCancel()}>取消</Button>,
<Button type="primary" htmlType="submit" onClick={() => onSave()}>确定</Button>
]}
>
<Form
form={form}
labelCol={{ span: 5 }}
wrapperCol={{ span: 12 }}
>
<Item
label="发单账号"
name="account"
rules={[
{ required: true, message: "请填写发单账号" },
() => ({
validator(_, value) {
if (value.length != 11) {
return Promise.reject(new Error('发单账号不符合要求'));
} else if (accounts.includes(value)) {
return Promise.reject(new Error('发单账号重复'));
}
return Promise.resolve();
},
}),
]}
>
<Input />
</Item>
</Form>
</Modal>
);
}