Blame view

src/pages/backlog/WorkTypeConfig/components/CreateModal.tsx 1.67 KB
c6d883b3   赵凤   add 工作类型配置
1
  import React, { useEffect, useState } from "react";
c4a486ae   赵凤   待办配置add工作类型字段
2
3
  import { Modal, Form, Input, message } from "antd";
  import { WorkTypeListVO, saveWorkType } from "../api";
c6d883b3   赵凤   add 工作类型配置
4
5
6
7
8
  
  interface Props {
    visible: boolean;
    onCancel: () => void;
    onRefreshing: () => void;
c4a486ae   赵凤   待办配置add工作类型字段
9
    item: WorkTypeListVO;
c6d883b3   赵凤   add 工作类型配置
10
11
12
13
14
15
16
17
18
  }
  export default function CreateModal({
    visible,
    onCancel,
    item,
    onRefreshing,
  }: Props) {
    const [form] = Form.useForm();
    const [saveLoading, setSaveLoading] = useState(false);
c6d883b3   赵凤   add 工作类型配置
19
  
c4a486ae   赵凤   待办配置add工作类型字段
20
21
22
23
24
25
26
    useEffect(() => {
      if (visible) {
        form.setFieldsValue({
          ...item,
        });
      }
    }, [visible]);
c6d883b3   赵凤   add 工作类型配置
27
28
29
  
    function handleSave(feildValue: any) {
      setSaveLoading(true);
c6d883b3   赵凤   add 工作类型配置
30
31
      const params = {
        ...feildValue,
c4a486ae   赵凤   待办配置add工作类型字段
32
        id: item.id,
c6d883b3   赵凤   add 工作类型配置
33
34
        name: (feildValue.name || "").trim(),
      };
c6d883b3   赵凤   add 工作类型配置
35
  
c4a486ae   赵凤   待办配置add工作类型字段
36
      setSaveLoading(false);
c6d883b3   赵凤   add 工作类型配置
37
38
      saveWorkType(params)
        .then((res) => {
c4a486ae   赵凤   待办配置add工作类型字段
39
          message.success("保存成功!");
c6d883b3   赵凤   add 工作类型配置
40
41
42
43
          onCancel && onCancel();
        })
        .catch((e) => {
          message.error(e.message);
c4a486ae   赵凤   待办配置add工作类型字段
44
45
        })
        .finally(() => setSaveLoading(false));
c6d883b3   赵凤   add 工作类型配置
46
47
48
49
50
51
52
53
54
55
    }
  
    return (
      <Modal
        visible={visible}
        onCancel={onCancel}
        onOk={form.submit}
        title={`${item.name ? "编辑" : "新增"}工作类型`}
        confirmLoading={saveLoading}
        maskClosable={false}
c4a486ae   赵凤   待办配置add工作类型字段
56
57
58
        afterClose={() => {
          form.resetFields();
        }}
c6d883b3   赵凤   add 工作类型配置
59
60
61
62
63
64
65
66
      >
        <Form
          form={form}
          onFinish={handleSave}
          wrapperCol={{ span: 18 }}
          labelCol={{ span: 6 }}
        >
          <Form.Item
c6d883b3   赵凤   add 工作类型配置
67
68
69
70
71
72
73
74
75
76
            label="工作类型名称"
            name="name"
            rules={[{ required: true }]}
          >
            <Input placeholder="请输入工作类型名称" />
          </Form.Item>
        </Form>
      </Modal>
    );
  }