index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-01-04 14:12:31
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-03-02 16:06:48
  6. * @FilePath: /BudgetManaSystem/src/pages/budgetMana/oneBatch/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import BMSPagecontainer from '@/components/BMSPageContainer'
  10. import { BMSTable } from '@/components/BMSTable';
  11. import { getComputeDate } from '@/pages/Home/service';
  12. import { ActionType, ProColumns } from '@ant-design/pro-components';
  13. import { message, Modal, Popover, Table, Tabs } from 'antd';
  14. import { useEffect, useRef, useState } from 'react';
  15. import { caculate, checkRequest, getData } from './service';
  16. import './style.less';
  17. import { create, all } from 'mathjs'
  18. const config = {
  19. number: 'number',
  20. precision: 14
  21. }
  22. const math = create(all, config as any);
  23. const OneBatch = () => {
  24. const [tableColumn, set_tableColumn] = useState<ProColumns[] | any[]>([]);
  25. const [currentComputeDate, set_currentComputeDate] = useState<string | undefined>();
  26. const [currentTabKey, set_currentTabKey] = useState('1');
  27. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>({ reportCode: undefined });
  28. const [auditType, set_auditType] = useState('0');
  29. const [ifShowTip, set_ifShowTip] = useState(false);
  30. const tableRef = useRef<ActionType>();
  31. const [tableH, set_tableH] = useState(0);
  32. const onTabChange = (activeKey: string) => {
  33. set_currentTabKey(activeKey);
  34. set_tableDataFilterParams({
  35. ...tableDataFilterParams,
  36. reportCode: activeKey
  37. })
  38. }
  39. const getTableData = async (params: any, sort: any, filter: any) => {
  40. const { reportCode = 1 } = params;
  41. const resp: any = await getData(
  42. currentComputeDate as string,
  43. reportCode
  44. );
  45. if (resp) {
  46. const { title, assignmentData } = resp;
  47. const columns = title.map((item: any) => {
  48. return {
  49. title: item.name,
  50. dataIndex: `${item.code}`,
  51. key: `${item.code}`,
  52. width: 100,
  53. align: 'center',
  54. }
  55. });
  56. set_tableColumn([{
  57. title: '核算单元',
  58. dataIndex: 'unitName',
  59. key: 'unitName',
  60. width: 100,
  61. fixed: 'left',
  62. align: 'center',
  63. }, ...columns, {
  64. title: '总奖金',
  65. dataIndex: 'totalScore',
  66. key: 'totalScore',
  67. width: 100,
  68. fixed: 'right',
  69. align: 'center',
  70. }]);
  71. const data = assignmentData.map((item: any) => {
  72. let rowData: { [key: string]: any } = {};
  73. for (let index = 0; index < item.value.length; index++) {
  74. for (const key in item.value[index]) {
  75. if (key != 'code') {
  76. rowData[`${item.value[index].code}`] = item.value[index].value
  77. }
  78. }
  79. }
  80. return { ...item, ...rowData, id: item.id, columns }
  81. });
  82. return {
  83. data,
  84. success: true
  85. }
  86. }
  87. return []
  88. }
  89. const checkHandle = async (type: string) => {
  90. const resp = await checkRequest({
  91. computeDate: currentComputeDate as string,
  92. auditType: type == '0' ? '1' : '0', //审核类型 1审核 0取消审核
  93. });
  94. if (resp) {
  95. if (type == '0') {
  96. message.success('审核提交成功!');
  97. set_auditType('1');
  98. }
  99. if (type == '1') {
  100. message.success('取消审核提交成功!');
  101. set_auditType('0');
  102. }
  103. }
  104. }
  105. const getCurrentComputeDate = async () => {
  106. const resp = await getComputeDate();
  107. set_currentComputeDate(resp);
  108. }
  109. const confirmCaculateHandle = async () => {
  110. const resp = await caculate(currentComputeDate as string);
  111. if (resp) {
  112. tableRef.current?.reload();
  113. }
  114. }
  115. const generateFunc = () => {
  116. Modal.confirm({
  117. title: '注意',
  118. cancelText: '',
  119. closable: true,
  120. content: '计算会覆盖原有数据,确定要继续计算操作?',
  121. onOk: () => confirmCaculateHandle()
  122. })
  123. }
  124. const handleResize = (e: any) => {
  125. const wH = e.target.innerHeight;
  126. const tableHeight = wH - 320;
  127. set_tableH(tableHeight);
  128. }
  129. function doResize() {
  130. setTimeout(() => {
  131. const ev: any = new Event('resize');
  132. window.dispatchEvent(ev);
  133. }, 0)
  134. }
  135. useEffect(() => {
  136. if (currentComputeDate) {
  137. }
  138. }, [currentComputeDate]);
  139. useEffect(() => {
  140. getCurrentComputeDate();
  141. window.addEventListener('resize',(e)=>handleResize(e)) //监听窗口大小改变
  142. doResize();
  143. }, [])
  144. return (
  145. <BMSPagecontainer className='OneBatch' title={`核算年月:${currentComputeDate}`}>
  146. <div className='btnGroup'>
  147. <Popover open={ifShowTip} content={'当前处于审核中,无法操作!'} >
  148. <div className={auditType == '0' ? 'caculateBtn' : 'caculateBtn disabled'}
  149. onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
  150. onMouseLeave={() => set_ifShowTip(false)}
  151. onClick={() => auditType == '0' ? generateFunc() : () => { }}>计算</div>
  152. </Popover>
  153. <div className='checkBtn' onClick={() => checkHandle(`${auditType}`)}>{auditType == '0' ? '审核' : '取消审核'}</div>
  154. </div>
  155. <div className='content'>
  156. <Tabs
  157. defaultActiveKey='1'
  158. onChange={onTabChange}
  159. items={[
  160. {
  161. label: `临床医生`,
  162. key: '1',
  163. },
  164. {
  165. label: `医技`,
  166. key: '2',
  167. },
  168. {
  169. label: `护理`,
  170. key: '3',
  171. },
  172. {
  173. label: `行政`,
  174. key: '4',
  175. },
  176. ]}
  177. />
  178. <div className='tabContent'>
  179. {currentComputeDate && <BMSTable actionRef={tableRef} rowKey='unitCode' pagination={false} columns={tableColumn as ProColumns[]}
  180. params={tableDataFilterParams}
  181. scroll={{ x: 120 * 10, y:tableH }}
  182. request={(params, sort, filter) => getTableData(params, sort, filter)}
  183. summary={(pageData) => {
  184. const Caculate = ({ colData }: { colData: any }) => {
  185. const { dataIndex } = colData;
  186. const total = pageData.reduce((prev, cur) => {
  187. //return prev + cur[`${dataIndex}`]
  188. if (typeof cur[`${dataIndex}`] == 'number') {
  189. return math.add(prev, cur[`${dataIndex}`] as number);
  190. }
  191. }, 0);
  192. return (
  193. //<span>{typeof total == 'number'?math.format(total, {precision: 14}) : '合计'}</span>
  194. <span>{typeof total == 'number' ? Number(total.toFixed(4)) : '合计'}</span>
  195. )
  196. }
  197. return (
  198. <Table.Summary fixed>
  199. <Table.Summary.Row>
  200. {
  201. tableColumn.map((item, index) => {
  202. return (
  203. <Table.Summary.Cell key={index} index={index} align='center' rowSpan={1} >
  204. <Caculate colData={item} />
  205. </Table.Summary.Cell >
  206. )
  207. })
  208. }
  209. </Table.Summary.Row>
  210. </Table.Summary>
  211. );
  212. }}
  213. />}
  214. </div>
  215. </div>
  216. </BMSPagecontainer>
  217. )
  218. }
  219. export default OneBatch