index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-10-20 17:32:10
  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 { createFromIconfontCN } from '@ant-design/icons';
  10. import {
  11. ProFormDependency,
  12. ProFormDigit,
  13. ProFormRadio,
  14. ProFormSelect,
  15. } from '@ant-design/pro-components';
  16. import { ModalForm, ProFormText } from '@ant-design/pro-form';
  17. import FormItem from 'antd/es/form/FormItem';
  18. import {DatePicker,Input} from 'antd';
  19. import { useEffect, useRef, useState } from 'react';
  20. import { getData, downloadTemplateReq, importDataPost } from './service';
  21. import './style.less';
  22. import moment from 'moment';
  23. import 'moment/locale/zh-cn';
  24. import locale from 'antd/es/date-picker/locale/zh_CN';
  25. import KCIMPagecontainer from '@/components/KCIMPageContainer';
  26. import { KCIMTable } from '@/components/KCIMTable';
  27. import KCIMUpload from '@/components/KCIMUpload';
  28. const IconFont = createFromIconfontCN({
  29. scriptUrl: '',
  30. });
  31. const currentData = `${new Date().getFullYear()}-${(new Date().getMonth()+1).toString().padStart(2, '0')}`
  32. export default function empCostDataImport() {
  33. const [computeDate,set_computeDate] = useState(currentData);
  34. const [tableDataFilterParams, set_tableDataFilterParams] = useState({computeDate:currentData});
  35. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState('');
  36. const tableRef = useRef();
  37. const columns = [
  38. {
  39. title: '工号',
  40. dataIndex: 'empCode',
  41. },
  42. {
  43. title: '姓名',
  44. dataIndex: 'empName',
  45. },
  46. {
  47. title: '总工时',
  48. dataIndex: 'hour',
  49. },
  50. {
  51. title: '固定薪资',
  52. dataIndex: 'salary',
  53. },
  54. {
  55. title: '变动薪资',
  56. dataIndex: 'variableCompensation',
  57. },
  58. {
  59. title: '总成本',
  60. dataIndex: 'cost',
  61. },
  62. ];
  63. const getTableData = async (params) => {
  64. const resp = await getData({ ...params,...tableDataFilterParams});
  65. const { status, data } = resp;
  66. if (status == 200) {
  67. const { list, totalCount, pageSize, totalPage } = data;
  68. if (resp.totalCount == 0 && resp.currPage != 1) {
  69. return getTableData({ ...params, current: resp.currPage - 1 });
  70. } else {
  71. return {
  72. data: list,
  73. success: true,
  74. total: totalCount,
  75. pageSize: pageSize,
  76. totalPage: totalPage,
  77. };
  78. }
  79. }
  80. return [];
  81. };
  82. const tableDataSearchHandle = (paramName) => {
  83. set_tableDataFilterParams({
  84. ...tableDataFilterParams,
  85. [`${paramName}`]: tableDataSearchKeywords
  86. })
  87. }
  88. const downloadTemplate = async () => {
  89. await downloadTemplateReq();
  90. };
  91. const importData = () => {
  92. return (
  93. <ModalForm
  94. width={360}
  95. title={`导入数据`}
  96. trigger={
  97. <a className="import" key="3">
  98. 导入
  99. </a>
  100. }
  101. submitter={{
  102. render: (props, defaultDoms) => {
  103. const needBtn = defaultDoms.filter((b) => {
  104. return b.key != 'rest';
  105. });
  106. return [
  107. // <Button
  108. // key="ok"
  109. // onClick={auditType == '0' ? () => downloadTemplate(index) : () => { }}
  110. // >
  111. // 下载模板
  112. // </Button>,
  113. ...needBtn,
  114. ];
  115. },
  116. }}
  117. onFinish={async (values) => {
  118. const {
  119. importFile: { fileList },
  120. } = values;
  121. let formData = new FormData();
  122. formData.append('file', fileList[0].originFileObj);
  123. formData.append('computeDate',computeDate);
  124. const resp = await importDataPost(formData);
  125. if (resp) {
  126. tableRef.current?.reload();
  127. return true;
  128. }
  129. }}
  130. >
  131. <FormItem name={'importFile'}>
  132. <KCIMUpload downloadTemplateFile={() => downloadTemplate()} />
  133. </FormItem>
  134. </ModalForm>
  135. );
  136. };
  137. useEffect(() => {}, []);
  138. return (
  139. <KCIMPagecontainer className="empCostDataImport" title={false}>
  140. <div className="toolBar">
  141. <div className="filter">
  142. <div className="filterItem">
  143. {
  144. <div className="search">
  145. <span>核算年月:</span>
  146. <DatePicker
  147. onChange={(data, dateString) => {
  148. set_computeDate(dateString);
  149. set_tableDataFilterParams({
  150. ...tableDataFilterParams,
  151. computeDate: dateString,
  152. });
  153. }}
  154. picker="month"
  155. locale={locale}
  156. defaultValue={moment(`${new Date().getFullYear()}-${(new Date().getMonth()+1).toString().padStart(2, '0')}`, 'YYYY-MM')}
  157. format="YYYY-MM"
  158. placeholder="选择年月"
  159. />
  160. </div>
  161. }
  162. </div>
  163. <div className='filterItem' style={{ marginLeft: 16, width: 205 }}>
  164. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  165. <Input placeholder={'输入工号,姓名'} allowClear
  166. suffix={
  167. <IconFont type="iconsousuo" style={{ color: '#99A6BF' }} onClick={() => tableDataSearchHandle('filter')} />
  168. }
  169. onChange={(e) => {
  170. set_tableDataSearchKeywords(e.target.value);
  171. if (e.target.value.length == 0) {
  172. set_tableDataFilterParams({
  173. ...tableDataFilterParams,
  174. filter: ''
  175. });
  176. }
  177. }}
  178. onPressEnter={(e) => {
  179. set_tableDataFilterParams({
  180. ...tableDataFilterParams,
  181. filter: e.target.value
  182. });
  183. }}
  184. />
  185. </div>
  186. </div>
  187. <div className="btnGroup">{importData()}</div>
  188. </div>
  189. <div style={{ marginTop: 16 }}>
  190. <KCIMTable
  191. columns={columns}
  192. actionRef={tableRef}
  193. rowKey="id"
  194. params={tableDataFilterParams}
  195. request={(params) => getTableData(params)}
  196. />
  197. </div>
  198. </KCIMPagecontainer>
  199. );
  200. }