index.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-13 14:31:32
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. import { PlusOutlined } from '@ant-design/icons';
  10. import { Button, Popconfirm} from 'antd';
  11. import React, { useState, useRef } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form';
  15. import UpdateForm from './updateForm';
  16. // import CAUpload from '@/components/CAUpload';
  17. import { getResponsibilityCenterList, editResponsibilityCenterList, delResponsibilityCenter, addResponsibilityCenter } from './service';
  18. import { getApportionmentLevelListNoPage } from '../apportionmentLevel/service';
  19. const responsibilityCenter = () => {
  20. const columns = [
  21. {
  22. title: '责任中心名称',
  23. dataIndex: 'responsibilityName',
  24. key: 'responsibilityName',
  25. hideInSearch: false,
  26. width: '15%'
  27. },
  28. {
  29. title: '责任中心编码',
  30. dataIndex: 'responsibilityCode',
  31. key: 'responsibilityCode',
  32. hideInSearch: true,
  33. },
  34. {
  35. title: '是否汇总中心',
  36. dataIndex: 'isGatherCenter',
  37. key: 'isGatherCenter',
  38. hideInSearch: true,
  39. render: (text) => <>{text == 1 ? '是' : '否'}</>,
  40. width: '15%'
  41. },
  42. {
  43. title: '责任类型',
  44. dataIndex: 'responsibilityType',
  45. key: 'responsibilityType',
  46. hideInSearch: true,
  47. width: '15%',
  48. render: (text) => <>{text == 1 ? '收益中心' : '成本(费用)中心'}</>,
  49. },
  50. {
  51. title: '分摊级别',
  52. dataIndex: 'shareLevel',
  53. key: 'shareLevel',
  54. hideInSearch: true,
  55. width: '10%'
  56. },
  57. {
  58. title: '分摊级别名称',
  59. dataIndex: 'shareName',
  60. key: 'shareName',
  61. hideInSearch: true,
  62. width: '15%'
  63. },
  64. {
  65. title:'操作',
  66. dataIndex: 'option',
  67. valueType: 'option',
  68. width: '15%',
  69. render: (_, record) => [
  70. <a
  71. key="config"
  72. onClick={() => {
  73. handleUpdateModalVisible(true);
  74. setCurrentRow(record);
  75. }}
  76. >
  77. 编辑
  78. </a>,
  79. <Popconfirm
  80. key="subscribeAlert"
  81. title="是否确定删除?"
  82. onConfirm={() => {
  83. setCurrentRow(record);
  84. delListHandler(record);
  85. }}
  86. >
  87. <a>删除</a>
  88. </Popconfirm>,
  89. ],
  90. },
  91. ];
  92. const [createModalVisible, handleModalVisible] = useState(false);
  93. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  94. const actionRef = useRef(); //表格
  95. const ref = useRef(); //新增表单
  96. const [currentRow, setCurrentRow] = useState({});
  97. const [selectedLevelList,setSelectedLevelList] = useState(null); //可选的分摊层级列表
  98. const [selectedLevel,setSelectedLevel] = useState(null);
  99. /**
  100. *
  101. * @param {Boolean} bool 弹窗展示状态
  102. */
  103. const updateModalVisibleChange = (bool) => {
  104. handleUpdateModalVisible(bool);
  105. if (!bool) setCurrentRow(undefined);
  106. };
  107. //获取科室列表
  108. const getList = async (params = {}, sort, filter) => {
  109. const res = await getResponsibilityCenterList(params);
  110. // console.log({res});
  111. return {
  112. data: res.data.list,
  113. total: res.data.totalCount,
  114. success: res.success,
  115. };
  116. };
  117. /**
  118. *
  119. * @param {Object} value 删除项数据
  120. */
  121. const delListHandler = async (value) => {
  122. const resp = await delResponsibilityCenter(value);
  123. if(resp.status==200){
  124. if (actionRef.current) {
  125. actionRef.current.reload();
  126. }
  127. }
  128. };
  129. //展开table
  130. const expandedRowRender = (record, index, indent, expanded) => {
  131. // console.log({ record, index, indent, expanded });
  132. const _columns = columns.filter(item => !(['id'].includes(item.key)));
  133. return (
  134. <ProTable
  135. columns={[..._columns]}
  136. headerTitle={false}
  137. showHeader={false}
  138. search={false}
  139. options={false}
  140. rowKey="id"
  141. dataSource={record.child}
  142. pagination={false}
  143. />
  144. );
  145. };
  146. return (
  147. <PageContainer>
  148. <ProTable
  149. columns={columns}
  150. request={getList}
  151. actionRef={actionRef}
  152. rowKey="id"
  153. childrenColumnName="child"
  154. expandable={{defaultExpandedRowKeys:[]}}
  155. toolBarRender={() => [
  156. <Button
  157. key="button"
  158. icon={<PlusOutlined />}
  159. type="primary"
  160. onClick={() => {
  161. handleModalVisible(true);
  162. }}
  163. >
  164. 新增
  165. </Button>
  166. ]}
  167. pagination={{
  168. pageSize: 10,
  169. }}
  170. search={false}
  171. />
  172. <ModalForm
  173. title="新增责任中心"
  174. width="800px"
  175. labelCol={{ span: 5, offset: 3 }}
  176. layout={'horizontal'}
  177. visible={createModalVisible}
  178. onVisibleChange={(bool)=>{
  179. if (ref.current) {
  180. ref.current.resetFields();
  181. }
  182. handleModalVisible(bool);
  183. }}
  184. formRef={ref}
  185. onFinish={async (value) => {
  186. // console.log({'新增':value,selectedLevel})
  187. const body = {...value,shareName:selectedLevel.shareName,shareId:selectedLevel.id};
  188. const success = await addResponsibilityCenter(body);
  189. if (success) {
  190. handleModalVisible(false);
  191. if (actionRef.current) {
  192. actionRef.current.reload();
  193. }
  194. }
  195. }}
  196. >
  197. <ProFormSelect
  198. name="id"
  199. label="责任管理中心"
  200. showSearch
  201. request={async ({ keyWords }) => {
  202. const res = await getResponsibilityCenterList();
  203. if(res.status == 200){
  204. // console.log({res});
  205. const filter_arr = res.data.list.filter(item=>{
  206. // console.log({item});
  207. if(keyWords){
  208. return item.responsibilityName.indexOf(keyWords) != -1
  209. }else {
  210. return item
  211. }
  212. });
  213. const arr = filter_arr.map(item=>({label:item.responsibilityName, value:item.id}));
  214. return arr;
  215. }else {
  216. return [];
  217. }
  218. }}
  219. width='md'
  220. placeholder="选择需要新增在哪个责任中心下,默认新增最外层"
  221. rules={[{ required: false, message: '' }]}
  222. />
  223. <ProFormText
  224. label="责任中心名"
  225. rules={[
  226. {
  227. required: true,
  228. message:'医院名是必填项',
  229. },
  230. ]}
  231. width="sm"
  232. name="responsibilityName"
  233. />
  234. <ProFormText
  235. label="责任中心编码"
  236. rules={[
  237. {
  238. required: true,
  239. message:'责任中心编码是必填项',
  240. },
  241. ]}
  242. width="sm"
  243. name="responsibilityCode"
  244. />
  245. <ProFormSelect
  246. rules={[
  247. {
  248. required: true,
  249. message:'请选择是否为汇总中心',
  250. },
  251. ]}
  252. options={[
  253. {
  254. value: 1,
  255. label: '是',
  256. },
  257. {
  258. value: 2,
  259. label: '否',
  260. },
  261. ]}
  262. width="sm"
  263. name="isGatherCenter"
  264. label="是否汇总中心"
  265. />
  266. <ProFormSelect
  267. rules={[
  268. {
  269. required: true,
  270. message:'请选择责任类型',
  271. },
  272. ]}
  273. options={[
  274. {
  275. value: 1,
  276. label: '收益中心',
  277. },
  278. {
  279. value: 2,
  280. label: '成本(费用)中心',
  281. },
  282. ]}
  283. width="sm"
  284. name="responsibilityType"
  285. label="选择责任类型"
  286. />
  287. <ProFormSelect
  288. rules={[
  289. {
  290. required: true,
  291. message:'请选择分摊级别',
  292. },
  293. ]}
  294. fieldProps={{
  295. onChange: async (val) => {
  296. const resp = await getApportionmentLevelListNoPage();
  297. const {status,data} = resp;
  298. if(status==200){
  299. const needItem = data.list.filter(item=>item.leverSort == val);
  300. setSelectedLevel(needItem[0]);
  301. }
  302. },
  303. }}
  304. request={ async ()=>{
  305. const resp = await getApportionmentLevelListNoPage();
  306. const {status,data} = resp;
  307. if(status==200){
  308. setSelectedLevelList(data.list);
  309. return data.list.map(item=>({label:`级别${item.leverSort}-${item.shareName}`,value:item.leverSort}))
  310. }else{
  311. return []
  312. }
  313. }}
  314. width="sm"
  315. name='shareLevel'
  316. label="选择分摊级别"
  317. />
  318. </ModalForm>
  319. {/* 更新 */}
  320. <UpdateForm
  321. onSubmit={async (value) => {
  322. console.log({ '编辑': value });
  323. const {responsibilityLevel,selectedLevel} = value;
  324. const body = selectedLevel.length==0?{
  325. //没有修改分摊层级
  326. ...value,shareLevelId:responsibilityLevel
  327. }:{
  328. //修改了分摊层级
  329. ...value,shareLevelId:selectedLevel[0].id
  330. }
  331. // console.log({'editBody':body});
  332. // return;
  333. const success = await editResponsibilityCenterList(body);
  334. if (success) {
  335. handleUpdateModalVisible(false);
  336. setCurrentRow(undefined);
  337. if (actionRef.current) {
  338. actionRef.current.reload();
  339. }
  340. }
  341. }}
  342. onCancel={() => {
  343. handleUpdateModalVisible(false);
  344. setCurrentRow(undefined);
  345. }}
  346. updateModalVisible={updateModalVisible}
  347. updateModalVisibleChange={updateModalVisibleChange}
  348. values={currentRow || {}}
  349. />
  350. </PageContainer>
  351. );
  352. };
  353. export default responsibilityCenter;