index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-07-21 17:25:37
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/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 { createFromIconfontCN } from '@ant-design/icons';
  12. import { ActionType } from '@ant-design/pro-components';
  13. import { ModalForm, ProFormDatePicker, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Input, message, Popconfirm, DatePicker } from 'antd';
  16. import { useEffect, useRef, useState } from 'react'
  17. import { addData, afterImport, delData, editData, getData, getSpecialImportTable, tableDataImport } from './service';
  18. import FormItem from 'antd/es/form/FormItem';
  19. import './style.less';
  20. import '../../../utils/zhongtaiA'
  21. import moment from 'moment';
  22. import 'moment/locale/zh-cn';
  23. import locale from 'antd/es/date-picker/locale/zh_CN';
  24. import { getComputeDate } from '@/pages/Home/service';
  25. import BMSUpload from '@/components/BMSUpload';
  26. const IconFont = createFromIconfontCN({
  27. scriptUrl: '',
  28. });
  29. export default function DicClassfication() {
  30. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  31. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  32. const [currentComputeDate, set_currentComputeDate] = useState<string | undefined>(undefined);
  33. const tableRef = useRef<ActionType>();
  34. const columns: ProColumns[] = [
  35. {
  36. title: '所属年月',
  37. dataIndex: 'computeDate',
  38. ellipsis: true
  39. },
  40. {
  41. title: '数据库表名称',
  42. dataIndex: 'tableNameDisplay',
  43. ellipsis: true
  44. },
  45. {
  46. title: '文件名称',
  47. dataIndex: 'fileName',
  48. ellipsis: true,
  49. renderText(text, record, index, action) {
  50. return <a href={record.url} target='_blank'>{record.fileName}</a>
  51. },
  52. },
  53. {
  54. title: '导入时间',
  55. dataIndex: 'createTime',
  56. ellipsis: true
  57. },
  58. {
  59. title: '导入人员',
  60. dataIndex: 'createUserName',
  61. ellipsis: true
  62. },
  63. {
  64. title: '操作',
  65. key: 'option',
  66. width: 120,
  67. valueType: 'option',
  68. render: (_: any, record: any) => {
  69. return [
  70. <Popconfirm
  71. title={`是否${record.importStatus == 1?'复原导入':'撤销导入'}?`}
  72. key="del"
  73. onConfirm={() => afterImportHandle(record)}
  74. >
  75. <a>{record.importStatus == 1?'复原导入':'撤销导入'}</a>
  76. </Popconfirm>
  77. ]
  78. },
  79. },
  80. ];
  81. const getCurrentComputeDate = async () => {
  82. const resp = await getComputeDate();
  83. set_currentComputeDate(resp);
  84. //set_tableDataFilterParams({...tableDataFilterParams,computeDate:resp})
  85. }
  86. const afterImportHandle =async (record:any) => {
  87. const {importStatus} = record;
  88. const resp = await afterImport(record.id,importStatus?'RECOVERY':'CANCEL');
  89. if(resp){
  90. message.success('操作成功!');
  91. tableRef.current?.reload();
  92. }
  93. }
  94. const getTableData = async (params: any) => {
  95. const { computeDate } = params;
  96. const resp = await getData({ ...params, computeDate: computeDate ? computeDate : currentComputeDate });
  97. if (resp) {
  98. return {
  99. data: resp.list,
  100. success: true,
  101. total: resp.totalCount,
  102. pageSize: resp.pageSize,
  103. totalPage: resp.totalPage,
  104. }
  105. }
  106. return []
  107. }
  108. const importData = () => {
  109. function downloadTemplate(): void {
  110. }
  111. return (
  112. <ModalForm
  113. className='SpecialDataImport-Modal'
  114. width={360}
  115. title={`导入数据`}
  116. trigger={
  117. <span key="3" className='importBtn'>导入</span>
  118. }
  119. submitter={{
  120. render: (props, defaultDoms) => {
  121. const needBtn = defaultDoms.filter((b) => {
  122. return b.key != 'rest'
  123. })
  124. return [
  125. ...needBtn,
  126. ];
  127. },
  128. }}
  129. onFinish={async (values) => {
  130. // console.log({values});
  131. const { importFile: { fileList } } = values;
  132. let formData = new FormData();
  133. formData.append('file', fileList[0].originFileObj);
  134. formData.append('computeDate', values.computeDate);
  135. formData.append('tableName', values.tableName);
  136. const resp = await tableDataImport(formData);
  137. if (resp) {
  138. tableRef.current?.reload();
  139. return true;
  140. }
  141. }}
  142. >
  143. <div className='tip'>本操作为追加导入,会保留已有的数据并将文件的所有记录追加到数据表</div>
  144. <ProFormDatePicker.Month label='所属年月' name='computeDate' width={326} rules={[{ required: true, message: '所属年月不能为空!' }]} />
  145. <ProFormSelect label='数据库表名称' name='tableName' width={326}
  146. request={async () => {
  147. const resp = await getSpecialImportTable();
  148. if (resp) {
  149. return resp.list.map((a: any) => ({
  150. label: a.name,
  151. value: a.code
  152. }))
  153. }
  154. return []
  155. }}
  156. rules={[{ required: true, message: '数据库表名称不能为空!' }]} />
  157. <FormItem name={'importFile'}>
  158. {currentComputeDate && <BMSUpload downloadTemplateFile={() => downloadTemplate()} ifShowTip={false} ifShowTemplateDownload={false} />}
  159. </FormItem>
  160. </ModalForm>
  161. )
  162. }
  163. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  164. if (type == 'ADD') {
  165. const resp = await addData({ ...formVal });
  166. if (resp) {
  167. tableRef.current?.reload();
  168. message.success('操作成功!');
  169. }
  170. }
  171. if (type == 'EDIT') {
  172. const resp = await editData({ ...formVal });
  173. if (resp) {
  174. tableRef.current?.reload();
  175. message.success('操作成功!');
  176. }
  177. }
  178. return true;
  179. }
  180. const tableDataSearchHandle = (paramName: string) => {
  181. set_tableDataFilterParams({
  182. ...tableDataFilterParams,
  183. [`${paramName}`]: tableDataSearchKeywords
  184. })
  185. }
  186. useEffect(() => {
  187. getCurrentComputeDate();
  188. }, [])
  189. return (
  190. <BMSPagecontainer className='SpecialDataImport' title={`核算年月:${currentComputeDate}`}>
  191. <div className='toolBar'>
  192. <div className='filter'>
  193. <div className='filterItem'>
  194. {(<div className='search'>
  195. <span>所属年月:</span>
  196. <DatePicker
  197. onChange={(data, dateString) => {
  198. set_tableDataFilterParams({ ...tableDataFilterParams, computeDate: dateString })
  199. }}
  200. picker='month'
  201. locale={locale}
  202. //defaultValue={moment(currentComputeDate, 'YYYY-MM')}
  203. format='YYYY-MM' placeholder="选择年月" />
  204. </div>)}
  205. </div>
  206. <div className='filterItem' style={{ marginLeft: 16 }}>
  207. <span className='label'>表名称:</span>
  208. <ProFormSelect
  209. noStyle
  210. allowClear
  211. placeholder="请选择"
  212. style={{ width: 160, marginRight: 16 }}
  213. request={async () => {
  214. const resp = await getSpecialImportTable();
  215. if (resp) {
  216. return resp.list.map((a: any) => ({
  217. label: a.name,
  218. value: a.code
  219. }))
  220. }
  221. return []
  222. }}
  223. fieldProps={{
  224. onChange(value, option) {
  225. set_tableDataFilterParams({ ...tableDataFilterParams,tableName: value })
  226. },
  227. }}
  228. />
  229. </div>
  230. </div>
  231. <div className='btnGroup'>
  232. {importData()}
  233. </div>
  234. </div>
  235. <div style={{ marginTop: 16 }}>
  236. {currentComputeDate && <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params, sort, filter) => getTableData(params)} />}
  237. </div>
  238. </BMSPagecontainer>
  239. )
  240. }