index.jsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-09-10 09:24:25
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. import { Space, Table, Tag } from 'antd';
  10. import React, { useState, useRef } from 'react';
  11. import { PageContainer} from '@ant-design/pro-layout';
  12. import ProTable from '@ant-design/pro-table';
  13. import { DrawerForm } from '@ant-design/pro-form';
  14. import { getResponsibilityCenterConnectList,getResponsibilityCenterConnectableList,saveResponsibilityCenterConnected } from './service';
  15. const ResponsibilityCenterConnect = () => {
  16. const columns = [
  17. {
  18. title: '责任中心名称',
  19. dataIndex: 'responsibilityName',
  20. key: 'responsibilityName',
  21. hideInSearch: false,
  22. width: '20%',
  23. ellipsis: true,
  24. },
  25. {
  26. title: '责任中心Id',
  27. dataIndex: 'responsibilityId',
  28. key: 'responsibilityId',
  29. hideInSearch: true,
  30. width: '20%',
  31. ellipsis: true,
  32. },
  33. {
  34. title: '部门列表',
  35. dataIndex: 'departments',
  36. key: 'departments',
  37. hideInSearch: false,
  38. ellipsis: true,
  39. render: (departments) => {
  40. if (Array.isArray(departments)) {
  41. return departments.map((item, index) => { return <Tag key={index}>{item.departmentName}</Tag> })
  42. } else {
  43. return <></>
  44. }
  45. }
  46. },
  47. {
  48. title:'操作',
  49. dataIndex: 'option',
  50. key: 'option',
  51. valueType: 'option',
  52. width: '15%',
  53. render: (_, record) => {
  54. const {isGatherCenter } = record;
  55. // console.log({record});
  56. return isGatherCenter==2 ? [
  57. <a
  58. key="config"
  59. onClick={() => {
  60. setDrawerVisible(true);
  61. setCurrentRow(record);
  62. }}
  63. >
  64. 绑定科室
  65. </a>,
  66. ] : []
  67. },
  68. }
  69. ];
  70. const drawerTableColumns = [
  71. {
  72. title: 'Id',
  73. dataIndex: 'id',
  74. key: 'id',
  75. hideInSearch: true,
  76. ellipsis: true,
  77. },
  78. {
  79. title: '科室名称',
  80. dataIndex: 'departmentName',
  81. key: 'departmentName',
  82. hideInSearch: false,
  83. ellipsis: true,
  84. },
  85. {
  86. title: '科室编码',
  87. dataIndex: 'departmentCode',
  88. key: 'departmentCode',
  89. hideInSearch: true,
  90. ellipsis: true,
  91. },
  92. ];
  93. const actionRef = useRef(); //表格
  94. const drawerFormRef = useRef(); //DrawerForm
  95. const actionDrawertableRef = useRef(); //Drawertable
  96. const [currentRow, setCurrentRow] = useState({});
  97. const [drawerVisible, setDrawerVisible] = useState(false);
  98. const [selectedRowKeys,setSelectedRowKeys] = useState([]);
  99. const [defaultExpandedRowKeys,setDefaultExpandedRowKeys] = useState([]);
  100. /**
  101. *
  102. * @param {Boolean} bool
  103. */
  104. const drawerVisibleChange = (bool) => {
  105. // console.log({currentRow});
  106. const {departments=[]} = currentRow;
  107. const selected = departments.map(item=>item.departmentId);
  108. if (bool)setSelectedRowKeys(selected==undefined?[]:selected);
  109. setDrawerVisible(bool);
  110. if (!bool) setCurrentRow(undefined);
  111. }
  112. //获取责任中心对应列表
  113. const getList = async (params = {}, sort, filter) => {
  114. const res = await getResponsibilityCenterConnectList(params);
  115. const defaultKeys = res.data.list?res.data.list.map(item=>item.responsibilityId):[];
  116. setDefaultExpandedRowKeys(defaultKeys);
  117. return {
  118. data: res.data.list,
  119. total: res.data.totalCount,
  120. success: res.success,
  121. };
  122. };
  123. //获取责任中心可绑定科室列表
  124. const getConnectableList = async (params = {}, sort, filter)=>{
  125. const {responsibilityId} = currentRow;
  126. const res = await getResponsibilityCenterConnectableList({...params,responsibilityId});
  127. const {data,status} = res;
  128. if(status == 200){
  129. return {
  130. data:data,
  131. success:true,
  132. }
  133. }
  134. }
  135. const onExpandedRowsChange = (expandedRows)=>{
  136. setDefaultExpandedRowKeys([].concat(expandedRows))
  137. }
  138. return (
  139. <PageContainer>
  140. <ProTable
  141. columns={columns}
  142. request={getList}
  143. actionRef={actionRef}
  144. rowKey="responsibilityId"
  145. childrenColumnName="child"
  146. expandable={{ defaultExpandedRowKeys: [],expandedRowKeys:defaultExpandedRowKeys,onExpandedRowsChange:onExpandedRowsChange }}
  147. toolBarRender={() => []}
  148. pagination={{
  149. pageSize: 10,
  150. }}
  151. search={false}
  152. />
  153. <DrawerForm
  154. title="可绑定科室列表"
  155. formRef={drawerFormRef}
  156. visible={drawerVisible}
  157. onVisibleChange={(visible) => drawerVisibleChange(visible)}
  158. // onFinish={(value) => onSubmit({ ...values, ...value })}
  159. onFinish={async ()=>{
  160. // console.log({selectedRowKeys,currentRow});
  161. const {responsibilityId} = currentRow;
  162. const resp = await saveResponsibilityCenterConnected({responsibilityId,departmentIds:selectedRowKeys});
  163. const {status} = resp;
  164. if(status==200){
  165. setDrawerVisible(false);
  166. if (actionRef.current) {
  167. actionRef.current.reload();
  168. }
  169. }
  170. }}
  171. >
  172. <ProTable
  173. columns={drawerTableColumns}
  174. request={getConnectableList}
  175. rowKey="id"
  176. toolBarRender={() => []}
  177. actionRef={actionDrawertableRef}
  178. pagination={{
  179. pageSize: 10,
  180. }}
  181. rowSelection={{
  182. // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
  183. // 注释该行则默认不显示下拉选项
  184. selectedRowKeys,
  185. selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
  186. onChange:(selectedRowKeys)=>{
  187. setSelectedRowKeys([...selectedRowKeys]);
  188. }
  189. }}
  190. tableAlertRender={({ selectedRowKeys, selectedRows, onCleanSelected }) => {
  191. // console.log({selectedRowKeys});
  192. return (
  193. <Space size={24}>
  194. <span>
  195. 已选 {selectedRowKeys.length} 项
  196. <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
  197. 取消选择
  198. </a>
  199. </span>
  200. </Space>
  201. )
  202. }}
  203. tableAlertOptionRender={() => {
  204. return (
  205. <Space size={16}>
  206. {/* <a>批量绑定</a> */}
  207. </Space>
  208. );
  209. }}
  210. search={false}
  211. />
  212. </DrawerForm>
  213. </PageContainer>
  214. );
  215. };
  216. export default ResponsibilityCenterConnect;