|
@@ -1,19 +1,337 @@
|
1
|
|
-import React from 'react';
|
2
|
|
-import { connect } from 'umi';
|
|
1
|
+import React, { useEffect, useState } from 'react';
|
|
2
|
+import { connect, history } from 'umi';
|
|
3
|
+
|
3
|
4
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
5
|
+import Container from '@/components/Container';
|
|
6
|
+import { Input, Form, Button, notification, Upload, message } from 'antd';
|
|
7
|
+import ProForm, {
|
|
8
|
+ ProFormText,
|
|
9
|
+ ProFormTextArea,
|
|
10
|
+ ProFormSelect,
|
|
11
|
+ ProFormDependency,
|
|
12
|
+} from '@ant-design/pro-form';
|
|
13
|
+import request from '@/utils/request';
|
|
14
|
+import School from '@/components/School';
|
|
15
|
+import UploadImage from '@/components/UploadImage';
|
|
16
|
+import { UploadOutlined } from '@ant-design/icons';
|
|
17
|
+import uploadFile from '@/utils/uploadFile';
|
|
18
|
+
|
|
19
|
+const { Search } = Input;
|
|
20
|
+const TestEdit = (props) => {
|
|
21
|
+ const { id, schoolId } = props.location.query;
|
|
22
|
+
|
|
23
|
+ const [searchLoading, setSearchLoading] = useState(false);
|
|
24
|
+ const [school, setSchool] = useState();
|
|
25
|
+ const [fileList, setFileList] = useState([]);
|
|
26
|
+
|
|
27
|
+ const [searchValue, setSearchValue] = useState();
|
|
28
|
+
|
|
29
|
+ const [form] = Form.useForm();
|
4
|
30
|
|
5
|
|
-const VisitList = () => {
|
|
31
|
+ // eslint-disable-next-line no-shadow
|
|
32
|
+ const getData = (id) => {
|
|
33
|
+ if (id) {
|
|
34
|
+ request(`/student-no/${id}`, { params: { schoolId: school } })
|
|
35
|
+ .then((res) => {
|
|
36
|
+ form.setFieldsValue(res);
|
|
37
|
+ setSearchLoading(false);
|
|
38
|
+ })
|
|
39
|
+ .catch((e) => {
|
|
40
|
+ setSearchLoading(false);
|
|
41
|
+ notification.error({ message: '未找到该学生' });
|
|
42
|
+ form.resetFields();
|
|
43
|
+ });
|
|
44
|
+ } else {
|
|
45
|
+ // this.setState({ data: [] });
|
|
46
|
+ }
|
|
47
|
+ };
|
6
|
48
|
|
|
49
|
+ useEffect(() => {
|
|
50
|
+ if (id) {
|
|
51
|
+ if (id) {
|
|
52
|
+ request(`/medical-log/${id}`)
|
|
53
|
+ .then((res) => {
|
|
54
|
+ form.setFieldsValue({ ...res });
|
|
55
|
+ setSearchLoading(false);
|
|
56
|
+ })
|
|
57
|
+ .catch((e) => {
|
|
58
|
+ setSearchLoading(false);
|
|
59
|
+ });
|
|
60
|
+ } else {
|
|
61
|
+ // this.setState({ data: [] });
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+ }, [id]);
|
7
|
65
|
|
8
|
|
-
|
|
66
|
+ const onSearch = (value) => {
|
|
67
|
+ if (value) {
|
|
68
|
+ getData(value);
|
|
69
|
+ setSearchLoading(true);
|
|
70
|
+ } else {
|
|
71
|
+ // this.setState({ data: [] });
|
|
72
|
+ }
|
|
73
|
+ };
|
|
74
|
+
|
|
75
|
+ const addTestLog = async (value) => {
|
|
76
|
+ await request('/taTestLog', { method: 'post', data: value })
|
|
77
|
+ .then(() => {
|
|
78
|
+ // notification.success({ message: '新建成功' });
|
|
79
|
+ // history.go('-1');
|
|
80
|
+ })
|
|
81
|
+ .catch((e) => {
|
|
82
|
+ notification.error({ message: e.message });
|
|
83
|
+ });
|
|
84
|
+ };
|
|
85
|
+
|
|
86
|
+ const handleSubmit = async (value) => {
|
|
87
|
+ console.log(value);
|
|
88
|
+ const { studentId, attchment } = value;
|
|
89
|
+ if (!studentId) {
|
|
90
|
+ message.error(`请选择学生`);
|
|
91
|
+ }
|
|
92
|
+ try {
|
|
93
|
+ if (attchment && attchment.fileList.length > 0) {
|
|
94
|
+ attchment.fileList.map((x) => {
|
|
95
|
+ addTestLog({ studentId, name: x.name, attchment: x.response });
|
|
96
|
+ return null;
|
|
97
|
+ });
|
|
98
|
+ notification.success({ message: '新建成功' });
|
|
99
|
+ history.go('-1');
|
|
100
|
+ }
|
|
101
|
+ } catch (error) {
|
|
102
|
+ notification.error({ message: '创建失败' });
|
|
103
|
+ }
|
|
104
|
+ };
|
|
105
|
+
|
|
106
|
+ const handleSchoolChange = (value) => {
|
|
107
|
+ setSchool(value);
|
|
108
|
+ setSearchValue('');
|
|
109
|
+ form.resetFields();
|
|
110
|
+ };
|
9
|
111
|
|
10
|
112
|
return (
|
11
|
|
- <PageContainer>
|
12
|
|
- 234
|
|
113
|
+ <PageContainer
|
|
114
|
+ header={{
|
|
115
|
+ extra: [
|
|
116
|
+ <Button key="1" onClick={() => history.go('-1')}>
|
|
117
|
+ 返回
|
|
118
|
+ </Button>,
|
|
119
|
+ ],
|
|
120
|
+ }}
|
|
121
|
+ >
|
|
122
|
+ <Container>
|
|
123
|
+ <ProForm form={form} submitter={!id} onFinish={handleSubmit}>
|
|
124
|
+ {!id && (
|
|
125
|
+ <ProForm.Group layout="inline">
|
|
126
|
+ <School
|
|
127
|
+ value={school}
|
|
128
|
+ onChange={handleSchoolChange}
|
|
129
|
+ style={{ width: 200, marginBottom: '20px' }}
|
|
130
|
+ allowClear
|
|
131
|
+ />
|
|
132
|
+ <Search
|
|
133
|
+ placeholder="请输入学号"
|
|
134
|
+ value={searchValue}
|
|
135
|
+ onChange={(e) => setSearchValue(e.value)}
|
|
136
|
+ loading={searchLoading}
|
|
137
|
+ style={{ width: 200, marginBottom: '20px' }}
|
|
138
|
+ onSearch={onSearch}
|
|
139
|
+ />
|
|
140
|
+ </ProForm.Group>
|
|
141
|
+ )}
|
|
142
|
+ <Form.Item name="studentId" noStyle />
|
|
143
|
+
|
|
144
|
+ <ProForm.Group layout="inline" title="就诊信息">
|
|
145
|
+ <ProFormText
|
|
146
|
+ label="姓名"
|
|
147
|
+ placeholder="输入名称"
|
|
148
|
+ name="name"
|
|
149
|
+ fieldProps={{ bordered: false, readOnly: true }}
|
|
150
|
+ // rules={[{ required: true, message: '请填写名称' }]}
|
|
151
|
+ />
|
|
152
|
+ <ProFormSelect
|
|
153
|
+ options={[
|
|
154
|
+ {
|
|
155
|
+ value: 1,
|
|
156
|
+ label: '男',
|
|
157
|
+ },
|
|
158
|
+ {
|
|
159
|
+ value: 2,
|
|
160
|
+ label: '女',
|
|
161
|
+ },
|
|
162
|
+ ]}
|
|
163
|
+ name="sex"
|
|
164
|
+ label="性别"
|
|
165
|
+ fieldProps={{ bordered: false, open: false, allowClear: false }}
|
|
166
|
+ // rules={[{ required: true, message: '请选择性别' }]}
|
|
167
|
+ />
|
|
168
|
+ <ProFormText
|
|
169
|
+ label="学号"
|
|
170
|
+ placeholder="输入学号"
|
|
171
|
+ name="studentNo"
|
|
172
|
+ fieldProps={{ bordered: false, readOnly: true }}
|
|
173
|
+ // rules={[{ required: true, message: '请填写学号' }]}
|
|
174
|
+ />
|
|
175
|
+ <ProFormText
|
|
176
|
+ label="联系方式"
|
|
177
|
+ placeholder="输入联系方式"
|
|
178
|
+ name="phone"
|
|
179
|
+ fieldProps={{ bordered: false, readOnly: true }}
|
|
180
|
+ // rules={[{ required: true, message: '请填写联系方式' }]}
|
|
181
|
+ />
|
|
182
|
+ </ProForm.Group>
|
|
183
|
+
|
|
184
|
+ <Form.Item
|
|
185
|
+ name="attchment"
|
|
186
|
+ label="体检报告"
|
|
187
|
+ placeholder="请选择体检报告"
|
|
188
|
+ extra="支持pdf文件"
|
|
189
|
+ // valuePropName="fileList"
|
|
190
|
+ rules={[{ required: true, message: '请上传体检报告' }]}
|
|
191
|
+ >
|
|
192
|
+ <Upload
|
|
193
|
+ accept=".pdf"
|
|
194
|
+ // listType="picture-card"
|
|
195
|
+ // className="avatar-uploader"
|
|
196
|
+ // showUploadList={false}
|
|
197
|
+ // fileList={fileList}
|
|
198
|
+ customRequest={uploadFile}
|
|
199
|
+ onChange={(info) => {
|
|
200
|
+ if (info.file.status !== 'uploading') {
|
|
201
|
+ console.log(info.file, info.fileList);
|
|
202
|
+ }
|
|
203
|
+ if (info.file.status === 'done') {
|
|
204
|
+ message.success(`${info.file.name} 上传成功`);
|
|
205
|
+ // setFileList([info.file])
|
|
206
|
+ } else if (info.file.status === 'error') {
|
|
207
|
+ message.error(`${info.file.name} 上传失败`);
|
|
208
|
+ }
|
|
209
|
+ }}
|
|
210
|
+ >
|
|
211
|
+ <Button icon={<UploadOutlined />}>点击上传</Button>
|
|
212
|
+ </Upload>
|
|
213
|
+ {/* <UploadImage /> */}
|
|
214
|
+ </Form.Item>
|
|
215
|
+
|
|
216
|
+ {/* <ProFormTextArea
|
|
217
|
+ label="诊断报告"
|
|
218
|
+ placeholder="输入诊断报告"
|
|
219
|
+ name="attchment"
|
|
220
|
+ fieldProps={{ readOnly: !!id, rows: 10 }}
|
|
221
|
+ rules={[{ required: true, message: '请填写诊断报告' }]}
|
|
222
|
+ style={{ width: '100%' }}
|
|
223
|
+ /> */}
|
|
224
|
+ </ProForm>
|
|
225
|
+ </Container>
|
|
226
|
+ {/* <Container>
|
|
227
|
+ <ProForm form={form} onFinish={handleSubmit}>
|
|
228
|
+ <ProFormText
|
|
229
|
+ label="姓名"
|
|
230
|
+ placeholder="输入姓名"
|
|
231
|
+ name="title"
|
|
232
|
+ rules={[{ required: true, message: '请填写姓名' }]}
|
|
233
|
+ />
|
|
234
|
+
|
|
235
|
+ <ProFormSelect
|
|
236
|
+ options={[
|
|
237
|
+ {
|
|
238
|
+ value: 1,
|
|
239
|
+ label: '男',
|
|
240
|
+ },
|
|
241
|
+ {
|
|
242
|
+ value: 2,
|
|
243
|
+ label: '女',
|
|
244
|
+ },
|
|
245
|
+ ]}
|
|
246
|
+ name="sex"
|
|
247
|
+ label="性别"
|
|
248
|
+ fieldProps={{ bordered: !id, open: id ? false : undefined }}
|
|
249
|
+ rules={[{ required: true, message: '请选择性别' }]}
|
|
250
|
+ />
|
|
251
|
+
|
|
252
|
+ <ProFormSelect
|
|
253
|
+ label="学校"
|
|
254
|
+ placeholder="请选择学校"
|
|
255
|
+ name="schoolId"
|
|
256
|
+ showSearch
|
|
257
|
+ request={async ({ keyWords }) => {
|
|
258
|
+ // if (keyWords) {
|
|
259
|
+ return request('/school', {
|
|
260
|
+ method: 'get',
|
|
261
|
+ params: { name: keyWords, pageNum: 1, pageSize: 1000 },
|
|
262
|
+ })
|
|
263
|
+ .then((res) => {
|
|
264
|
+ return res?.records?.map((x) => {
|
|
265
|
+ return { label: x.name, value: x.schoolId };
|
|
266
|
+ });
|
|
267
|
+ })
|
|
268
|
+ .catch((e) => {
|
|
269
|
+ notification.error({ message: e.message });
|
|
270
|
+ return Promise.reject(e.message);
|
|
271
|
+ });
|
|
272
|
+ // }
|
|
273
|
+ }}
|
|
274
|
+ />
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+ <ProFormDependency name={['schoolId']}>
|
|
278
|
+ {({ schoolId }) => {
|
|
279
|
+ return (
|
|
280
|
+ <ProFormSelect
|
|
281
|
+ label="专业"
|
|
282
|
+ placeholder="请选择专业"
|
|
283
|
+ name="specialtyId"
|
|
284
|
+ dependencies={['schoolId']}
|
|
285
|
+ showSearch
|
|
286
|
+ params={{ schoolId }}
|
|
287
|
+ disabled={!schoolId}
|
|
288
|
+ options={specialtyOptions}
|
|
289
|
+ request={async ({ keyWords, ...params }) => {
|
|
290
|
+ console.log({ params });
|
|
291
|
+ if (schoolId) {
|
|
292
|
+ return request('/specialty', {
|
|
293
|
+ method: 'get',
|
|
294
|
+ params: { name: keyWords, ...params, pageNum: 1, pageSize: 1000 },
|
|
295
|
+ })
|
|
296
|
+ .then((res) => {
|
|
297
|
+ return res?.records?.map((x) => {
|
|
298
|
+ return { label: x.name, value: x.specialtyId };
|
|
299
|
+ });
|
|
300
|
+ })
|
|
301
|
+ .catch((e) => {
|
|
302
|
+ notification.error({ message: e.message });
|
|
303
|
+ return Promise.reject(e.message);
|
|
304
|
+ });
|
|
305
|
+ }
|
|
306
|
+ }}
|
|
307
|
+ />
|
|
308
|
+ );
|
|
309
|
+ }}
|
|
310
|
+ </ProFormDependency>
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+ <ProFormText
|
|
314
|
+ label="学号"
|
|
315
|
+ placeholder="输入学号"
|
|
316
|
+ name="studentNo"
|
|
317
|
+ fieldProps={{ bordered: !id, readOnly: !!id }}
|
|
318
|
+ rules={[{ required: true, message: '请填写学号' }]}
|
|
319
|
+ />
|
|
320
|
+
|
|
321
|
+ <Form.Item
|
|
322
|
+ name="image"
|
|
323
|
+ label="体检报告"
|
|
324
|
+ placeholder="请选择体检报告"
|
|
325
|
+ extra="支持pdf文件"
|
|
326
|
+ rules={[{ required: true, message: '请上传体检报告' }]}
|
|
327
|
+ >
|
|
328
|
+ <UploadImage />
|
|
329
|
+ </Form.Item>
|
|
330
|
+ </ProForm>
|
|
331
|
+
|
|
332
|
+ </Container> */}
|
13
|
333
|
</PageContainer>
|
14
|
334
|
);
|
15
|
335
|
};
|
16
|
336
|
|
17
|
|
-export default connect((s) => ({
|
18
|
|
- typeList: s.post.typeList,
|
19
|
|
-}))(VisitList);
|
|
337
|
+export default TestEdit;
|