AddModal.jsx 3.03 KB
Newer Older
1 2
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Select, AutoComplete, Button, notification } from 'antd';
3
import { SetServiceConfig } 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();
17 18 19 20
        SetServiceConfig({
          schemename: obj.schemename,
          terminalType: type === 'add' ? 'web' : 'phone',
          isBaseMap: 'false',
21 22 23 24
          jsonCfg:
            type === 'add'
              ? JSON.stringify({ type: 'dynamic' })
              : JSON.stringify({ isDefault: false }),
25 26 27
        })
          .then(res => {
            setLoading(false);
28
            if (res.code == '0') {
29 30 31 32 33 34 35 36
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '新增成功',
              });
            } else {
37 38 39
              notification.error({
                message: '提示',
                duration: 3,
40
                description: '新增失败',
41
              });
42 43 44 45 46 47 48
            }
          })
          .catch(err => {
            notification.error({
              message: '提示',
              duration: 3,
              description: '新增失败',
49
            });
50 51
            setLoading(false);
          });
52 53 54 55
      }
    });
  };

56
  const onFinish = value => {};
57
  useEffect(() => {
58
    if (type != '') {
59 60
      form.setFieldsValue({ schemename: listData[0] });
    }
61 62 63 64 65
  }, [visible]);

  const layout = {
    layout: 'horizontal',
    labelCol: {
66
      span: 3,
67 68
    },
    wrapperCol: {
69
      span: 20,
70 71 72
    },
  };

73 74 75
  const handleChange = value => {
    form.setFieldsValue({ schemename: value });
  };
76

77 78 79
  return (
    <Modal
      title={`${type === 'add' ? '元数据发布' : '编辑'}`}
80
      bodyStyle={{ width: '100%' }}
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
      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
96 97
            label="方案名"
            name="schemename"
98 99
            rules={[{ required: true, message: '请选择服务名' }]}
          >
100
            <Select onChange={handleChange}>
101 102 103 104 105 106 107
              {listData.map((item, index) => {
                return (
                  <Option value={item} key={index}>
                    {item}
                  </Option>
                );
              })}
108
            </Select>
109 110 111 112 113 114 115
          </Item>
        </Form>
      )}
    </Modal>
  );
};
export default AddModal;