modal.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-12 17:11:11
  4. * @LastEditTime: 2024-01-19 10:35:31
  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, UserRelaSeletDataListType } 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, PlatformPubDirDataType } 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 [dirData, set_dirData] = useState<PlatformPubDirDataType[]>([]);
  31. const columns: ProColumns<DataSourceType>[] = [
  32. {
  33. title: 'id',
  34. dataIndex: 'id',
  35. key: 'id',
  36. hideInTable: true,
  37. },
  38. {
  39. title: '账号',
  40. dataIndex: 'account',
  41. key: 'account',
  42. },
  43. {
  44. title: '密码',
  45. key: 'password',
  46. dataIndex: 'password',
  47. },
  48. {
  49. title: '是否默认',
  50. dataIndex: 'isDefault',
  51. valueType: 'select',
  52. request: async () => [
  53. {
  54. value: 1,
  55. label: '是',
  56. },
  57. {
  58. value: 0,
  59. label: '否',
  60. },
  61. ],
  62. },
  63. {
  64. title: '操作',
  65. valueType: 'option',
  66. key: 'option',
  67. width: 120,
  68. render: (text, record, _, action) => [
  69. <a
  70. key="delete"
  71. onClick={() => {
  72. setDataSource(dataSource.filter((item) => item.key !== record.key));
  73. }}
  74. >
  75. 删除
  76. </a>,
  77. ],
  78. },
  79. ];
  80. const onVisibleChangeHandle = (bool: boolean) => {
  81. if (!bool) {
  82. dispatch &&
  83. dispatch({
  84. type: 'hospManageModel/cancelTableAct',
  85. });
  86. }
  87. };
  88. const onFinishHandle = (data: any & AddUsersDataType) => {
  89. if (tableAct == TableActType.ADD) {
  90. dispatch &&
  91. dispatch({
  92. type: 'hospManageModel/postAddData',
  93. payload: data,
  94. });
  95. }
  96. if (tableAct == TableActType.EDIT || tableAct == TableActType.BINDACCOUNT) {
  97. console.log({ data });
  98. dispatch &&
  99. dispatch({
  100. type: 'hospManageModel/postEditData',
  101. payload:
  102. tableAct == TableActType.EDIT
  103. ? {
  104. ...data,
  105. parentId: data.isHospital ? data.parentId.value : undefined,
  106. parentName: data.isHospital ? data.parentId.label : '-',
  107. }
  108. : data,
  109. });
  110. }
  111. return true;
  112. };
  113. const setModalTitle = () => {
  114. if (tableAct == TableActType.EDIT) {
  115. return '编辑院区';
  116. }
  117. if (tableAct == TableActType.ADD) {
  118. return '新增院区';
  119. }
  120. if (tableAct == TableActType.BINDACCOUNT) {
  121. return '院区报告设置';
  122. }
  123. };
  124. const setInitialValues: any = () => {
  125. if (tableAct == TableActType.EDIT) {
  126. return {
  127. ...currentEdit,
  128. parentId: currentEdit?.parentId,
  129. parentName: currentEdit?.parentName,
  130. isDataShare: currentEdit?.dataShare == '是' ? 1 : 0,
  131. };
  132. }
  133. if (tableAct == TableActType.ADD) {
  134. return {
  135. hospSign: randomString(16),
  136. isDataShare: 0,
  137. hospitalLevel: setSelectorData('HOSPITAL_LEVEL').defaultvalue,
  138. hospitalType: setSelectorData('HOSPITAL_TYPE').defaultvalue,
  139. hospitalNature: setSelectorData('HOSPITAL_NATURE').defaultvalue,
  140. };
  141. }
  142. if (tableAct == TableActType.BINDACCOUNT) {
  143. if (currentEdit?.reportId) {
  144. return { ...currentEdit, reportId: parseInt(currentEdit.reportId) };
  145. }
  146. }
  147. };
  148. const getDirecData = async (key?: string) => {
  149. const data = await getPlatformDictionary();
  150. if (data) {
  151. set_dirData(data);
  152. }
  153. };
  154. const setSelectorData = (key: string) => {
  155. let result = dirData.filter((t: any) => t.code == key);
  156. if (result.length > 0) {
  157. let dataArr = result[0].dataVoList;
  158. let defaultValue = dataArr.filter((t) => t.defaultValue == 1);
  159. dataArr.sort((prev: any, next: any) => {
  160. return prev.sort - next.sort;
  161. });
  162. return {
  163. defaultvalue: defaultValue[0] ? defaultValue[0].value : '',
  164. list: dataArr.map((t) => ({ label: t.name, value: t.code, defaultValue: t.defaultValue })),
  165. };
  166. }
  167. return {
  168. defaultvalue: '',
  169. list: [],
  170. };
  171. };
  172. useEffect(() => {
  173. //加装key字段
  174. const fixedDataSource = currentEdit?.youshuUsers
  175. ? currentEdit.youshuUsers.map((t) => ({
  176. ...t,
  177. key: Number((Math.random() * 1000000).toFixed(0)),
  178. }))
  179. : [];
  180. setDataSource(fixedDataSource);
  181. }, [currentEdit]);
  182. useEffect(() => {
  183. getDirecData();
  184. }, []);
  185. return (
  186. <KCModal
  187. visible={isShowModal}
  188. onVisibleChange={onVisibleChangeHandle}
  189. layout="horizontal"
  190. width={480}
  191. initialValues={setInitialValues()}
  192. title={setModalTitle()}
  193. labelCol={{
  194. span: 5,
  195. }}
  196. wrapperCol={{ span: 12 }}
  197. onFinish={async (data) => onFinishHandle(tableAct == TableActType.BINDACCOUNT ? { ...data, dataSource } : data)}
  198. >
  199. {tableAct != TableActType.BINDACCOUNT && (
  200. <>
  201. <ProFormText
  202. width="md"
  203. name="hospName"
  204. label="医院名称"
  205. placeholder="请输入"
  206. rules={[
  207. {
  208. required: true,
  209. message: '请输入医院名称!',
  210. },
  211. ]}
  212. />
  213. <KCProSelect
  214. label="是否主院"
  215. width="md"
  216. name="isHospital"
  217. options={[
  218. {
  219. value: 1,
  220. label: '否',
  221. },
  222. {
  223. value: 0,
  224. label: '是',
  225. },
  226. ]}
  227. rules={[
  228. {
  229. required: true,
  230. message: '请选择!',
  231. },
  232. ]}
  233. />
  234. <ProFormDependency name={['isHospital']}>
  235. {({ isHospital }) => {
  236. if (isHospital && isHospital == 1) {
  237. return (
  238. <KCProSelect
  239. label="选择主院"
  240. width="md"
  241. name="parentId"
  242. fieldProps={{
  243. labelInValue: true,
  244. }}
  245. request={async () => {
  246. const hospList: any[] = await getHospList();
  247. if (hospList) {
  248. return hospList.map((t: any) => ({
  249. label: t.name,
  250. value: t.id,
  251. }));
  252. }
  253. return [];
  254. }}
  255. rules={[
  256. {
  257. required: true,
  258. message: '请选择院区!',
  259. },
  260. ]}
  261. />
  262. );
  263. }
  264. }}
  265. </ProFormDependency>
  266. <KCProSelect
  267. label="医院等级"
  268. width="md"
  269. name="hospitalLevel"
  270. request={async () => {
  271. return setSelectorData('HOSPITAL_LEVEL').list;
  272. }}
  273. fieldProps={{ showSearch: true }}
  274. rules={[
  275. {
  276. required: true,
  277. message: '请选择!',
  278. },
  279. ]}
  280. />
  281. <KCProSelect
  282. label="医院类型"
  283. width="md"
  284. name="hospitalType"
  285. request={async () => {
  286. return setSelectorData('HOSPITAL_TYPE').list;
  287. }}
  288. fieldProps={{ showSearch: true }}
  289. rules={[
  290. {
  291. required: true,
  292. message: '请选择!',
  293. },
  294. ]}
  295. />
  296. <KCProSelect
  297. label="医院性质"
  298. width="md"
  299. name="hospitalNature"
  300. request={async () => {
  301. return setSelectorData('HOSPITAL_NATURE').list;
  302. }}
  303. fieldProps={{ showSearch: true }}
  304. rules={[
  305. {
  306. required: true,
  307. message: '请选择!',
  308. },
  309. ]}
  310. />
  311. <ProFormText width="md" name="hospSign" label="医院标识" disabled />
  312. <ProFormText
  313. width="md"
  314. name="hospAbbreviation"
  315. label="简称"
  316. placeholder="请输入"
  317. rules={[
  318. {
  319. required: true,
  320. },
  321. ]}
  322. />
  323. <ProFormText
  324. width="md"
  325. name="systemName"
  326. label="系统名称"
  327. placeholder="请输入"
  328. rules={[
  329. {
  330. required: true,
  331. },
  332. ]}
  333. />
  334. <ProFormText width="md" name="hospitalCode" label="编码" placeholder="请输入" />
  335. <ProFormRadio.Group
  336. name="isDataShare"
  337. label="是否数据分享"
  338. options={[
  339. {
  340. label: '是',
  341. value: 1,
  342. },
  343. {
  344. label: '否',
  345. value: 0,
  346. },
  347. ]}
  348. />
  349. <ProFormRadio.Group
  350. name="loadType"
  351. label="登陆模式"
  352. options={[
  353. {
  354. label: '简易',
  355. value: 1,
  356. },
  357. {
  358. label: '普通',
  359. value: 0,
  360. },
  361. ]}
  362. />
  363. </>
  364. )}
  365. {tableAct == TableActType.BINDACCOUNT && (
  366. <>
  367. <ProFormText
  368. width="md"
  369. name="reportUrl"
  370. label="报告请求地址"
  371. placeholder="请输入"
  372. rules={[
  373. {
  374. required: true,
  375. message: '请输入!',
  376. },
  377. ]}
  378. />
  379. <ProFormDigit
  380. label="报告项目Id"
  381. name="reportId"
  382. min={0}
  383. width={328}
  384. fieldProps={{ precision: 0 }}
  385. rules={[
  386. {
  387. required: true,
  388. message: '请输入!',
  389. },
  390. ]}
  391. />
  392. <EditableProTable<DataSourceType>
  393. rowKey="key"
  394. headerTitle="院区[有数]账号绑定"
  395. columns={columns}
  396. value={dataSource}
  397. recordCreatorProps={{
  398. record: {
  399. key: Number((Math.random() * 1000000).toFixed(0)),
  400. id: -1,
  401. userName: '',
  402. account: '',
  403. password: '',
  404. isDefault: 0,
  405. },
  406. }}
  407. onChange={setDataSource}
  408. editable={{
  409. // type: 'multiple',
  410. deletePopconfirmMessage: '确定删除此行?',
  411. editableKeys,
  412. onChange: setEditableRowKeys,
  413. }}
  414. />
  415. </>
  416. )}
  417. </KCModal>
  418. );
  419. };
  420. export default ActModal;