index.jsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-13 11:38:52
  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 { Cascader, Form, Button, Drawer, Table } from 'antd';
  11. import React, { useRef, useState, useEffect } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import {
  15. ProFormDatePicker,
  16. ProFormSelect,
  17. } from '@ant-design/pro-form';
  18. import { getAfterIncomeCollectionList, getAfterIncomeCollectionTableData } from './service';
  19. import { getResponsibilityCenterList } from '@/pages/responsibilityCenter/service';
  20. import { getCostProjecttList } from '@/pages/costProjectMana/service';
  21. import moment from 'moment';
  22. import 'moment/locale/zh-cn';
  23. import locale from 'antd/es/date-picker/locale/zh_CN';
  24. import './index.less';
  25. const AfterCollectionSearch = () => {
  26. const [currentTime, setCurrentTime] = useState(moment().format('YYYY-MM'));
  27. const [selectableResponsibilityList, setSelectableResponsibilityList] = useState([]);
  28. const [selectedResponsibilityCode,setSelectedResponsibilityCode] = useState(null);
  29. const [selectedAccountingCode,setSelectedAccountingCode] = useState(null)
  30. // const [selectableCostProjectList, setSelectableCostProjectList] = useState([])
  31. const columns = [
  32. {
  33. title: '选择时间',
  34. key: 'date',
  35. hideInTable: true,
  36. dataIndex: 'date',
  37. renderFormItem: (item, { type, defaultRender, formItemProps, fieldProps, ...rest }, form) => {
  38. if (type === 'form') {
  39. return null;
  40. }
  41. return (
  42. <Form.Item >
  43. <ProFormDatePicker initialValue={currentTime} fieldProps={{ picker: 'month', format: (value) => { return value.format('YYYY-MM') }, locale: locale,onChange:(moment)=>{setCurrentTime(moment.format('YYYYMM'))} }} name="date" />
  44. </Form.Item>
  45. )
  46. },
  47. },
  48. {
  49. title: '执行责任中心',
  50. key: 'responsibilityCode',
  51. hideInTable: true,
  52. fieldProps: (form, config) => {
  53. console.log({ form, config });
  54. },
  55. dataIndex: 'responsibilityName',
  56. renderFormItem: (item, { type, defaultRender, formItemProps, fieldProps, ...rest }, form) => {
  57. // console.log({item,type, defaultRender,formItemProps, fieldProps,rest,form })
  58. if (type === 'form') {
  59. return null;
  60. }
  61. return (
  62. <Form.Item name="responsibilityCode">
  63. <Cascader options={selectableResponsibilityList}
  64. fieldNames={{
  65. label: 'responsibilityName',
  66. value: 'responsibilityCode',
  67. children: 'child',
  68. }}
  69. onChange={(val)=>{setSelectedResponsibilityCode(val[0])}}
  70. {...fieldProps}
  71. />
  72. </Form.Item>
  73. )
  74. },
  75. },
  76. {
  77. title: '成本项目',
  78. key: 'accountingCode',
  79. hideInTable: true,
  80. dataIndex: 'accountingCode',
  81. renderFormItem: (item, { type, defaultRender, formItemProps, fieldProps, ...rest }, form) => {
  82. // console.log({item,type, defaultRender,formItemProps, fieldProps,rest,form })
  83. if (type === 'form') {
  84. return null;
  85. }
  86. return (
  87. <Form.Item name="accountingCode">
  88. <ProFormSelect
  89. request={async () => {
  90. const resp = await getCostProjecttList({ pageSize: 100 });
  91. const { status, data: { list } } = resp;
  92. if (status == 200) {
  93. const arr = list.map(item => ({
  94. 'label': item.productName,
  95. 'value': item.productCode
  96. }));
  97. return arr;
  98. }
  99. }}
  100. fieldProps={{
  101. onChange:(value)=>{setSelectedAccountingCode(value)}
  102. }}
  103. width="md"
  104. name="accountingCode"
  105. />
  106. </Form.Item>
  107. )
  108. },
  109. },
  110. {
  111. title: '年份',
  112. dataIndex: 'year',
  113. key: 'year',
  114. hideInSearch: true,
  115. },
  116. {
  117. title: '月份',
  118. dataIndex: 'month',
  119. key: 'month',
  120. hideInSearch: true,
  121. },
  122. {
  123. title: '科室编码',
  124. dataIndex: 'departmentCode',
  125. key: 'departmentCode',
  126. hideInSearch: true,
  127. },
  128. {
  129. title: '科室名称',
  130. dataIndex: 'departmentName',
  131. key: 'departmentName',
  132. hideInSearch: true,
  133. },
  134. {
  135. title: '责任中心编码',
  136. dataIndex: 'responsibilityCode',
  137. key: 'responsibilityCode',
  138. hideInSearch: true,
  139. },
  140. {
  141. title: '责任中心名',
  142. dataIndex: 'responsibilityName',
  143. key: 'responsibilityName',
  144. hideInSearch: true,
  145. },
  146. {
  147. title: '会计科目编码',
  148. dataIndex: 'accountingCode',
  149. key: 'accountingCode',
  150. hideInSearch: true,
  151. },
  152. {
  153. title: '会计科目名',
  154. dataIndex: 'accountingName',
  155. key: 'accountingName',
  156. hideInSearch: true,
  157. },
  158. {
  159. title: '成本项目编码',
  160. dataIndex: 'productCode',
  161. key: 'productCode',
  162. hideInSearch: true,
  163. },
  164. {
  165. title: '成本项目名',
  166. dataIndex: 'productName',
  167. key: 'productName',
  168. hideInSearch: true,
  169. },
  170. {
  171. title: '金额',
  172. dataIndex: 'amount',
  173. key: 'amount',
  174. hideInSearch: true,
  175. },
  176. ];
  177. const actionRef = useRef();
  178. const [totalCount, setTotalCount] = useState(0);
  179. const [drawerVisible, setDrawerVisible] = useState(false);
  180. const [reportTableColumns, setReportTableColumns] = useState([]);
  181. const [totalData,setTotalData] = useState([]);
  182. //获取列表
  183. const getList = async (params = {}, sort, filter) => {
  184. const { date } = params;
  185. console.log(moment(date).format('YYYY-MM'));
  186. const res = await getAfterIncomeCollectionList({ ...params, date: moment(date).format('YYYYMM') });
  187. if (res && res.status) {
  188. const { data: { totalAmount } } = res;
  189. setTotalCount(totalAmount);
  190. return {
  191. data: res.data.list,
  192. total: res.data.totalCount,
  193. success: res.success,
  194. };
  195. }
  196. };
  197. const renderDrawerHandle = () => {
  198. setDrawerVisible(true);
  199. }
  200. const getReportData = async (params = {}, sort, filter)=>{
  201. const resp = await getAfterIncomeCollectionTableData({...params,date:currentTime,responsibilityCode:selectedResponsibilityCode,accountingCode:selectedAccountingCode});
  202. const { status, data: { titleMap, realData, totalMap } } = resp;
  203. if (status == 200) {
  204. const titleMapToArr = Object.entries(titleMap);
  205. const totalMapToArr = Object.entries(totalMap);
  206. const columns = [...titleMapToArr].map((item, index) => {
  207. if (index == 0 || index == [...titleMapToArr].length - 1) {
  208. return {
  209. title: item[1],
  210. dataIndex: item[0],
  211. key: item[0],
  212. fixed:index == 0?'left':'right',
  213. hideInSearch: true,
  214. width: 100,
  215. }
  216. }
  217. return {
  218. title: item[1],
  219. dataIndex: item[0],
  220. key: item[0],
  221. hideInSearch: true,
  222. width: 500,
  223. }
  224. });
  225. setReportTableColumns(columns);
  226. setTotalData(totalMapToArr);
  227. return Promise.resolve({
  228. data: realData,
  229. success: true,
  230. });
  231. }
  232. }
  233. useEffect(async () => {
  234. const responsibilityList = await getResponsibilityCenterList({ pageSize: 50 });
  235. const { data: { list } } = responsibilityList;
  236. setSelectableResponsibilityList(list);
  237. }, []);
  238. return (
  239. <PageContainer>
  240. <ProTable
  241. columns={columns}
  242. request={getList}
  243. actionRef={actionRef}
  244. rowKey="id"
  245. toolBarRender={() => [
  246. <Button key='reportBtn' type='primary' onClick={() => renderDrawerHandle()}>报表数据</Button>
  247. ]}
  248. pagination={{
  249. pageSize: 10,
  250. }}
  251. search={{
  252. defaultCollapsed: false,
  253. labelWidth: 'auto',
  254. }}
  255. footer={() => <a>{`合计:${totalCount}`}</a>}
  256. />
  257. <Drawer
  258. title="报表数据"
  259. placement="right"
  260. width={'90%'}
  261. destroyOnClose={true}
  262. closable={true}
  263. onClose={() => setDrawerVisible(false)}
  264. visible={drawerVisible}
  265. >
  266. <ProTable
  267. columns={reportTableColumns}
  268. request={getReportData}
  269. actionRef={actionRef}
  270. rowKey="id"
  271. bordered
  272. pagination={false}
  273. search={false}
  274. scroll={{ x: 1500, y: 300 }}
  275. summary={() => (
  276. <Table.Summary fixed >
  277. <Table.Summary.Row className="rowCell">
  278. <Table.Summary.Cell className="firstCell" index={0}>合计</Table.Summary.Cell>
  279. {
  280. totalData.map((item, index) => {
  281. return (
  282. <Table.Summary.Cell key={index} className={index == totalData.length-1 ? 'ant-table-cell ant-table-cell-fix-right ant-table-cell-fix-right-last' : 'cell'} index={index+1}>{item[1]}</Table.Summary.Cell>
  283. )
  284. })
  285. }
  286. </Table.Summary.Row>
  287. </Table.Summary>
  288. )}
  289. // footer={() => <a>{`合计:${totalCount}`}</a>}
  290. />
  291. </Drawer>
  292. </PageContainer>
  293. );
  294. };
  295. export default AfterCollectionSearch;