AddChildModal.jsx 2.78 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 17:26:14
5
 * @LastEditTime: 2022-03-22 16:21:57
皮倩雯's avatar
皮倩雯 committed
6 7
 * @LastEditors: leizhe
 */
8 9 10
import React, { useState } from 'react';
import { Form, Input, notification } from 'antd';
import SiteModal from '@/components/Modal/SiteModa';
邓超's avatar
邓超 committed
11
import { addStation, addChildSiteNode } from '@/services/siteManage/api';
12 13
const { Item } = Form;
const AddChildModal = props => {
皮倩雯's avatar
皮倩雯 committed
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
  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);
        addChildSiteNode({
          pid: props.pid,
          nodeName: res.stationName,
          description: res.description,
        })
          .then(res => {
            setLoading(false);
            if (res.code === 0) {
              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,
53
            });
皮倩雯's avatar
皮倩雯 committed
54 55 56 57 58 59
          });
      })
      .catch(err => {
        console.error(err);
      });
  };
60

皮倩雯's avatar
皮倩雯 committed
61 62 63 64 65 66 67 68 69
  const onFinish = value => {};
  return (
    <SiteModal
      {...props}
      title="新增子站点"
      bodyStyle={{ width: '100%', minHeight: '100px' }}
      style={{ top: 200, borderRadius: '20px' }}
      width="600px"
      destroyOnClose
70 71 72
      afterClose={() => {
        form.resetFields();
      }}
皮倩雯's avatar
皮倩雯 committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      maskClosable={false}
      cancelText="取消"
      okText="确认"
      onOk={() => onSubmit()}
      confirmLoading={loading}
    >
      <Form form={form} layout={formLayout} onFinish={onFinish} labelCol={{ span: 4 }}>
        <Item
          label="站点名称"
          name="stationName"
          rules={[
            {
              required: true,
              message: '请输入站点名称',
            },
          ]}
89
        >
90
          <Input placeholder="请输入站点名称" style={{ width: '95%' }} maxLength="20" />
皮倩雯's avatar
皮倩雯 committed
91 92 93
        </Item>
        {/* <Item label="站点类别">all</Item> */}
        <Item label="站点描述" name="description">
94
          <Input placeholder="请输入站点描述" style={{ width: '95%' }} maxLength="100" />
皮倩雯's avatar
皮倩雯 committed
95 96 97 98
        </Item>
      </Form>
    </SiteModal>
  );
99 100 101
};

export default AddChildModal;