modal.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-12 17:11:11
  4. * @LastEditTime: 2022-07-07 16:26:50
  5. * @LastEditors: code4eat awesomedema@gmail.com
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/userManage/modal.tsx
  8. */
  9. import React, { useEffect, useRef, useState } from 'react';
  10. import KCModal from '@/components/KCModal';
  11. import KCProSelect from '@/components/KCProSelect';
  12. import { hospManageModelState, Dispatch } from 'umi';
  13. import { ProFormText, ProFormRadio, ProFormDependency, ProFormDigit } from '@ant-design/pro-form';
  14. import type { ProColumns } from '@ant-design/pro-table';
  15. import { EditableProTable } from '@ant-design/pro-table';
  16. import { getHospList, getHospYoushuAccounts, getMainHosp, YoushuAccountsType } from '@/service/hospList';
  17. import type { AddUsersDataType } from '@/service/user';
  18. import { randomString } from '@/utils';
  19. import { TableActType } from '..';
  20. import { Form } from 'antd';
  21. import MenuEditer from '@/pages/platform/components/menuEditer/menu';
  22. import { getPlatformDictionary } from '@/service/dictionary';
  23. interface ActModalProps extends hospManageModelState {
  24. dispatch: Dispatch | undefined;
  25. }
  26. type DataSourceType = YoushuAccountsType & { key: number };
  27. const ActModal: React.FC<ActModalProps> = ({ dispatch, isShowModal, tableAct, currentEdit }) => {
  28. const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
  29. const [dataSource, setDataSource] = useState<DataSourceType[]>([]);
  30. const columns: ProColumns<DataSourceType>[] = [
  31. {
  32. title: 'id',
  33. dataIndex: 'id',
  34. key: 'id',
  35. hideInTable: true,
  36. },
  37. {
  38. title: '账号',
  39. dataIndex: 'account',
  40. key: 'account',
  41. },
  42. {
  43. title: '密码',
  44. key: 'password',
  45. dataIndex: 'password',
  46. },
  47. {
  48. title: '是否默认',
  49. dataIndex: 'isDefault',
  50. valueType: 'select',
  51. request: async () => [
  52. {
  53. value: 1,
  54. label: '是',
  55. },
  56. {
  57. value: 0,
  58. label: '否',
  59. },
  60. ],
  61. },
  62. {
  63. title: '操作',
  64. valueType: 'option',
  65. key: 'option',
  66. width: 120,
  67. render: (text, record, _, action) => [
  68. <a
  69. key="delete"
  70. onClick={() => {
  71. setDataSource(dataSource.filter((item) => item.key !== record.key));
  72. }}
  73. >
  74. 删除
  75. </a>,
  76. ],
  77. },
  78. ];
  79. const onVisibleChangeHandle = (bool: boolean) => {
  80. if (!bool) {
  81. dispatch &&
  82. dispatch({
  83. type: 'hospManageModel/cancelTableAct',
  84. });
  85. }
  86. };
  87. const onFinishHandle = (data: any & AddUsersDataType) => {
  88. console.log({ data });
  89. if (tableAct == TableActType.ADD) {
  90. dispatch &&
  91. dispatch({
  92. type: 'hospManageModel/postAddData',
  93. payload: data,
  94. });
  95. }
  96. if (
  97. tableAct == TableActType.EDIT ||
  98. tableAct == TableActType.EDITMENU ||
  99. tableAct == TableActType.BINDACCOUNT
  100. ) {
  101. dispatch &&
  102. dispatch({
  103. type: 'hospManageModel/postEditData',
  104. payload: data,
  105. });
  106. }
  107. return true;
  108. };
  109. const setModalTitle = () => {
  110. if (tableAct == TableActType.EDIT) {
  111. return '编辑院区';
  112. }
  113. if (tableAct == TableActType.ADD) {
  114. return '新增院区';
  115. }
  116. if (tableAct == TableActType.EDITMENU) {
  117. return '绑定菜单';
  118. }
  119. if (tableAct == TableActType.BINDACCOUNT) {
  120. return '院区报告设置';
  121. }
  122. };
  123. const setInitialValues = () => {
  124. if (tableAct == TableActType.EDIT) {
  125. return {
  126. ...currentEdit,
  127. isDataShare: currentEdit?.dataShare == '是' ? 1 : 0,
  128. };
  129. }
  130. if (tableAct == TableActType.ADD) {
  131. return { hospSign: randomString(16), isDataShare: 0 };
  132. }
  133. if (tableAct == TableActType.EDITMENU) {
  134. return { ...currentEdit };
  135. }
  136. if (tableAct == TableActType.BINDACCOUNT) {
  137. if (currentEdit?.reportId) {
  138. return { ...currentEdit, reportId: parseInt(currentEdit.reportId) };
  139. }
  140. }
  141. };
  142. useEffect(() => {
  143. //加装key字段
  144. const fixedDataSource = currentEdit?.youshuUsers
  145. ? currentEdit.youshuUsers.map((t) => ({
  146. ...t,
  147. key: Number((Math.random() * 1000000).toFixed(0)),
  148. }))
  149. : [];
  150. setDataSource(fixedDataSource);
  151. }, [currentEdit]);
  152. return (
  153. <KCModal
  154. visible={isShowModal}
  155. onVisibleChange={onVisibleChangeHandle}
  156. layout="horizontal"
  157. width={600}
  158. initialValues={setInitialValues()}
  159. title={setModalTitle()}
  160. labelCol={{
  161. span: 6,
  162. }}
  163. wrapperCol={{ span: 12 }}
  164. onFinish={async (data) =>
  165. onFinishHandle(tableAct == TableActType.BINDACCOUNT ? { ...data, dataSource } : data)
  166. }
  167. >
  168. {tableAct == TableActType.EDITMENU && (
  169. <Form.Item name="bindMenuIds">
  170. <MenuEditer />
  171. </Form.Item>
  172. )}
  173. {tableAct != TableActType.EDITMENU && tableAct != TableActType.BINDACCOUNT && (
  174. <>
  175. <ProFormText
  176. width="md"
  177. name="hospName"
  178. label="医院名称"
  179. placeholder="请输入"
  180. rules={[
  181. {
  182. required: true,
  183. message: '请输入医院名称!',
  184. },
  185. ]}
  186. />
  187. <KCProSelect
  188. label="是否主院"
  189. width="md"
  190. name="isHospital"
  191. options={[
  192. {
  193. value: 1,
  194. label: '否',
  195. },
  196. {
  197. value: 0,
  198. label: '是',
  199. },
  200. ]}
  201. rules={[
  202. {
  203. required: true,
  204. message: '请选择!',
  205. },
  206. ]}
  207. />
  208. <ProFormDependency name={['isHospital']}>
  209. {({ isHospital }) => {
  210. if (isHospital && isHospital == 1) {
  211. return (
  212. <KCProSelect
  213. label="选择主院"
  214. width="md"
  215. name="mainHospId"
  216. request={async () => {
  217. const hospList = await getHospList();
  218. if (hospList) {
  219. return hospList.map((t) => ({
  220. label: t.name,
  221. value: t.id,
  222. }));
  223. }
  224. return [];
  225. }}
  226. rules={[
  227. {
  228. required: true,
  229. message: '请选择院区!',
  230. },
  231. ]}
  232. />
  233. );
  234. }
  235. }}
  236. </ProFormDependency>
  237. <KCProSelect
  238. label="医院等级"
  239. width="md"
  240. name="hospitalLevel"
  241. request={async () => {
  242. const resp = await getPlatformDictionary('HOSPITAL_LEVEL');
  243. if (resp) {
  244. return resp[0].dataVoList.map((t) => ({
  245. label: t.code,
  246. value: t.value,
  247. }));
  248. }
  249. return [];
  250. }}
  251. rules={[
  252. {
  253. required: true,
  254. message: '请选择!',
  255. },
  256. ]}
  257. />
  258. <KCProSelect
  259. label="医院类型"
  260. width="md"
  261. name="hospitalType"
  262. request={async () => {
  263. const resp = await getPlatformDictionary('HOSPITAL_TYPE');
  264. if (resp) {
  265. return resp[0].dataVoList.map((t) => ({
  266. label: t.code,
  267. value: t.value,
  268. }));
  269. }
  270. return [];
  271. }}
  272. rules={[
  273. {
  274. required: true,
  275. message: '请选择!',
  276. },
  277. ]}
  278. />
  279. <KCProSelect
  280. label="医院性质"
  281. width="md"
  282. name="hospitalNature"
  283. request={async () => {
  284. const resp = await getPlatformDictionary('HOSPITAL_NATURE');
  285. if (resp) {
  286. return resp[0].dataVoList.map((t) => ({
  287. label: t.code,
  288. value: t.value,
  289. }));
  290. }
  291. return [];
  292. }}
  293. rules={[
  294. {
  295. required: true,
  296. message: '请选择!',
  297. },
  298. ]}
  299. />
  300. <ProFormText width="md" name="hospSign" label="医院标识" disabled />
  301. <ProFormText width="md" name="hospAbbreviation" label="简称" placeholder="请输入" />
  302. <ProFormText width="md" name="hospitalCode" label="编码" placeholder="请输入" />
  303. <ProFormText width="md" name="systemName" label="系统名称" placeholder="请输入" />
  304. <ProFormRadio.Group
  305. name="isDataShare"
  306. label="是否数据分享"
  307. options={[
  308. {
  309. label: '是',
  310. value: 1,
  311. },
  312. {
  313. label: '否',
  314. value: 0,
  315. },
  316. ]}
  317. />
  318. </>
  319. )}
  320. {tableAct == TableActType.BINDACCOUNT && (
  321. <>
  322. <ProFormText
  323. width="md"
  324. name="reportUrl"
  325. label="报告请求地址"
  326. placeholder="请输入"
  327. rules={[
  328. {
  329. required: true,
  330. message: '请输入!',
  331. },
  332. ]}
  333. />
  334. <ProFormDigit
  335. label="报告项目Id"
  336. name="reportId"
  337. min={0}
  338. fieldProps={{ precision: 0 }}
  339. rules={[
  340. {
  341. required: true,
  342. message: '请输入!',
  343. },
  344. ]}
  345. />
  346. <EditableProTable<DataSourceType>
  347. rowKey="key"
  348. headerTitle="院区[有数]账号绑定"
  349. columns={columns}
  350. value={dataSource}
  351. recordCreatorProps={{
  352. record: {
  353. key: Number((Math.random() * 1000000).toFixed(0)),
  354. id: -1,
  355. userName: '',
  356. account: '',
  357. password: '',
  358. isDefault: 0,
  359. },
  360. }}
  361. onChange={setDataSource}
  362. editable={{
  363. // type: 'multiple',
  364. deletePopconfirmMessage: '确定删除此行?',
  365. editableKeys,
  366. onChange: setEditableRowKeys,
  367. }}
  368. />
  369. </>
  370. )}
  371. </KCModal>
  372. );
  373. };
  374. export default ActModal;