modal.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-12 17:11:11
  4. * @LastEditTime: 2022-03-04 09:06:04
  5. * @LastEditors: Please set LastEditors
  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, 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. interface ActModalProps extends hospManageModelState {
  23. dispatch: Dispatch | undefined;
  24. }
  25. type DataSourceType = YoushuAccountsType & { key: number };
  26. const ActModal: React.FC<ActModalProps> = ({ dispatch, isShowModal, tableAct, currentEdit }) => {
  27. const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
  28. const [dataSource, setDataSource] = useState<DataSourceType[]>([]);
  29. const columns: ProColumns<DataSourceType>[] = [
  30. {
  31. title: 'id',
  32. dataIndex: 'id',
  33. key: 'id',
  34. hideInTable: true,
  35. },
  36. {
  37. title: '账号',
  38. dataIndex: 'account',
  39. key: 'account',
  40. },
  41. {
  42. title: '密码',
  43. key: 'password',
  44. dataIndex: 'password',
  45. },
  46. {
  47. title: '是否默认',
  48. dataIndex: 'isDefault',
  49. valueType: 'select',
  50. request: async () => [
  51. {
  52. value: 1,
  53. label: '是',
  54. },
  55. {
  56. value: 0,
  57. label: '否',
  58. },
  59. ],
  60. },
  61. {
  62. title: '操作',
  63. valueType: 'option',
  64. key: 'option',
  65. width: 120,
  66. render: (text, record, _, action) => [
  67. <a
  68. key="delete"
  69. onClick={() => {
  70. setDataSource(dataSource.filter((item) => item.key !== record.key));
  71. }}
  72. >
  73. 删除
  74. </a>,
  75. ],
  76. },
  77. ];
  78. const onVisibleChangeHandle = (bool: boolean) => {
  79. if (!bool) {
  80. dispatch &&
  81. dispatch({
  82. type: 'hospManageModel/cancelTableAct',
  83. });
  84. }
  85. };
  86. const onFinishHandle = (data: any & AddUsersDataType) => {
  87. console.log({ data });
  88. if (tableAct == TableActType.ADD) {
  89. dispatch &&
  90. dispatch({
  91. type: 'hospManageModel/postAddData',
  92. payload: data,
  93. });
  94. }
  95. if (
  96. tableAct == TableActType.EDIT ||
  97. tableAct == TableActType.EDITMENU ||
  98. tableAct == TableActType.BINDACCOUNT
  99. ) {
  100. dispatch &&
  101. dispatch({
  102. type: 'hospManageModel/postEditData',
  103. payload: data,
  104. });
  105. }
  106. return true;
  107. };
  108. const setModalTitle = () => {
  109. if (tableAct == TableActType.EDIT) {
  110. return '编辑院区';
  111. }
  112. if (tableAct == TableActType.ADD) {
  113. return '新增院区';
  114. }
  115. if (tableAct == TableActType.EDITMENU) {
  116. return '绑定菜单';
  117. }
  118. if (tableAct == TableActType.BINDACCOUNT) {
  119. return '院区报告设置';
  120. }
  121. };
  122. const setInitialValues = () => {
  123. if (tableAct == TableActType.EDIT) {
  124. return {
  125. ...currentEdit,
  126. isDataShare: currentEdit?.dataShare == '是' ? 1 : 0,
  127. };
  128. }
  129. if (tableAct == TableActType.ADD) {
  130. return { hospSign: randomString(16), isDataShare: 0 };
  131. }
  132. if (tableAct == TableActType.EDITMENU) {
  133. return { ...currentEdit };
  134. }
  135. if (tableAct == TableActType.BINDACCOUNT) {
  136. if (currentEdit?.reportId) {
  137. return { ...currentEdit, reportId: parseInt(currentEdit.reportId) };
  138. }
  139. }
  140. };
  141. useEffect(() => {
  142. //加装key字段
  143. const fixedDataSource = currentEdit?.youshuUsers
  144. ? currentEdit.youshuUsers.map((t) => ({
  145. ...t,
  146. key: Number((Math.random() * 1000000).toFixed(0)),
  147. }))
  148. : [];
  149. setDataSource(fixedDataSource);
  150. }, [currentEdit]);
  151. return (
  152. <KCModal
  153. visible={isShowModal}
  154. onVisibleChange={onVisibleChangeHandle}
  155. layout="horizontal"
  156. width={600}
  157. initialValues={setInitialValues()}
  158. title={setModalTitle()}
  159. labelCol={{
  160. span: 6,
  161. }}
  162. wrapperCol={{ span: 12 }}
  163. onFinish={async (data) =>
  164. onFinishHandle(tableAct == TableActType.BINDACCOUNT ? { ...data, dataSource } : data)
  165. }
  166. >
  167. {tableAct == TableActType.EDITMENU && (
  168. <Form.Item name="bindMenuIds">
  169. <MenuEditer />
  170. </Form.Item>
  171. )}
  172. {tableAct != TableActType.EDITMENU && tableAct != TableActType.BINDACCOUNT && (
  173. <>
  174. <ProFormText
  175. width="md"
  176. name="hospName"
  177. label="医院名称"
  178. placeholder="请输入"
  179. rules={[
  180. {
  181. required: true,
  182. message: '请输入医院名称!',
  183. },
  184. ]}
  185. />
  186. <KCProSelect
  187. label="是否主院"
  188. width="md"
  189. name="isHospital"
  190. options={[
  191. {
  192. value: 1,
  193. label: '否',
  194. },
  195. {
  196. value: 0,
  197. label: '是',
  198. },
  199. ]}
  200. rules={[
  201. {
  202. required: true,
  203. message: '请选择!',
  204. },
  205. ]}
  206. />
  207. <ProFormDependency name={['isHospital']}>
  208. {({ isHospital }) => {
  209. if (isHospital && isHospital == 1) {
  210. return (
  211. <KCProSelect
  212. label="选择主院"
  213. width="md"
  214. name="mainHospId"
  215. request={async () => {
  216. const hospList = await getHospList();
  217. if (hospList) {
  218. return hospList.map((t) => ({
  219. label: t.name,
  220. value: t.id,
  221. }));
  222. }
  223. return [];
  224. }}
  225. rules={[
  226. {
  227. required: true,
  228. message: '请选择院区!',
  229. },
  230. ]}
  231. />
  232. );
  233. }
  234. }}
  235. </ProFormDependency>
  236. <ProFormText width="md" name="hospSign" label="医院标识" disabled />
  237. <ProFormText width="md" name="hospAbbreviation" label="简称" placeholder="请输入" />
  238. <ProFormText width="md" name="systemName" label="系统名称" placeholder="请输入" />
  239. <ProFormRadio.Group
  240. name="isDataShare"
  241. label="是否数据分享"
  242. options={[
  243. {
  244. label: '是',
  245. value: 1,
  246. },
  247. {
  248. label: '否',
  249. value: 0,
  250. },
  251. ]}
  252. />
  253. </>
  254. )}
  255. {tableAct == TableActType.BINDACCOUNT && (
  256. <>
  257. <ProFormText
  258. width="md"
  259. name="reportUrl"
  260. label="报告请求地址"
  261. placeholder="请输入"
  262. rules={[
  263. {
  264. required: true,
  265. message: '请输入!',
  266. },
  267. ]}
  268. />
  269. <ProFormDigit
  270. label="报告项目Id"
  271. name="reportId"
  272. min={0}
  273. fieldProps={{ precision: 0 }}
  274. rules={[
  275. {
  276. required: true,
  277. message: '请输入!',
  278. },
  279. ]}
  280. />
  281. <EditableProTable<DataSourceType>
  282. rowKey="key"
  283. headerTitle="院区[有数]账号绑定"
  284. columns={columns}
  285. value={dataSource}
  286. recordCreatorProps={{
  287. record: {
  288. key: Number((Math.random() * 1000000).toFixed(0)),
  289. id: -1,
  290. userName: '',
  291. account: '',
  292. password: '',
  293. isDefault: 0,
  294. },
  295. }}
  296. onChange={setDataSource}
  297. editable={{
  298. // type: 'multiple',
  299. deletePopconfirmMessage: '确定删除此行?',
  300. editableKeys,
  301. onChange: setEditableRowKeys,
  302. }}
  303. />
  304. </>
  305. )}
  306. </KCModal>
  307. );
  308. };
  309. export default ActModal;