|
@@ -0,0 +1,173 @@
|
|
1
|
+import React, { useRef, useState } from 'react';
|
|
2
|
+import { PageContainer } from '@ant-design/pro-layout';
|
|
3
|
+import ProTable from '@ant-design/pro-table';
|
|
4
|
+import { Button, Modal, Input, notification } from 'antd';
|
|
5
|
+import { PlusOutlined } from '@ant-design/icons';
|
|
6
|
+import request, { queryTable } from '@/utils/request';
|
|
7
|
+import School from '@/components/School';
|
|
8
|
+
|
|
9
|
+export default () => {
|
|
10
|
+ const tableRef = useRef();
|
|
11
|
+ const [school, setSchool] = useState();
|
|
12
|
+ const [current, setCurrent] = useState();
|
|
13
|
+ const [inputVal, setInputVal] = useState([]);
|
|
14
|
+ const [show, setShow] = useState(false);
|
|
15
|
+
|
|
16
|
+ const queryFunc = (params, page, sort, filter) => {
|
|
17
|
+ if (!school.schoolId) {
|
|
18
|
+ return Promise.resolve({ data: [], success: true, total: 0 });
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ const newParams = { ...params, schoolId: school.schoolId };
|
|
22
|
+ return queryTable('/hospital')(newParams, page, sort, filter);
|
|
23
|
+ };
|
|
24
|
+
|
|
25
|
+ const handleEdit = (hospital) => {
|
|
26
|
+ setCurrent(hospital);
|
|
27
|
+ setInputVal(hospital.name);
|
|
28
|
+ setShow(true);
|
|
29
|
+ };
|
|
30
|
+
|
|
31
|
+ const handleAdd = () => {
|
|
32
|
+ setCurrent();
|
|
33
|
+ setInputVal();
|
|
34
|
+ setShow(true);
|
|
35
|
+ };
|
|
36
|
+
|
|
37
|
+ const changeStatus = (hospital) => {
|
|
38
|
+ // 0 变 1, 1 变 0
|
|
39
|
+ // eslint-disable-next-line no-bitwise
|
|
40
|
+ const status = hospital.status ^ 1;
|
|
41
|
+ const data = { ...hospital, status }
|
|
42
|
+
|
|
43
|
+ request(`/hospital/${hospital.hospitalId}`, {
|
|
44
|
+ method: 'put',
|
|
45
|
+ data,
|
|
46
|
+ })
|
|
47
|
+ .then(() => {
|
|
48
|
+ tableRef.current.reload();
|
|
49
|
+ notification.success({ message: '操作成功' });
|
|
50
|
+ })
|
|
51
|
+ .catch((e) => {
|
|
52
|
+ notification.error({ message: e.message });
|
|
53
|
+ });
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+ };
|
|
57
|
+
|
|
58
|
+ const renderFormItem = (item, config, form) => {
|
|
59
|
+ const handleSchoolChange = (schoolId, schoolInfo) => {
|
|
60
|
+ form.setFieldsValue({ schoolId });
|
|
61
|
+ form.submit();
|
|
62
|
+ setSchool(schoolInfo);
|
|
63
|
+ };
|
|
64
|
+
|
|
65
|
+ return <School onChange={handleSchoolChange} />;
|
|
66
|
+ };
|
|
67
|
+
|
|
68
|
+ const columns = [
|
|
69
|
+ {
|
|
70
|
+ title: '所属学校',
|
|
71
|
+ key: 'schoolId',
|
|
72
|
+ dataIndex: 'schoolId',
|
|
73
|
+ hideInTable: true,
|
|
74
|
+ valueType: 'select',
|
|
75
|
+ renderFormItem,
|
|
76
|
+ },
|
|
77
|
+ {
|
|
78
|
+ title: '诊室名称',
|
|
79
|
+ key: 'name',
|
|
80
|
+ dataIndex: 'name',
|
|
81
|
+ },
|
|
82
|
+ {
|
|
83
|
+ title: '状态',
|
|
84
|
+ key: 'status',
|
|
85
|
+ dataIndex: 'status',
|
|
86
|
+ valueEnum: {
|
|
87
|
+ 0: { text: '未启用', status: 'Default' },
|
|
88
|
+ 1: { text: '启用', status: 'Success' },
|
|
89
|
+ },
|
|
90
|
+ hideInSearch: true,
|
|
91
|
+ },
|
|
92
|
+ {
|
|
93
|
+ title: '创建日期',
|
|
94
|
+ key: 'createDate',
|
|
95
|
+ dataIndex: 'createDate',
|
|
96
|
+ valueType: 'date',
|
|
97
|
+ hideInSearch: true,
|
|
98
|
+ },
|
|
99
|
+ {
|
|
100
|
+ title: '操作',
|
|
101
|
+ key: 'option',
|
|
102
|
+ valueType: 'option',
|
|
103
|
+ width: 180,
|
|
104
|
+ render: (_, hospital) => [
|
|
105
|
+ <a key="edit" onClick={() => handleEdit(hospital)}>
|
|
106
|
+ 修改
|
|
107
|
+ </a>,
|
|
108
|
+ <a key="status" onClick={() => changeStatus(hospital)}>
|
|
109
|
+ {hospital.status === 1 ? '弃用' : '启用'}
|
|
110
|
+ </a>,
|
|
111
|
+ ],
|
|
112
|
+ },
|
|
113
|
+ ];
|
|
114
|
+
|
|
115
|
+ const handleSubmit = () => {
|
|
116
|
+ setShow(false);
|
|
117
|
+
|
|
118
|
+ if (!inputVal) {
|
|
119
|
+ return;
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ if (current && current.hospitalId) {
|
|
123
|
+ request(`/hospital/${current.hospitalId}`, {
|
|
124
|
+ method: 'put',
|
|
125
|
+ data: { ...current, name: inputVal },
|
|
126
|
+ })
|
|
127
|
+ .then(() => {
|
|
128
|
+ tableRef.current.reload();
|
|
129
|
+ notification.success({ message: '修改成功' });
|
|
130
|
+ })
|
|
131
|
+ .catch((e) => {
|
|
132
|
+ notification.error({ message: e.message });
|
|
133
|
+ });
|
|
134
|
+ } else {
|
|
135
|
+ request('/hospital', { method: 'post', data: { schoolId: school.schoolId, name: inputVal } })
|
|
136
|
+ .then(() => {
|
|
137
|
+ tableRef.current.reload();
|
|
138
|
+ notification.success({ message: '修改成功' });
|
|
139
|
+ })
|
|
140
|
+ .catch((e) => {
|
|
141
|
+ notification.error({ message: e.message });
|
|
142
|
+ });
|
|
143
|
+ }
|
|
144
|
+ };
|
|
145
|
+
|
|
146
|
+ const actions = [
|
|
147
|
+ <Button key="button" icon={<PlusOutlined />} type="primary" onClick={handleAdd}>
|
|
148
|
+ 新建
|
|
149
|
+ </Button>,
|
|
150
|
+ ];
|
|
151
|
+
|
|
152
|
+ return (
|
|
153
|
+ <PageContainer>
|
|
154
|
+ <ProTable
|
|
155
|
+ manualRequest
|
|
156
|
+ actionRef={tableRef}
|
|
157
|
+ columns={columns}
|
|
158
|
+ request={queryFunc}
|
|
159
|
+ rowKey="schoolId"
|
|
160
|
+ headerTitle="诊室列表"
|
|
161
|
+ toolBarRender={() => actions}
|
|
162
|
+ />
|
|
163
|
+ <Modal
|
|
164
|
+ title={school?.name}
|
|
165
|
+ visible={show}
|
|
166
|
+ onOk={handleSubmit}
|
|
167
|
+ onCancel={() => setShow(false)}
|
|
168
|
+ >
|
|
169
|
+ <Input size="large" value={inputVal} onChange={(e) => setInputVal(e.target.value)} />
|
|
170
|
+ </Modal>
|
|
171
|
+ </PageContainer>
|
|
172
|
+ );
|
|
173
|
+};
|