ChildAccountModal.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Button, Form, Modal, Select } from 'antd';
  2. import { useState } from 'react';
  3. interface ChildAccountModalProps {
  4. visible: boolean;
  5. childAccountList: APIChildAccount.FetchChildAccountListResponse;
  6. onCancel: () => void;
  7. onConfirm: (id: number) => Promise<boolean>;
  8. }
  9. export default function (props: ChildAccountModalProps) {
  10. const [form] = Form.useForm();
  11. const [loading, setLoading] = useState<boolean>(false);
  12. return (
  13. <Modal title="选择子账号" open={props.visible} footer={null} destroyOnClose>
  14. <Form form={form} layout="vertical">
  15. <Form.Item
  16. label="请选择分配子账号"
  17. name="child_account"
  18. rules={[{ required: true, message: '子账号不可为空' }]}
  19. >
  20. <Select>
  21. {props.childAccountList.map((item) => {
  22. return (
  23. <Select.Option key={item.id} value={item.id}>
  24. {item.contractName}
  25. </Select.Option>
  26. );
  27. })}
  28. </Select>
  29. </Form.Item>
  30. <Button
  31. block
  32. type="primary"
  33. loading={loading}
  34. onClick={() => {
  35. form.validateFields().then(() => {
  36. setLoading(true);
  37. props
  38. .onConfirm(form.getFieldValue('child_account'))
  39. .then((success) => {
  40. setLoading(false);
  41. if (success) {
  42. props.onCancel();
  43. }
  44. })
  45. .catch(() => {
  46. props.onCancel();
  47. setLoading(false);
  48. });
  49. });
  50. }}
  51. >
  52. 确认
  53. </Button>
  54. </Form>
  55. </Modal>
  56. );
  57. }