modal.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-12 17:11:11
  4. * @LastEditTime: 2023-09-18 18:07:16
  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 from 'react';
  10. import KCModal from '@/components/KCModal';
  11. import KCProSelect from '@/components/KCProSelect';
  12. import { roleManageModelState, Dispatch } from 'umi';
  13. import { ProFormText, ProFormTextArea } from '@ant-design/pro-form';
  14. import { getHospList, getShareHospList } from '@/service/hospList';
  15. import { AddUsersDataType, getYoushuUsers } from '@/service/user';
  16. import { TableActType } from '..';
  17. import { Form } from 'antd';
  18. import MenuEditer from '@/pages/platform/components/menuEditer/menu';
  19. import UserEditer from '@/pages/platform/components/usersEditer';
  20. interface ActModalProps extends roleManageModelState {
  21. dispatch: Dispatch | undefined;
  22. }
  23. const ActModal: React.FC<ActModalProps> = ({ dispatch, isShowModal, tableAct, currentEdit, hospId }) => {
  24. const onVisibleChangeHandle = (bool: boolean) => {
  25. // console.log({bool});
  26. if (!bool) {
  27. dispatch &&
  28. dispatch({
  29. type: 'roleManageModel/cancelTableAct',
  30. });
  31. }
  32. };
  33. const onFinishHandle = (data: any & AddUsersDataType) => {
  34. if (tableAct == TableActType.ADD) {
  35. dispatch &&
  36. dispatch({
  37. type: 'roleManageModel/postAddData',
  38. payload: data,
  39. });
  40. }
  41. if (tableAct == TableActType.EDIT || tableAct == TableActType.EDITMENU || tableAct == TableActType.EDITRELAUSER) {
  42. dispatch &&
  43. dispatch({
  44. type: 'roleManageModel/postEditData',
  45. payload: data,
  46. });
  47. }
  48. return true;
  49. };
  50. const setModalTitle = () => {
  51. if (tableAct == TableActType.EDIT) {
  52. return '编辑角色';
  53. }
  54. if (tableAct == TableActType.ADD) {
  55. return '新增角色';
  56. }
  57. if (tableAct == TableActType.EDITMENU) {
  58. return '绑定菜单';
  59. }
  60. if (tableAct == TableActType.EDITRELAUSER) {
  61. return '绑定人员';
  62. }
  63. };
  64. const setInitialValues = () => {
  65. if (tableAct == TableActType.EDIT) {
  66. return { ...currentEdit };
  67. }
  68. if (tableAct == TableActType.ADD) {
  69. console.log({hospId});
  70. return { hospId: hospId };
  71. }
  72. if (tableAct == TableActType.EDITMENU || tableAct == TableActType.EDITRELAUSER) {
  73. return { ...currentEdit };
  74. }
  75. };
  76. return (
  77. <KCModal
  78. visible={isShowModal}
  79. onVisibleChange={onVisibleChangeHandle}
  80. layout="horizontal"
  81. width={500}
  82. initialValues={setInitialValues()}
  83. title={setModalTitle()}
  84. labelCol={{
  85. span: 5,
  86. }}
  87. onFinish={async (data) => onFinishHandle(data)}
  88. >
  89. {tableAct == TableActType.EDITMENU && (
  90. <Form.Item name="bindMenuIds">
  91. <MenuEditer noAction={true} hospId={currentEdit?.hospId} />
  92. </Form.Item>
  93. )}
  94. {tableAct == TableActType.EDITRELAUSER && (
  95. <Form.Item name="bindUserIds">
  96. <UserEditer total={currentEdit?currentEdit.allUsers:[]} noAction={true} />
  97. </Form.Item>
  98. )}
  99. {(tableAct == TableActType.ADD || tableAct == TableActType.EDIT) && (
  100. <>
  101. <KCProSelect
  102. label="选择院区"
  103. width="md"
  104. name="hospId"
  105. disabled
  106. request={async () => {
  107. const hospList = await getShareHospList();
  108. if (hospList) {
  109. return hospList.map((t) => ({
  110. label: t.name,
  111. value: t.id,
  112. }));
  113. }
  114. return [];
  115. }}
  116. />
  117. <ProFormText
  118. width="md"
  119. name="roleName"
  120. label="角色名称"
  121. placeholder="请输入"
  122. rules={[
  123. {
  124. required: true,
  125. message: '请输入医院名称!',
  126. },
  127. ]}
  128. />
  129. <KCProSelect
  130. label="关联有数账号"
  131. width="md"
  132. name="youshuUserId"
  133. request={async () => {
  134. const resp = await getYoushuUsers();
  135. if (resp) {
  136. return resp.map((t) => ({
  137. label: t.name,
  138. value: t.id,
  139. }));
  140. }
  141. return [];
  142. }}
  143. />
  144. <ProFormTextArea name="remark" label="备注" placeholder="请输入名称" width="md" fieldProps={{}} />
  145. </>
  146. )}
  147. </KCModal>
  148. );
  149. };
  150. export default ActModal;