modal.tsx 4.7 KB

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