index.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-19 15:57:26
  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,Form} from 'antd';
  11. import React, { useState, useRef } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import ProForm,{ ModalForm, ProFormText, ProFormSelect,ProFormDatePicker} from '@ant-design/pro-form';
  15. import DrawerContent from './components/DrawerContent';
  16. import CAUpload from '@/components/CAUpload/index';
  17. import { getIncomeCostDataImport,addIncomeCostDataImport,cancelIncomeCostDataImport,getIncomeCostDataImportErrList } from './service';
  18. import moment from 'moment';
  19. import 'moment/locale/zh-cn';
  20. import locale from 'antd/es/date-picker/locale/zh_CN';
  21. const IncomeCostDataImport = () => {
  22. const [currentTime, setCurrentTime] = useState(moment().format('YYYY-MM'));
  23. const columns = [
  24. {
  25. title: '所属年份',
  26. key: 'dateTime',
  27. hideInTable: true,
  28. dataIndex: 'dateTime',
  29. renderFormItem: (item, { type, defaultRender, formItemProps, fieldProps, ...rest }, form) => {
  30. if (type === 'form') {
  31. return null;
  32. }
  33. return (
  34. <Form.Item name='dateTime'>
  35. <ProFormDatePicker fieldProps={{ picker: 'month', format: (value) => { return value.format('YYYY-MM') }, locale: locale,onChange:(moment)=>{setCurrentTime(moment.format('YYYY-MM'))} }} name="dateTime" />
  36. </Form.Item>
  37. )
  38. },
  39. },
  40. {
  41. title: '文件编号',
  42. dataIndex: 'id',
  43. key: 'id',
  44. hideInSearch: true,
  45. },
  46. {
  47. title: '导入类型',
  48. dataIndex: 'fileType',
  49. key: 'fileType',
  50. hideInSearch: true,
  51. },
  52. {
  53. title: '文件名称',
  54. dataIndex: 'fileName',
  55. key: 'fileName',
  56. },
  57. {
  58. title: '所属年月',
  59. dataIndex: 'dateTime',
  60. key: 'dateTime',
  61. hideInSearch: true,
  62. render:(_,record)=>{
  63. return `${record.dateYear}-${record.dateMonth}`
  64. }
  65. },
  66. {
  67. title: '导入时间',
  68. dataIndex: 'dateTime',
  69. key: 'dateTime',
  70. hideInSearch: true,
  71. },
  72. {
  73. title: '总数',
  74. dataIndex: 'totalAmount',
  75. key: 'totalAmount',
  76. hideInSearch: true,
  77. },
  78. {
  79. title: '导入数',
  80. dataIndex: 'successAmount',
  81. key: 'successAmount',
  82. hideInSearch: true,
  83. },
  84. {
  85. title: '导入人员',
  86. dataIndex: 'userName',
  87. key: 'userName',
  88. hideInSearch: true,
  89. },
  90. {
  91. title: '下载',
  92. dataIndex: 'fileUrl',
  93. key: 'fileUrl',
  94. hideInSearch: true,
  95. render: url =>{
  96. const userData = localStorage.getItem('userData');
  97. const {token} = JSON.parse(userData);
  98. return <a href={`${url}?token=${token}`} target="_blank">下载</a>
  99. }
  100. },
  101. {
  102. title: '操作',
  103. dataIndex: 'option',
  104. valueType: 'option',
  105. render: (_, record) =>{
  106. const {errStatus,rollbackStatus} = record;
  107. return [
  108. <Button
  109. key="config"
  110. disabled={rollbackStatus==1?true:false}
  111. danger={errStatus==1?true:false}
  112. onClick={() => {
  113. optionBtnGrouphandle(errStatus,record)
  114. }}
  115. >
  116. {errStatus==1?'错误详情':'撤销导入'}
  117. </Button>
  118. ]
  119. }
  120. },
  121. ];
  122. const drawerTableColumns = [
  123. {
  124. title: '行数',
  125. dataIndex: 'total',
  126. key: 'total',
  127. width:'10%',
  128. hideInSearch: true,
  129. },
  130. {
  131. title: '错误信息',
  132. dataIndex: 'errMessage',
  133. key: 'errMessage',
  134. hideInSearch: true,
  135. }
  136. ]
  137. const [createModalVisible, handleModalVisible] = useState(false);
  138. const actionRef = useRef();
  139. const ref = useRef(); //新增表单
  140. const importFormRef = useRef(); //导入表单
  141. const [currentRow, setCurrentRow] = useState(null);
  142. const [drawerVisible,setDrawerVisible] = useState(false);
  143. const [formData,setFormData] = useState(null);
  144. /**
  145. *
  146. * @param {Number} errStatus
  147. */
  148. const optionBtnGrouphandle = async (errStatus,record)=>{
  149. console.log({errStatus,record});
  150. setCurrentRow(record);
  151. if(errStatus != 1){
  152. const {id} = record;
  153. const resp = await cancelIncomeCostDataImport({id});
  154. const {status} = resp;
  155. if(status==200){
  156. if (actionRef.current) {
  157. actionRef.current.reload();
  158. }
  159. }
  160. }else{
  161. setDrawerVisible(true);
  162. }
  163. }
  164. //获取列表
  165. const getList = async (params = {}, sort, filter) => {
  166. const {dateTime} = params
  167. const res = await getIncomeCostDataImport({...params,dateTime:dateTime?currentTime:''});
  168. // console.log({res});
  169. return {
  170. data: res.data.list,
  171. total: res.data.totalCount,
  172. success: res.success,
  173. };
  174. };
  175. //自定义上传回调
  176. const customRequestCallback = (file)=>{
  177. // console.log({file});
  178. const formData = new FormData();
  179. formData.set('file',file);
  180. setFormData(formData);
  181. if(importFormRef.current){
  182. importFormRef.current.setFieldsValue({
  183. 'formData':formData
  184. });
  185. importFormRef?.current?.submit();
  186. }
  187. }
  188. const ModalContent = ()=>{
  189. return (
  190. <ProForm
  191. formRef={importFormRef}
  192. layout={{
  193. labelCol: { span: 4 },
  194. wrapperCol: { span: 14 },
  195. }}
  196. onFinish={async (values)=>{
  197. const formData = importFormRef.current.getFieldValue('formData');
  198. const {fileType,dateTime} = values;
  199. formData.set('fileType',fileType);
  200. formData.set('dateTime',dateTime);
  201. const resp = await addIncomeCostDataImport({formData},{
  202. 'content-type':'multipart/form-data',
  203. })
  204. const {status} = resp;
  205. if(status==200){
  206. if (actionRef.current) {
  207. actionRef.current.reload();
  208. }
  209. }
  210. }}
  211. submitter={{
  212. render:false
  213. }}
  214. >
  215. <ProFormDatePicker
  216. rules={[
  217. {
  218. required: true,
  219. message:'请选择数据年月',
  220. },
  221. ]}
  222. width="sm"
  223. name="dateTime"
  224. fieldProps={{
  225. format: 'YYYY-MM',
  226. picker:'month',
  227. locale:locale
  228. }}
  229. label="数据所属年月"
  230. />
  231. <ProFormSelect
  232. rules={[
  233. {
  234. required: true,
  235. message:'请选择数据类型',
  236. },
  237. ]}
  238. options={[
  239. {
  240. value: 1,
  241. label: '成本分摊参数值',
  242. },
  243. {
  244. value: 2,
  245. label: '收入数据',
  246. },
  247. {
  248. value: 3,
  249. label: '成本数据',
  250. },
  251. ]}
  252. width="sm"
  253. name="fileType"
  254. label="选择数据类型"
  255. />
  256. </ProForm>
  257. )
  258. }
  259. const getDrawerTableList = async ()=>{
  260. // console.log({currentRow});
  261. const {id} = currentRow;
  262. const resp = await getIncomeCostDataImportErrList({id});
  263. const {status,data} = resp;
  264. if(status==200){
  265. return {
  266. data: data,
  267. success:true,
  268. };
  269. }
  270. }
  271. // useEffect(()=>{
  272. // CARequest('/api/costAccount/hosptail/list');
  273. // },[]);
  274. return (
  275. <PageContainer>
  276. <ProTable
  277. columns={columns}
  278. request={getList}
  279. actionRef={actionRef}
  280. rowKey="id"
  281. toolBarRender={() => [
  282. <CAUpload
  283. key='CAUpload'
  284. templateHrefs={[
  285. {
  286. label:'成本分摊参数模板',
  287. value:'/costAccount/excel/getShareParamTemplate'
  288. },
  289. {
  290. label:'收入数据模板',
  291. value:'/costAccount/excel/getImportIncomeProductAccountTemplate'
  292. },
  293. {
  294. label:'成本数据模板',
  295. value:'/costAccount/excel/getImportCostProductAccountTemplate'
  296. }
  297. ]}
  298. url='/costAccount/excel/importDataByFileType'
  299. importSuccessCallback={() => { }}
  300. type='dialog'
  301. content={<ModalContent />}
  302. // token={'123'}
  303. customRequestCallback={customRequestCallback}
  304. />
  305. ]}
  306. pagination={{
  307. pageSize: 10,
  308. }}
  309. search={{
  310. defaultCollapsed: false,
  311. labelWidth: 'auto',
  312. }}
  313. />
  314. <ModalForm
  315. title="新增全院其他收支设置"
  316. width="800px"
  317. labelCol={{ span: 5, offset: 3 }}
  318. layout={'horizontal'}
  319. formRef={ref}
  320. visible={createModalVisible}
  321. onVisibleChange={(bool) => {
  322. if (ref.current) {
  323. ref.current.resetFields();
  324. }
  325. handleModalVisible(bool);
  326. }}
  327. onFinish={async (value) => {
  328. const { name, isHospital, id, sign } = value;
  329. const success = await addDistrict(isHospital == 0 ? {
  330. name, isHospital, sign
  331. } : {
  332. name, isHospital, parentId: id
  333. });
  334. // console.log({ success });
  335. if (success) {
  336. handleModalVisible(false);
  337. if (actionRef.current) {
  338. actionRef.current.reload();
  339. }
  340. }
  341. }}
  342. >
  343. <ProFormSelect
  344. rules={[
  345. {
  346. required: true,
  347. message: '请选择收支类型',
  348. },
  349. ]}
  350. options={[
  351. {
  352. value: 1,
  353. label: '收入',
  354. },
  355. {
  356. value: 2,
  357. label: '支出',
  358. },
  359. ]}
  360. width="sm"
  361. name="paymentsType"
  362. label="选择收支类型"
  363. />
  364. <ProFormText
  365. rules={[
  366. {
  367. required: true,
  368. message: '请填写收支名称',
  369. },
  370. ]}
  371. width="sm"
  372. name="paymentsName"
  373. label="收支名称"
  374. />
  375. </ModalForm>
  376. <DrawerContent
  377. columns={drawerTableColumns}
  378. visible={drawerVisible}
  379. title="错误详情"
  380. currentRow={currentRow}
  381. onVisibleChange={(bool) =>{setDrawerVisible(bool);} }
  382. renderListFunc={getDrawerTableList}
  383. onFinishFunc={async (value, selectedRowKeys, selectedRows) => {
  384. }}
  385. />
  386. </PageContainer>
  387. );
  388. };
  389. export default IncomeCostDataImport;