index.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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-08 11:08:33
  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, getCurrentCheckStatus, 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: 140,
  53. }
  54. });
  55. set_tableColumn([{
  56. title: '核算单元',
  57. dataIndex: 'unitName',
  58. key: 'unitName',
  59. width: 140,
  60. fixed: 'left',
  61. }, ...columns, {
  62. title: '总奖金',
  63. dataIndex: 'totalScore',
  64. key: 'totalScore',
  65. width: 140,
  66. fixed: 'right',
  67. }]);
  68. const data = assignmentData.map((item: any) => {
  69. let rowData: { [key: string]: any } = {};
  70. for (let index = 0; index < item.value.length; index++) {
  71. for (const key in item.value[index]) {
  72. if (key != 'code') {
  73. rowData[`${item.value[index].code}`] = item.value[index].value
  74. }
  75. }
  76. }
  77. return { ...item, ...rowData, id: item.id, columns }
  78. });
  79. return {
  80. data,
  81. success: true
  82. }
  83. }
  84. return []
  85. }
  86. const checkHandle = async (type: string) => {
  87. const resp = await checkRequest({
  88. computeDate: currentComputeDate as string,
  89. auditType: type == '0' ? '1' : '0', //审核类型 1审核 0取消审核
  90. });
  91. if (resp) {
  92. if (type == '0') {
  93. message.success('审核提交成功!');
  94. set_auditType('1');
  95. }
  96. if (type == '1') {
  97. message.success('取消审核提交成功!');
  98. set_auditType('0');
  99. }
  100. }
  101. }
  102. const getCurrentComputeDate = async () => {
  103. const resp = await getComputeDate();
  104. set_currentComputeDate(resp);
  105. }
  106. const confirmCaculateHandle = async () => {
  107. const resp = await caculate(currentComputeDate as string);
  108. if (resp) {
  109. tableRef.current?.reload();
  110. }
  111. }
  112. const getCheckStatus = async (computeDate: string) => {
  113. const resp = await getCurrentCheckStatus(computeDate);
  114. if (resp) {
  115. set_auditType(`${resp}`); //0 未审核 1 已审核
  116. }
  117. }
  118. const generateFunc = () => {
  119. Modal.confirm({
  120. title: '注意',
  121. cancelText: '',
  122. closable: true,
  123. content: '计算会覆盖原有数据,确定要继续计算操作?',
  124. onOk: () => confirmCaculateHandle()
  125. })
  126. }
  127. const handleResize = (e: any) => {
  128. const wH = e.target.innerHeight;
  129. const tableHeight = wH - 290;
  130. set_tableH(tableHeight);
  131. }
  132. function doResize() {
  133. setTimeout(() => {
  134. const ev: any = new Event('resize');
  135. window.dispatchEvent(ev);
  136. }, 0)
  137. }
  138. useEffect(() => {
  139. if (currentComputeDate) {
  140. getCheckStatus(currentComputeDate);
  141. }
  142. }, [currentComputeDate]);
  143. useEffect(() => {
  144. getCurrentComputeDate();
  145. window.addEventListener('resize',(e)=>handleResize(e)) //监听窗口大小改变
  146. doResize();
  147. return ()=>{
  148. window.removeEventListener('resize',(e)=>handleResize(e))
  149. }
  150. }, [])
  151. return (
  152. <BMSPagecontainer className='OneBatch' title={`核算年月:${currentComputeDate}`}>
  153. <div className='btnGroup'>
  154. <Popover open={ifShowTip} content={'当前处于审核中,无法操作!'} >
  155. <div className={auditType == '0' ? 'caculateBtn' : 'caculateBtn disabled'}
  156. onMouseEnter={() => auditType == '0' ? set_ifShowTip(false) : set_ifShowTip(true)}
  157. onMouseLeave={() => set_ifShowTip(false)}
  158. onClick={() => auditType == '0' ? generateFunc() : () => { }}>计算</div>
  159. </Popover>
  160. <div className='checkBtn' onClick={() => checkHandle(`${auditType}`)}>{auditType == '0' ? '审核' : '取消审核'}</div>
  161. </div>
  162. <div className='content'>
  163. <Tabs
  164. defaultActiveKey='1'
  165. onChange={onTabChange}
  166. items={[
  167. {
  168. label: `临床医生`,
  169. key: '1',
  170. },
  171. {
  172. label: `医技`,
  173. key: '2',
  174. },
  175. {
  176. label: `护理`,
  177. key: '3',
  178. },
  179. {
  180. label: `行政`,
  181. key: '4',
  182. },
  183. ]}
  184. />
  185. <div className='tabContent'>
  186. {currentComputeDate && <BMSTable actionRef={tableRef} rowKey='unitCode' pagination={false} columns={tableColumn as ProColumns[]}
  187. params={tableDataFilterParams}
  188. scroll={{ x: 140 * 10, y:tableH }}
  189. request={(params, sort, filter) => getTableData(params, sort, filter)}
  190. summary={(pageData) => {
  191. const Caculate = ({ colData }: { colData: any }) => {
  192. const { dataIndex } = colData;
  193. const total = pageData.reduce((prev, cur) => {
  194. //return prev + cur[`${dataIndex}`]
  195. if (typeof cur[`${dataIndex}`] == 'number') {
  196. return math.add(prev, cur[`${dataIndex}`] as number);
  197. }
  198. }, 0);
  199. return (
  200. //<span>{typeof total == 'number'?math.format(total, {precision: 14}) : '合计'}</span>
  201. <span>{typeof total == 'number' ? Number(total.toFixed(4)) : '合计'}</span>
  202. )
  203. }
  204. return (
  205. <Table.Summary fixed>
  206. <Table.Summary.Row>
  207. {
  208. tableColumn.map((item, index) => {
  209. return (
  210. <Table.Summary.Cell key={index} index={index} align='center' rowSpan={1} >
  211. <Caculate colData={item} />
  212. </Table.Summary.Cell >
  213. )
  214. })
  215. }
  216. </Table.Summary.Row>
  217. </Table.Summary>
  218. );
  219. }}
  220. />}
  221. </div>
  222. </div>
  223. </BMSPagecontainer>
  224. )
  225. }
  226. export default OneBatch