AddModal.jsx 2.79 KB
Newer Older
1 2
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Select, AutoComplete, Button, notification } from 'antd';
3
import { SetServiceConfig, AddWebSchema } from '@/services/webConfig/api';
4 5 6

const { Option } = Select;
const AddModal = props => {
7
  const { callBackSubmit = () => {}, type, formObj, visible, listData } = props;
8 9 10 11 12 13 14 15 16
  const [loading, setLoading] = useState(false);
  const [form] = Form.useForm();
  const { Item } = Form;
  // 提交
  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
        setLoading(true);
        let obj = form.getFieldsValue();
shaoan123's avatar
shaoan123 committed
17
        AddWebSchema({
18
          schemename: obj.schemename,
19 20 21
        })
          .then(res => {
            setLoading(false);
22
            if (res.msg === '') {
23 24 25 26 27 28 29 30 31 32 33
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '新增成功',
              });
            } else {
              notification.error({
                message: '提示',
                duration: 3,
34
                description: res.msg,
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
              });
            }
          })
          .catch(err => {
            notification.error({
              message: '提示',
              duration: 3,
              description: '新增失败',
            });
            setLoading(false);
          });
      }
    });
  };

50
  const onFinish = value => {};
51
  useEffect(() => {
52
    if (type != '') {
53 54 55 56 57 58 59
      form.setFieldsValue({ schemename: listData[0] });
    }
  }, [visible]);

  const layout = {
    layout: 'horizontal',
    labelCol: {
60
      span: 3,
61 62
    },
    wrapperCol: {
63
      span: 20,
64 65 66
    },
  };

67 68 69
  const handleChange = value => {
    form.setFieldsValue({ schemename: value });
  };
70 71 72 73

  return (
    <Modal
      title={`${type === 'add' ? '元数据发布' : '编辑'}`}
74
      bodyStyle={{ width: '100%' }}
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
      style={{ top: '150px' }}
      width="700px"
      destroyOnClose
      maskClosable={false}
      cancelText="取消"
      okText="确认"
      {...props}
      onOk={() => onSubmit()}
      confirmLoading={loading}
      forceRender={true}
      getContainer={false}
    >
      {visible && (
        <Form form={form} {...layout} onFinish={onFinish}>
          <Item
            label="方案名"
            name="schemename"
            rules={[{ required: true, message: '请选择服务名' }]}
          >
            <Select onChange={handleChange}>
95 96 97 98 99 100 101
              {listData.map((item, index) => {
                return (
                  <Option value={item} key={index}>
                    {item}
                  </Option>
                );
              })}
102 103 104 105 106 107 108 109
            </Select>
          </Item>
        </Form>
      )}
    </Modal>
  );
};
export default AddModal;