index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2024-03-18 15:52:26
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-09-06 14:00:08
  6. * @FilePath: /CostAccountingSys/src/pages/monthlyInfoCollection/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import KCIMPagecontainer from "@/components/KCIMPageContainer"
  10. import { DatePicker, message, Input, Modal, Table } from 'antd';
  11. import { Key, useEffect, useRef, useState } from "react";
  12. import moment from 'moment';
  13. import 'moment/locale/zh-cn';
  14. import locale from 'antd/es/date-picker/locale/zh_CN';
  15. import './style.less';
  16. import { KCIMLeftList } from "@/components/KCIMLeftList";
  17. import { formatMoneyNumber } from "@/utils/format";
  18. import { createFromIconfontCN } from "@ant-design/icons";
  19. import { KCIMTable } from "@/components/KCIMTable";
  20. import { ActionType, ProColumns } from "@ant-design/pro-components";
  21. import { getResponsibilityCenterList } from "../baseSetting/responsibilityCenterSet/responsibilityCenter/service";
  22. import { getIncomeCollectionReq, getTableDataReq } from "./service";
  23. import { cancelIncomeCollection, getAfterIncomeCollectionTableData, startIncomeCollection } from "../costAccounting/calcPageTemplate/service";
  24. import { useModel } from "@umijs/max";
  25. const IconFont = createFromIconfontCN({
  26. scriptUrl: '',
  27. });
  28. const tableColumn: ProColumns[] = [
  29. {
  30. title: '科室代码',
  31. ellipsis: true,
  32. dataIndex: 'departmentCode',
  33. },
  34. {
  35. title: '科室名称',
  36. ellipsis: true,
  37. dataIndex: 'departmentName',
  38. },
  39. {
  40. title: '会计科目',
  41. ellipsis: true,
  42. dataIndex: 'accountingName',
  43. },
  44. {
  45. title: '收入项目',
  46. ellipsis: true,
  47. dataIndex: 'productName',
  48. },
  49. {
  50. title: '金额',
  51. ellipsis: true,
  52. dataIndex: 'amount',
  53. renderText(num) {
  54. return formatMoneyNumber(num)
  55. },
  56. },
  57. ];
  58. const IncomeCollectionAction = () => {
  59. const tableRef = useRef<ActionType>();
  60. const { initialState,setInitialState } = useModel('@@initialState');
  61. const [computeDate, set_computeDate] = useState<string>(initialState?initialState.computeDate:'');
  62. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>({ computeDate });
  63. const [incomeCollectionData,set_incomeCollectionData] = useState<any>(undefined);
  64. const [loading, set_loading] = useState(false);
  65. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState('');
  66. const [leftTreeData, set_leftTreeData] = useState<any[]>([]);
  67. const [currentResp, set_currentResp] = useState<any>(undefined);
  68. const [currentSelectedLeftObj, set_currentSelectedLeftObj] = useState<any>(undefined);
  69. const onLeftChange = (item: any) => {
  70. set_currentSelectedLeftObj(item);
  71. // _currentSelectedLeftObj = item;
  72. }
  73. const getIncomeCollection = async ()=>{
  74. const resp = await getIncomeCollectionReq({computeDate,current:1,pageSize:100});
  75. if(resp&&resp.list.length>0){
  76. set_incomeCollectionData(resp.list[0])
  77. }else{
  78. set_incomeCollectionData(undefined)
  79. }
  80. }
  81. const getTableData = async (params: any) => {
  82. const { computeDate, responsibilityCode } = params;
  83. if (!computeDate && !responsibilityCode) return [];
  84. const resp = await getTableDataReq({ ...params, ...tableDataFilterParams });
  85. if (resp) {
  86. set_currentResp(resp);
  87. return {
  88. data: resp.list,
  89. success: true,
  90. total: resp.totalCount,
  91. pageSize: resp.pageSize,
  92. totalPage: resp.totalPage,
  93. }
  94. }
  95. return {
  96. data: [],
  97. success: true
  98. }
  99. }
  100. const tableDataSearchHandle = (paramName: string) => {
  101. set_tableDataFilterParams({
  102. ...tableDataFilterParams,
  103. [`${paramName}`]: tableDataSearchKeywords
  104. })
  105. }
  106. const getTreeData = async () => {
  107. let totalData: any[] = [];
  108. let page = 1;
  109. const pageSize = 500;
  110. const fetchPage = async (page: number) => {
  111. const resp = await getResponsibilityCenterList({ pageSize, current: page });
  112. if (resp && resp.list.length > 0) {
  113. totalData = totalData.concat(resp.list);
  114. // 如果返回的数据量等于每页的大小,说明可能还有下一页
  115. if (resp.list.length === pageSize) {
  116. await fetchPage(page + 1);
  117. }
  118. }
  119. };
  120. await fetchPage(page);
  121. set_leftTreeData([...totalData]);
  122. return totalData;
  123. };
  124. const openDataTable = async () => {
  125. set_loading(true);
  126. try {
  127. const { responsibilityCode = null } = tableDataFilterParams;
  128. const resp = await getAfterIncomeCollectionTableData(
  129. { date: `${computeDate.replace(/-/g, '')}` }
  130. );
  131. if (resp) {
  132. const { titleMap = {}, realData = [], totalMap = {} } = resp;
  133. const titleMapToArr = Object.entries(titleMap);
  134. const totalMapToArr = Object.entries(totalMap);
  135. const columns = [...titleMapToArr].map((item, index) => {
  136. if (index == 0 || index == [...titleMapToArr].length - 1) {
  137. return {
  138. title: item[1],
  139. key: item[0],
  140. dataIndex: item[0],
  141. fixed: index == 0 ? 'left' : 'right',
  142. width: 150,
  143. }
  144. }
  145. return {
  146. title: item[1],
  147. dataIndex: item[0],
  148. key: item[0],
  149. width: 150,
  150. }
  151. });
  152. set_loading(false);
  153. Modal.info({
  154. title: '报表数据',
  155. icon: '',
  156. okText: '确定',
  157. width: 800,
  158. content: (
  159. <KCIMTable
  160. rowKey='id'
  161. scroll={{ x: (columns.length) * 150, y: 450 }}
  162. columns={columns as ProColumns[]}
  163. dataSource={[...realData]}
  164. pagination={false}
  165. summary={() => (
  166. <Table.Summary fixed >
  167. <Table.Summary.Row className="rowCell">
  168. {/* <Table.Summary.Cell className="firstCell" index={0}>合计</Table.Summary.Cell> */}
  169. {
  170. totalMapToArr.map((item, index) => {
  171. return (
  172. <Table.Summary.Cell key={index} className={index == totalMapToArr.length - 1 ? 'ant-table-cell ant-table-cell-fix-right ant-table-cell-fix-right-last' : 'cell'} index={index}>{item[1] as any}</Table.Summary.Cell>
  173. )
  174. })
  175. }
  176. </Table.Summary.Row>
  177. </Table.Summary>
  178. )}
  179. />
  180. )
  181. })
  182. }
  183. } catch (err) {
  184. console.log({ err });
  185. }
  186. }
  187. const optionBtnGroupshandle = async () => {
  188. const { year, month } = incomeCollectionData?incomeCollectionData:{year:(computeDate.split('-'))[0],month:(computeDate.split('-'))[1]};
  189. if (incomeCollectionData&&incomeCollectionData.isCollection) {
  190. const resp = await cancelIncomeCollection({ year, month });
  191. if (resp) {
  192. message.success('操作成功!');
  193. getIncomeCollection();
  194. tableRef.current?.reload();
  195. }
  196. } else {
  197. Modal.confirm({
  198. title: '注意',
  199. content: '收入归集操作会覆盖已有的归集后数据,确定要继续操作?',
  200. okText: '确定',
  201. cancelText: '取消',
  202. onOk: async (...args) => {
  203. set_loading(true);
  204. const resp = await startIncomeCollection({ year, month });
  205. if (resp) {
  206. set_loading(false);
  207. message.success('操作成功!');
  208. tableRef?.current?.reload();
  209. getIncomeCollection();
  210. } else {
  211. set_loading(false);
  212. }
  213. },
  214. })
  215. }
  216. }
  217. useEffect(() => {
  218. if (currentSelectedLeftObj) {
  219. set_tableDataFilterParams({ ...tableDataFilterParams, responsibilityCode: currentSelectedLeftObj.responsibilityCode,accountFilter:'' })
  220. set_tableDataSearchKeywords('');
  221. }
  222. }, [currentSelectedLeftObj]);
  223. useEffect(()=>{
  224. getIncomeCollection();
  225. },[computeDate])
  226. useEffect(() => {
  227. getTreeData();
  228. getIncomeCollection();
  229. }, [])
  230. return (
  231. <KCIMPagecontainer className="IncomeCollectionAction" title={false}>
  232. <div className="header">
  233. <div className="search">
  234. <span>核算年月:</span>
  235. <DatePicker
  236. onChange={(data, dateString) => {
  237. set_computeDate(dateString);
  238. set_tableDataFilterParams({
  239. ...tableDataFilterParams,
  240. computeDate: dateString,
  241. accountFilter:''
  242. });
  243. setInitialState((s:any)=>({...s,computeDate: dateString,}));
  244. set_tableDataSearchKeywords('');
  245. }}
  246. picker="month"
  247. locale={locale}
  248. defaultValue={moment(computeDate, 'YYYY-MM')}
  249. format="YYYY-MM"
  250. placeholder="选择年月"
  251. />
  252. </div>
  253. <div className="btnGroup">
  254. <span className="check" onClick={() => openDataTable()}>报表数据</span>
  255. <span className="oneKeyGet" onClick={() => optionBtnGroupshandle()}>{(incomeCollectionData&&incomeCollectionData.isCollection) ? '撤销归集' : '开始归集'}</span>
  256. </div>
  257. </div>
  258. <div className="pageContent">
  259. <div className="line">
  260. <div className="info">
  261. <img src={require('../../../static/multiblock.png')} alt="" />
  262. 全部科室合计:
  263. <span>{currentResp ? formatMoneyNumber(currentResp.totalAmount) : '0.00'}元</span>
  264. </div>
  265. </div>
  266. <div className="contentWrapper">
  267. <div className="left">
  268. <KCIMLeftList
  269. fieldNames={{ title: 'responsibilityName', key: 'responsibilityCode', children: 'child' }}
  270. rowKey={'responsibilityCode'}
  271. contentH={`calc(100vh - 270px)`}
  272. dataSource={leftTreeData} searchKey={'responsibilityName'} onChange={onLeftChange}
  273. placeholder={'责任中心'} listType={'tree'}
  274. icon={undefined}
  275. />
  276. </div>
  277. <div className="right">
  278. <div className="toolBar" style={{ display: 'flex' }}>
  279. <div className="leftTool">当前科室合计:<span>{currentResp ? formatMoneyNumber(currentResp.departmentAmount) ? currentResp.departmentAmount : '0.00' : '0.00'}元</span></div>
  280. <div className="rightTool">
  281. <div className='filterItem' style={{ marginLeft: 16, width: 233 }}>
  282. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  283. <Input placeholder={'会计科目代码/名称'} allowClear value={tableDataSearchKeywords}
  284. suffix={
  285. <IconFont type="iconsousuo" style={{ color: '#99A6BF' }} onClick={() => tableDataSearchHandle(`accountFilter`)} />
  286. }
  287. onChange={(e) => {
  288. set_tableDataSearchKeywords(e.target.value);
  289. if (e.target.value.length == 0) {
  290. set_tableDataFilterParams({
  291. ...tableDataFilterParams,
  292. 'accountFilter': ''
  293. });
  294. }
  295. }}
  296. onPressEnter={(e) => {
  297. set_tableDataFilterParams({
  298. ...tableDataFilterParams,
  299. 'accountFilter': ((e.target) as HTMLInputElement).value
  300. });
  301. }}
  302. />
  303. </div>
  304. </div>
  305. </div>
  306. <KCIMTable actionRef={tableRef} columns={tableColumn}
  307. rowKey='id'
  308. request={(params) => getTableData(params)}
  309. tableAlertRender={false}
  310. scroll={{ x: scrollX,y:`calc(100vh - 322px)` }}
  311. params={tableDataFilterParams}
  312. />
  313. </div>
  314. </div>
  315. </div>
  316. </KCIMPagecontainer>
  317. )
  318. }
  319. export default IncomeCollectionAction