QYF-GitLab1
2025-07-28 fe1ed567b817bfb3fe88156d1bbbce2cfa673bb3
1
2
3
4
5
6
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
34
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
60
61
62
63
64
65
66
67
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import {
  Button,
  Col,
  DatePicker,
  Divider,
  Form,
  Input,
  Modal,
  Row,
  Select,
} from "antd";
import React, { useEffect, useState } from "react";
import Staff from "./staff";
 
interface ApplyProps {
  visible: boolean;
  onCancel?: () => void;
  setFormData: (data: any) => void;
  applyType: string;
  title: string;
  formItems: any[];
}
 
const Apply: React.FC<ApplyProps> = (props) => {
  const { visible, setFormDat, onCancel, applyType, title, formItems } = props;
 
  const [staffVisible, setStaffVisible] = useState(false);
  const [form] = Form.useForm();
 
  const onFinish = (values: any) => {
    console.log(values);
    // setFormDat(values);
  };
 
  // 打开员工列表
  const onStaffVisible = () => {
    setStaffVisible(true);
  };
 
  // 设置选中员工
  const onSetStaff = (val: any) => {
    if (val) {
      form.setFieldsValue(val);
    }
    console.log(val);
  };
 
  useEffect(() => {
    if (visible) {
      setStaffVisible(false);
    }
  }, [visible]);
 
  // 关闭且重置表单
  const closeForm = () => {
    if (onCancel) {
      onCancel();
    }
    form.resetFields();
  };
 
  return (
    <Modal
      width={910}
      title={title + "申请"}
      open={visible}
      onCancel={closeForm}
      footer={null}
      className="ModelForm"
    >
      <Form
        name="basic"
        initialValues={{ remember: true }}
        style={{ paddingTop: 20 }}
        onFinish={onFinish}
        autoComplete="off"
        form={form}
      >
        <Row>
          {formItems?.length &&
            formItems.map((item, index) => {
              if (item.type === "input") {
                return (
                  <Col span={item.width > 300 ? 24 : 12} key={index}>
                    <Form.Item
                      labelCol={{ span: item.labelCol }}
                      label={item.label}
                      name={item.name}
                      rules={item.rules}
                    >
                      {item.name !== "name" && (
                        <Input
                          readOnly={item.readOnly}
                          style={{ width: item.width }}
                        />
                      )}
                      {item.name === "name" && (
                        <Input
                          readOnly={item.readOnly}
                          style={{ width: item.width }}
                          onClick={onStaffVisible}
                        />
                      )}
                    </Form.Item>
                  </Col>
                );
              } else if (item.type === "select") {
                return (
                  <Col span={12} key={index}>
                    <Form.Item
                      labelCol={{ span: item.labelCol }}
                      label={item.label}
                      name={item.name}
                      rules={item.rules}
                    >
                      <Select
                        options={item?.options}
                        style={{ width: item.width }}
                      />
                    </Form.Item>
                  </Col>
                );
              } else if (item.type === "textArea") {
                return (
                  <Col span={24} key={index}>
                    <Form.Item
                      labelCol={{ span: item.labelCol }}
                      label={item.label}
                      name={item.name}
                      rules={item.rules}
                    >
                      <Input.TextArea
                        style={{ width: item.width }}
                        showCount
                        maxLength={item?.maxLength || 100}
                      />
                    </Form.Item>
                  </Col>
                );
              } else if (item.type === "divider") {
                return (
                  <Col span={24} key={index}>
                    <Divider orientation="left" style={{ marginBottom: 20 }}>
                      {item.label}
                    </Divider>
                  </Col>
                );
              } else if (item.type === "date") {
                return (
                  <Col span={12} key={index}>
                    <Form.Item
                      labelCol={{ span: item.labelCol }}
                      label={item.label}
                      name={item.name}
                      rules={item.rules}
                    >
                      <DatePicker style={{ width: item.width }} />
                    </Form.Item>
                  </Col>
                );
              } else {
                return null;
              }
            })}
        </Row>
        <Form.Item label={null}>
          <div className="functionBtn">
            <Button type="primary" htmlType="submit">
              提交
            </Button>
            <Button onClick={closeForm}>关闭</Button>
            <Staff
              open={staffVisible}
              onCancel={() => setStaffVisible(false)}
              setData={onSetStaff}
            />
          </div>
        </Form.Item>
      </Form>
    </Modal>
  );
};
 
export default Apply;