EditModal.jsx 3.2 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4 5
/* eslint-disable indent */
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-04-07 10:23:26
6
 * @LastEditTime: 2022-04-15 14:44:54
皮倩雯's avatar
皮倩雯 committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * @LastEditors: leizhe
 */
import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, notification, message, Select } from 'antd';
import { list, Edit } from '@/services/ModelFileManage/api';

const { Option } = Select;

const EditModal = props => {
  const { visible, onCancel, pickItem, callBackSubmit = () => {} } = props;
  const [addForm] = Form.useForm();
  const [value, setValue] = useState('');
  const [select, setSelect] = useState('');

  useEffect(() => {
    console.log(pickItem);
    addForm.setFieldsValue({ name: pickItem.name });
    addForm.setFieldsValue({ type: pickItem.typeID });
    list({ _site: '' }).then(res => {
      console.log(res.getMe);
      setValue(res.getMe);
    });
  }, [visible]);

  const submitEdit = () => {
    console.log(addForm.getFieldValue('name'));
    console.log(addForm.getFieldValue('type'));
34
    if (addForm.getFieldValue('name') && addForm.getFieldValue('type')) {
皮倩雯's avatar
皮倩雯 committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      Edit({
        id: pickItem.id,
        Name: addForm.getFieldValue('name'),
        TypeId: addForm.getFieldValue('type'),
      })
        .then(res => {
          if (res.statusCode === '0000') {
            onCancel();
            callBackSubmit();
            notification.success({
              message: '提交成功',
              duration: 2,
              description: res.info,
            });
            // 重新获取机构树与用户表
          } else {
            notification.error({
              message: '提交失败',
              description: res.errMsg,
            });
          }
        })
        .catch(err => {
          message.error(err);
        });
60
    } else if (!addForm.getFieldValue('name')) {
皮倩雯's avatar
皮倩雯 committed
61
      notification.warning({
62 63 64 65 66 67
        message: '画板名称不能为空',
        duration: 2,
      });
    } else if (!addForm.getFieldValue('type')) {
      notification.warning({
        message: '画板类型不能为空',
皮倩雯's avatar
皮倩雯 committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
        duration: 2,
      });
    }
  };

  const changValue = e => {
    console.log(e);
    setSelect(e);
  };
  return (
    <Modal
      title="编辑画板"
      visible={visible}
      onCancel={onCancel}
      destroyOnClose
      onOk={submitEdit}
      afterClose={() => {
        addForm.resetFields();
      }}
      maskClosable={false}
      okText="确认"
      cancelText="取消"
    >
      <Form form={addForm} labelCol={{ span: 6 }}>
        <Form.Item name="name" label="画板名称" rules={[{ required: true, message: '不能为空' }]}>
          <Input placeholder="请输入模板类型名称" maxLength="20" style={{ width: '330px' }} />
        </Form.Item>
        <Form.Item name="type" label="画板类型" rules={[{ required: true, message: '不能为空' }]}>
          <Select placeholder="选择画板类型" onChange={changValue} style={{ width: '330px' }}>
            {value
              ? value.map((item, index) => (
                  <Option key={item.id} value={item.id}>
                    {item.name}
                  </Option>
                ))
              : ''}
          </Select>
        </Form.Item>
      </Form>
    </Modal>
  );
};
export default EditModal;