index.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-13 20:18:17
  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, useEffect } 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 DrawerContent from './components/DrawerContent';
  17. import { getVisitsAndBedDayCostSettingList, delVisitsAndBedDayCostSettingList, addVisitsAndBedDayCostSettingList,
  18. getVisitsAndBedDayCostSettingListById,editVisitsAndBedDayCostSettingList } from './service';
  19. import { getCostshareparamList } from '@/pages/costAllocationParamsSetting/service';
  20. import { getReportProjectSettingList } from '@/pages/baseSetting/reportProjectSetting/service';
  21. const DistrictMana = () => {
  22. const columns = [
  23. {
  24. title: '分配方式',
  25. dataIndex: 'allocation',
  26. key: 'allocation',
  27. hideInSearch: true,
  28. render: num => <>{num == 1 ? '按照收入比例分配' : '按照固定比例分配'}</>
  29. },
  30. {
  31. title: '收入类型',
  32. dataIndex: 'incomeType',
  33. key: 'incomeType',
  34. hideInSearch: true,
  35. render: num => <>{num == 1 ? '门诊方式' : '住院方式'}</>
  36. },
  37. {
  38. title: '对应值',
  39. dataIndex: 'incomeFileName',
  40. key: 'incomeFileName',
  41. hideInSearch: false,
  42. },
  43. {
  44. title: '分摊参数编码',
  45. dataIndex: 'shareParamCode',
  46. key: 'shareParamCode',
  47. hideInSearch: true,
  48. },
  49. {
  50. title: '分摊参数名称',
  51. dataIndex: 'shareParamName',
  52. key: 'shareParamName',
  53. hideInSearch: true,
  54. },
  55. {
  56. title: '成本对应',
  57. dataIndex: 'costCorrespondingName',
  58. key: 'costCorrespondingName',
  59. hideInSearch: true,
  60. },
  61. {
  62. title: '操作',
  63. dataIndex: 'option',
  64. valueType: 'option',
  65. render: (_, record) => [
  66. <a
  67. key="config"
  68. onClick={() => {
  69. edithandle(record);
  70. }}
  71. >
  72. 编辑
  73. </a>,
  74. <Popconfirm
  75. key="subscribeAlert"
  76. title="是否确定删除?"
  77. onConfirm={() => {
  78. setCurrentRow(record);
  79. delListHandler(record);
  80. }}
  81. >
  82. <a>删除</a>
  83. </Popconfirm>,
  84. ],
  85. },
  86. ];
  87. const drawerTableColumns = [
  88. {
  89. title: '分摊参数名称',
  90. dataIndex: 'shareParamName',
  91. key: 'shareParamName',
  92. hideInSearch: true,
  93. },
  94. {
  95. title: '分摊参数代码',
  96. dataIndex: 'shareParamCode',
  97. key: 'shareParamCode',
  98. hideInSearch: true,
  99. }
  100. ]
  101. const drawerTableReportColumns = [
  102. {
  103. title: '报表项目名',
  104. dataIndex: 'reportName',
  105. key: 'reportName',
  106. hideInSearch: true,
  107. },
  108. {
  109. title: '编号',
  110. dataIndex: 'num',
  111. key: 'num',
  112. hideInSearch: true,
  113. }
  114. ]
  115. const [createModalVisible, handleModalVisible] = useState(false);
  116. const [updateModalVisible, handleUpdateModalVisible] = useState(false);
  117. const actionRef = useRef();
  118. const ref = useRef(); //新增表单
  119. const [updateFormRef,setUpdateFormRef] = useState(null);
  120. const [currentRow, setCurrentRow] = useState({});
  121. const [drawerVisible, setDrawerVisible] = useState(false);
  122. const [type, setType] = useState(0); //1 分摊参数,2 报表
  123. const [selectedShareparams, setSelectedShareparams] = useState(null);
  124. const [selectedIncome, setSelectedIncome] = useState(null);
  125. const [activeKey, setActiveKey] = useState('0');
  126. const [selectedCost, setSelectedCost] = useState(null);
  127. const [ifcostCorresponding, setIfcostCorresponding] = useState(true);
  128. const [dataById, setDataById] = useState(null);
  129. const [edit,setEdit] = useState(false);
  130. const [expandedRowKeys,setExpandedRowKeys] = useState([]);
  131. const [defaultReportTableSelected,setDefaultReportTableSelected] = useState([]);
  132. const reportTableTypes = ['损益表','完全成本法表','变动成本表','全院损益表','全成本报表'];
  133. /**
  134. *
  135. * @param {Boolean} bool 弹窗展示状态
  136. */
  137. const updateModalVisibleChange = (bool) => {
  138. handleUpdateModalVisible(bool);
  139. if (!bool) setCurrentRow(undefined);
  140. };
  141. //获取列表
  142. const getList = async (params = {}, sort, filter) => {
  143. const res = await getVisitsAndBedDayCostSettingList({...params});
  144. // console.log({res});
  145. return {
  146. data: res.data.list,
  147. total: res.data.totalCount,
  148. success: res.success,
  149. };
  150. };
  151. //获取drawer 列表
  152. const getDrawerTableList = async (params = {}, sort, filter) => {
  153. if (type == 1) {
  154. const res = await getCostshareparamList({ ...params });
  155. return {
  156. data: res.data.list,
  157. total: res.data.totalCount,
  158. success: res.success,
  159. };
  160. }
  161. if (type == 2) {
  162. const res = await getReportProjectSettingList({ ...params, reportType: activeKey });
  163. const arr = res.data.list.map(item=>item.num);
  164. setExpandedRowKeys(arr);
  165. return {
  166. data: res.data.list,
  167. total: res.data.totalCount,
  168. success: res.success,
  169. };
  170. }
  171. };
  172. /**
  173. *
  174. * @param {Object} value 删除项数据
  175. */
  176. const delListHandler = async (value) => {
  177. const resp = await delVisitsAndBedDayCostSettingList(value);
  178. // console.log({ resp });
  179. if (resp.status) {
  180. if (actionRef.current) {
  181. actionRef.current.reload();
  182. }
  183. }
  184. };
  185. const edithandle = async (record) => {
  186. setEdit(true);
  187. const { id } = record;
  188. //获取指定id数据
  189. const resp = await getVisitsAndBedDayCostSettingListById({ id });
  190. // console.log({ resp });
  191. const { status, data } = resp;
  192. if (status == 200) {
  193. setDataById(data);
  194. }
  195. setCurrentRow(record);
  196. handleUpdateModalVisible(true);
  197. }
  198. const openDrawerHandle = (num, bool) => {
  199. setType(num);
  200. setIfcostCorresponding(bool);
  201. if(!edit)setDefaultReportTableSelected([].concat([]));
  202. if(bool&&edit){
  203. console.log('成本');
  204. const {costFileType,costCorresponding} = dataById;
  205. setDefaultReportTableSelected([].concat([costCorresponding]));
  206. setActiveKey(`${costFileType}`);
  207. }
  208. if(!bool&&edit){
  209. console.log('收入');
  210. const {incomeFileType,incomeFieldNum} = dataById;
  211. setDefaultReportTableSelected([].concat([incomeFieldNum]));
  212. setActiveKey(`${incomeFileType}`);
  213. }
  214. setDrawerVisible(true);
  215. }
  216. useEffect(() => {
  217. }, []);
  218. return (
  219. <PageContainer>
  220. <ProTable
  221. columns={columns}
  222. request={getList}
  223. actionRef={actionRef}
  224. rowKey="id"
  225. toolBarRender={() => [
  226. <Button
  227. key="button"
  228. icon={<PlusOutlined />}
  229. type="primary"
  230. onClick={() => {
  231. setEdit(false);
  232. handleModalVisible(true);
  233. }}
  234. >
  235. 新增
  236. </Button>
  237. ]}
  238. pagination={{
  239. pageSize: 10,
  240. }}
  241. search={{
  242. defaultCollapsed: false,
  243. labelWidth: 'auto',
  244. }}
  245. />
  246. {
  247. <ModalForm
  248. title="新增诊次/床日成本设置"
  249. width="800px"
  250. labelCol={{ span: 5, offset: 3 }}
  251. layout={'horizontal'}
  252. formRef={ref}
  253. visible={createModalVisible}
  254. onVisibleChange={(bool) => {
  255. if (ref.current) {
  256. ref.current.resetFields();
  257. }
  258. handleModalVisible(bool);
  259. }}
  260. onFinish={async (value) => {
  261. const { allocation, incomeType } = value;
  262. const { shareParamCode, shareParamName } = selectedShareparams;
  263. const { num: incomeFieldNum, reportName: incomeFileName,reportType:incomeFileType } = selectedIncome;
  264. const { num: costCorresponding, reportName: costCorrespondingName,reportType:costFileType } = selectedCost;
  265. const data = {
  266. allocation, incomeType, shareParamCode, shareParamName, incomeFieldNum,
  267. incomeFileName:`[${reportTableTypes[incomeFileType]}] ${incomeFileName}`,
  268. costCorresponding, costCorrespondingName:`[${reportTableTypes[costFileType]}] ${costCorrespondingName}`,
  269. incomeFileType,costFileType}
  270. // console.log({data});
  271. const success = await addVisitsAndBedDayCostSettingList(data);
  272. if (success) {
  273. handleModalVisible(false);
  274. if (actionRef.current) {
  275. actionRef.current.reload();
  276. }
  277. }
  278. //清空
  279. setSelectedCost(null);
  280. setSelectedShareparams(null);
  281. setSelectedIncome(null);
  282. }}
  283. >
  284. <ProFormSelect
  285. rules={[
  286. {
  287. required: true,
  288. message: '请选择分配方式',
  289. },
  290. ]}
  291. options={[
  292. {
  293. value: 1,
  294. label: '按收入比例分配',
  295. },
  296. // {
  297. // value: 2,
  298. // label: '按照固定比例分配',
  299. // },
  300. ]}
  301. width="sm"
  302. name="allocation"
  303. label="分配方式"
  304. />
  305. <ProFormSelect
  306. rules={[
  307. {
  308. required: true,
  309. message: '请选择收入类型',
  310. },
  311. ]}
  312. options={[
  313. {
  314. value: 1,
  315. label: '住院收入',
  316. },
  317. {
  318. value: 2,
  319. label: '门诊收入',
  320. },
  321. ]}
  322. width="sm"
  323. name="incomeType"
  324. label="收入类型"
  325. />
  326. <ProFormText
  327. fieldProps={{
  328. onFocus: () => { openDrawerHandle(1) },
  329. allowClear:false
  330. }}
  331. rules={[
  332. {
  333. required: true,
  334. message: '请选择分摊参数',
  335. },
  336. ]}
  337. width="sm"
  338. name="shareParamName"
  339. label="选择分摊参数"
  340. />
  341. <ProFormText
  342. fieldProps={{
  343. onFocus: () => { openDrawerHandle(2, false); },
  344. allowClear:false
  345. }}
  346. rules={[
  347. {
  348. required: true,
  349. message: '请选择对应收入字段',
  350. },
  351. ]}
  352. width="sm"
  353. name="incomeFileName"
  354. label="对应收入字段"
  355. />
  356. <ProFormText
  357. fieldProps={{
  358. onFocus: () => { openDrawerHandle(2, true); },
  359. allowClear:false
  360. }}
  361. rules={[
  362. {
  363. required: true,
  364. message: '请选择对应成本字段',
  365. },
  366. ]}
  367. width="sm"
  368. name="costCorrespondingName"
  369. label="对应成本字段"
  370. />
  371. </ModalForm>
  372. }
  373. {/* 抽屉内容 */}
  374. {
  375. type == 1 ? <DrawerContent
  376. columns={drawerTableColumns}
  377. visible={drawerVisible}
  378. currentRow={currentRow}
  379. title="选择分摊参数"
  380. type='radio'
  381. defaultSelected={edit?[dataById.shareParamCode]:[]}
  382. onVisibleChange={(bool) => setDrawerVisible(bool)}
  383. renderListFunc={getDrawerTableList}
  384. config={{ tableSearch: false, rowKeys: 'shareParamCode' }}
  385. onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
  386. // console.log({ '分摊': selectedRows })
  387. setSelectedShareparams(selectedRows[0]);
  388. const { shareParamName } = selectedRows[0];
  389. if(edit){
  390. updateFormRef?.current?.setFieldsValue({
  391. shareParamName: shareParamName,
  392. });
  393. }else{
  394. ref?.current?.setFieldsValue({
  395. shareParamName: shareParamName,
  396. });
  397. }
  398. setDrawerVisible(false);
  399. }}
  400. /> : <DrawerContent
  401. columns={drawerTableReportColumns}
  402. visible={drawerVisible}
  403. currentRow={currentRow}
  404. title={ifcostCorresponding ? '选择对应成本字段' : '选择对应收入字段'}
  405. type='radio'
  406. tabList={[
  407. {
  408. tab: '损益表',
  409. key: 0,
  410. },
  411. {
  412. tab: '完全成本法表',
  413. key: 1,
  414. },
  415. {
  416. tab: '变动成本表',
  417. key: 2,
  418. },
  419. {
  420. tab: '全院损益表',
  421. key: 3,
  422. },
  423. {
  424. tab: '全成本报表',
  425. key: 4,
  426. },
  427. ]}
  428. // tabActiveKey='3'
  429. renderCell={(checked, record, index, originNode) => {
  430. const { children } = record;
  431. if (!children || children.length == 0) {
  432. return originNode
  433. } else {
  434. return null
  435. }
  436. }}
  437. onTabChange={(key, ref) => {
  438. setActiveKey(key);
  439. if (ref.current) ref.current.reload()
  440. }}
  441. expandable={{
  442. expandedRowKeys:expandedRowKeys
  443. }}
  444. defaultSelected={defaultReportTableSelected}
  445. onVisibleChange={(bool) => setDrawerVisible(bool)}
  446. renderListFunc={getDrawerTableList}
  447. config={{ tableSearch: false,rowKeys:'num'}}
  448. tabActiveKey={activeKey}
  449. onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
  450. // console.log({ '报表': selectedRows,'ifcostCorresponding':ifcostCorresponding,value });
  451. if(selectedRows.length>0){
  452. const { reportName,reportType } = selectedRows[0];
  453. if (!ifcostCorresponding) {
  454. setSelectedIncome(selectedRows[0]);
  455. if(edit){
  456. updateFormRef?.current?.setFieldsValue({
  457. incomeFileName: reportName,
  458. });
  459. }else{
  460. ref?.current?.setFieldsValue({
  461. incomeFileName: reportName,
  462. });
  463. }
  464. }
  465. if (ifcostCorresponding) {
  466. setSelectedCost(selectedRows[0]);
  467. if(edit){
  468. updateFormRef?.current?.setFieldsValue({
  469. costCorrespondingName: reportName,
  470. });
  471. }else{
  472. ref?.current?.setFieldsValue({
  473. costCorrespondingName: reportName,
  474. });
  475. }
  476. }
  477. }
  478. setDrawerVisible(false);
  479. setActiveKey('0');
  480. }}
  481. />
  482. }
  483. {/* 更新 */}
  484. <UpdateForm
  485. onSubmit={async (value) => {
  486. // console.log({ '编辑': value });
  487. const {id} = currentRow;
  488. const { allocation, incomeType } = value;
  489. let data = {id,allocation,incomeType};
  490. if(selectedShareparams){
  491. const { shareParamCode, shareParamName } = selectedShareparams;
  492. data = {...data,shareParamCode, shareParamName}
  493. }else{
  494. const { shareParamCode, shareParamName } = dataById;
  495. data = {...data,shareParamCode, shareParamName}
  496. }
  497. if(selectedIncome){
  498. const { num: incomeFieldNum, reportName: incomeFileName,reportType:incomeFileType } = selectedIncome;
  499. data = {...data,incomeFieldNum,incomeFileName,incomeFileType}
  500. }else{
  501. const { incomeFieldNum, incomeFileName,incomeFileType } = dataById;
  502. data = {...data,incomeFieldNum,incomeFileName,incomeFileType}
  503. }
  504. if(selectedCost){
  505. const { num: costCorresponding, reportName: costCorrespondingName,reportType:costFileType } = selectedCost;
  506. data = {...data,costCorresponding,costCorrespondingName,costFileType}
  507. }else{
  508. const { costCorresponding, costCorrespondingName,costFileType } = dataById;
  509. data = {...data,costCorresponding,costCorrespondingName,costFileType}
  510. }
  511. const success = await editVisitsAndBedDayCostSettingList(data);
  512. if (success) {
  513. handleUpdateModalVisible(false);
  514. setCurrentRow(undefined);
  515. if (actionRef.current) {
  516. actionRef.current.reload();
  517. }
  518. }
  519. //清空
  520. setSelectedCost(null);
  521. setSelectedShareparams(null);
  522. setSelectedIncome(null);
  523. setDataById(null);
  524. setDefaultReportTableSelected([]);
  525. }}
  526. openDrawerHandle={openDrawerHandle}
  527. onCancel={() => {
  528. handleUpdateModalVisible(false);
  529. setCurrentRow(undefined);
  530. }}
  531. getFormRef={ref=>setUpdateFormRef(ref)}
  532. updateModalVisible={updateModalVisible}
  533. updateModalVisibleChange={updateModalVisibleChange}
  534. values={currentRow || {}}
  535. />
  536. </PageContainer>
  537. );
  538. };
  539. export default DistrictMana;