AddModal.jsx 2.72 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-01-13 17:26:14
5
 * @LastEditTime: 2022-08-02 14:10:39
皮倩雯's avatar
皮倩雯 committed
6 7
 * @LastEditors: leizhe
 */
Maofei94's avatar
Maofei94 committed
8 9
import React, { useState } from 'react';
import { Form, Input, notification } from 'antd';
10
import SiteModal from '@/components/Modal/SiteModa';
邓超's avatar
邓超 committed
11
import { addStation } from '@/services/siteManage/api';
Maofei94's avatar
Maofei94 committed
12 13
const { Item } = Form;
const AddModal = props => {
14 15
  const [form] = Form.useForm();
  const [formLayout, setFormLayout] = useState('horizontal');
Maofei94's avatar
Maofei94 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
  const [loading, setLoading] = useState(false);
  const { confirmModal } = props;
  const onSubmit = () => {
    form
      .validateFields()
      .then(res => {
        console.log(res, 'res');
        setLoading(true);
        addStation({
          stationName: res.stationName,
          description: res.description,
        })
          .then(res => {
            setLoading(false);
30
            if (res.code === 0) {
Maofei94's avatar
Maofei94 committed
31 32 33 34 35 36 37 38 39 40 41
              form.resetFields();
              notification.success({
                message: '通知',
                duration: 3,
                description: '新增成功',
              });
              confirmModal();
            } else {
              notification.error({
                message: '提示',
                duration: 3,
42
                description: res.msg,
Maofei94's avatar
Maofei94 committed
43 44 45 46 47 48 49 50 51 52
              });
            }
          })
          .catch(err => {
            setLoading(false);
            notification.error({
              message: '提示',
              duration: 3,
              description: err,
            });
53
          });
Maofei94's avatar
Maofei94 committed
54 55 56 57 58 59 60 61 62 63 64 65 66
      })
      .catch(err => {
        console.error(err);
      });
  };

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

Maofei94's avatar
Maofei94 committed
100
export default AddModal;