index.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-07-31 15:01:30
  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 KCIMPagecontainer from '@/components/KCIMPageContainer';
  10. import { KCIMTable } from '@/components/KCIMTable';
  11. import { createFromIconfontCN } from '@ant-design/icons';
  12. import { ActionType, ProFormInstance, ProFormText, ProFormSelect, ProFormCascader, ProFormDigit, ProFormDatePicker } from '@ant-design/pro-components';
  13. import { ModalForm } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Input, message, Popconfirm, Dropdown } from 'antd';
  16. import type { MenuProps } from 'antd';
  17. import { Key, useEffect, useRef, useState } from 'react';
  18. import 'moment/locale/zh-cn';
  19. import locale from 'antd/es/date-picker/locale/zh_CN';
  20. import { addData, calculateMonthCostShareData, copyMonthCostShareData, delData, editData, getMonthCostShareDataList } from './service';
  21. import './style.less';
  22. import moment from 'moment';
  23. import { getCostshareparamList } from '../costAllocationParamsSet/service';
  24. import { getResponsibilityCenterList } from '../../responsibilityCenterSet/responsibilityCenter/service';
  25. import { renameChildListToChildren } from '@/utils/tooljs';
  26. import { tableColumnsWidObj } from '@/constant';
  27. const IconFont = createFromIconfontCN({
  28. scriptUrl: '',
  29. });
  30. const currentData = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`;
  31. export default function CostAllocationParamsDeal(
  32. { date, ifShowGetBtn, ifShowCancelBtn,responsibilityCode,
  33. cancelHandle,getHandle
  34. }: { date: string, ifShowGetBtn: boolean, ifShowCancelBtn: boolean,responsibilityCode:string,
  35. cancelHandle: () => Promise<boolean>,
  36. getHandle:() => Promise<boolean>,
  37. }
  38. ) {
  39. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>({ computeDate: currentData });
  40. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  41. const tableRef = useRef<ActionType>();
  42. const formRef = useRef<ProFormInstance>();
  43. const [computeDate, set_computeDate] = useState(currentData);
  44. const [currentEditRow, set_currentEditRow] = useState<undefined | any>(undefined);
  45. const columns: ProColumns[] = [
  46. {
  47. title: '分摊参数',
  48. dataIndex: 'shareParamName',
  49. renderText(text, record, index, action) {
  50. const {shareParamCode,shareParamName} = record;
  51. return `[${shareParamCode}]${shareParamName}`
  52. },
  53. },
  54. {
  55. title: '数值',
  56. dataIndex: 'valueNum',
  57. renderText(num, record, index, action) {
  58. return (
  59. <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  60. {
  61. (currentEditRow && currentEditRow.id == record.id) && (
  62. <>
  63. <ProFormDigit
  64. width={80}
  65. noStyle
  66. fieldProps={{
  67. value: num,
  68. onChange(value) {
  69. set_currentEditRow({ ...record, valueNum: value ? value : 0 });
  70. },
  71. }}
  72. />
  73. <img onClick={() => updateTable({ ...record, ...currentEditRow }, 'EDIT')} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../static/confirmIcon.png')} />
  74. </>
  75. )
  76. }
  77. {
  78. (!currentEditRow || (currentEditRow && currentEditRow.id != record.id)) && (
  79. <>
  80. <div>{num}</div>
  81. <img onClick={() => set_currentEditRow(record)} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../static/editIcon.png')} />
  82. </>
  83. )
  84. }
  85. </div>
  86. )
  87. },
  88. },
  89. {
  90. title: '责任中心',
  91. dataIndex: 'responsibilityName',
  92. renderText(text, record, index, action) {
  93. const {responsibilityCode,responsibilityName} = record;
  94. return `[${responsibilityCode}]${responsibilityName}`
  95. },
  96. },
  97. {
  98. title: '操作',
  99. key: 'option',
  100. width: 90,
  101. fixed: 'right',
  102. valueType: 'option',
  103. render: (_: any, record: any) => {
  104. return [
  105. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  106. <Popconfirm
  107. title="是否确认删除?"
  108. key="del"
  109. onConfirm={() => delTableData(record)}
  110. >
  111. <a>删除</a>
  112. </Popconfirm>
  113. ]
  114. },
  115. },
  116. ]
  117. const items: MenuProps['items'] = [
  118. {
  119. key: '1',
  120. label: (
  121. <a onClick={()=>cancelHandle().then((isok)=>{
  122. if(isok)tableRef.current?.reload();
  123. })} style={{ display: ifShowCancelBtn ? 'inline-block' : 'none' }}>
  124. 撤销
  125. </a>
  126. ),
  127. },
  128. {
  129. key: '2',
  130. label: (
  131. <a onClick={()=>getHandle().then((isok)=>{
  132. if(isok){
  133. tableRef.current?.reload()
  134. };
  135. })} style={{ display: ifShowGetBtn ? 'inline-block' : 'none' }}>
  136. 获取
  137. </a>
  138. ),
  139. },
  140. ];
  141. const getTableData = async (params: any) => {
  142. const {computeDate,responsibilityCode} = params;
  143. if(computeDate&&responsibilityCode){
  144. const resp = await getMonthCostShareDataList({ ...params });
  145. if (resp) {
  146. return {
  147. data: resp.list,
  148. success: true,
  149. total: resp.totalCount,
  150. pageSize: resp.pageSize,
  151. totalPage: resp.totalPage,
  152. }
  153. }
  154. }
  155. return []
  156. }
  157. const delTableData = async (record: any) => {
  158. const resp = await delData([record.id]);
  159. if (resp) {
  160. message.success('操作成功!');
  161. tableRef.current?.reload();
  162. // message.success('操作成功!');
  163. }
  164. }
  165. const tableDataSearchHandle = (paramName: string) => {
  166. set_tableDataFilterParams({
  167. ...tableDataFilterParams,
  168. [`${paramName}`]: tableDataSearchKeywords
  169. })
  170. }
  171. const updateTable = async (formVal: any, type: 'EDIT' | "ADD" | "COPY") => {
  172. const result = {
  173. date: computeDate.replace('-', ''),
  174. shareParamCode: formVal.shareParamCode,
  175. valueNum: formVal.valueNum,
  176. };
  177. if (type == 'ADD') {
  178. const resp = await addData({ ...result, responsibilityCode: formVal.responsibilityCode[formVal.responsibilityCode.length - 1] });
  179. if (resp) {
  180. tableRef.current?.reload();
  181. message.success('操作成功!');
  182. }
  183. }
  184. if (type == 'EDIT') {
  185. try {
  186. const resp = await editData({ ...result, id: formVal.id, responsibilityCode: typeof formVal.responsibilityCode == 'string' ? formVal.responsibilityCode : formVal.responsibilityCode[formVal.responsibilityCode.length - 1] });
  187. if (resp) {
  188. tableRef.current?.reload();
  189. message.success('操作成功!');
  190. }
  191. } catch (error) {
  192. console.log({ error });
  193. }
  194. }
  195. if (type == 'COPY') {
  196. const { dataSourceType, toDate, date: fromDate } = formVal;
  197. const resp = await copyMonthCostShareData({ dataSourceType, toDate: moment(toDate).format('yyyyMM'), fromDate: moment(fromDate).format('yyyyMM') });
  198. if (resp) {
  199. tableRef.current?.reload();
  200. message.success('操作成功!');
  201. }
  202. }
  203. return true;
  204. }
  205. const calculateHandle = async () => {
  206. const resp = await calculateMonthCostShareData({ date: computeDate.replace('-', '') });
  207. if (resp) {
  208. message.success('计算成功!');
  209. tableRef?.current?.reload();
  210. }
  211. };
  212. useEffect(() => {
  213. if (date&&responsibilityCode) {
  214. set_computeDate(date);
  215. set_tableDataFilterParams({
  216. ...tableDataFilterParams,
  217. computeDate: date,
  218. responsibilityCode:responsibilityCode
  219. });
  220. }
  221. }, [date,responsibilityCode])
  222. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' | 'COPY' }) => {
  223. return (
  224. <ModalForm
  225. title={`${type == 'EDIT' ? '编辑' : '新增'}成本分摊参数处理`}
  226. width={350}
  227. formRef={formRef}
  228. initialValues={type == 'EDIT' ? {
  229. ...record,
  230. } : {}}
  231. trigger={
  232. type == 'EDIT' ? <a key="edit" >编辑</a> : type == 'COPY' ? <span>复制</span> : <span>新增</span>
  233. }
  234. onFinish={(val) => {
  235. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type);
  236. }}
  237. modalProps={{ destroyOnClose: true }}
  238. colProps={{ span: 24 }}
  239. grid
  240. >
  241. {
  242. type == 'COPY' && (
  243. <>
  244. <ProFormDatePicker
  245. name="date"
  246. width={318}
  247. rules={[
  248. {
  249. required: true,
  250. message: '复制时间是必填项!',
  251. },
  252. ]}
  253. label="复制数据年月"
  254. fieldProps={{ picker: 'month', locale: locale, format: 'YYYY-MM' }}
  255. />
  256. <ProFormDatePicker
  257. name="toDate"
  258. width={318}
  259. label="目标年月"
  260. rules={[
  261. {
  262. required: true,
  263. message: '目标时间是必填项!',
  264. },
  265. ]}
  266. fieldProps={{ picker: 'month', locale: locale, format: 'YYYY-MM' }}
  267. />
  268. <ProFormSelect
  269. options={[
  270. {
  271. value: 1,
  272. label: '手动输入',
  273. },
  274. {
  275. value: 2,
  276. label: '文件导入',
  277. },
  278. {
  279. value: 3,
  280. label: '全部',
  281. },
  282. ]}
  283. rules={[
  284. {
  285. required: true,
  286. message: '数据类型是必填项!',
  287. },
  288. ]}
  289. name="dataSourceType"
  290. label="数据类型"
  291. />
  292. </>
  293. )
  294. }
  295. {
  296. type != 'COPY' && (
  297. <>
  298. <ProFormSelect
  299. name="shareParamCode"
  300. label="选择分摊参数"
  301. request={async (params) => {
  302. const resp = await getCostshareparamList({ ...params, pageSize: 500 });
  303. if (resp) {
  304. return resp.list.map((item: any) => ({ label: item.shareParamName, value: item.shareParamCode }))
  305. }
  306. }}
  307. placeholder="请选择"
  308. rules={[{ required: true, message: '分摊参数是必选项!' }]}
  309. />
  310. <ProFormCascader
  311. label='责任中心'
  312. name='responsibilityCode'
  313. allowClear
  314. placeholder="请选择"
  315. request={async () => {
  316. const resp = await getResponsibilityCenterList({ pageSize: 500 });
  317. if (resp) {
  318. return resp.list
  319. }
  320. return [];
  321. }}
  322. fieldProps={{
  323. fieldNames: { label: 'responsibilityName', value: 'responsibilityCode', children: 'child', },
  324. }}
  325. />
  326. <ProFormDigit
  327. label="数值"
  328. name="valueNum"
  329. rules={[
  330. {
  331. required: true,
  332. message: '必选项!',
  333. },
  334. ]}
  335. />
  336. </>
  337. )
  338. }
  339. </ModalForm>
  340. )
  341. }
  342. return (
  343. <KCIMPagecontainer className='CostAllocationParamsDeal' title={false}>
  344. <div className='toolBar'>
  345. <div className='filter'>
  346. <div className='filterItem'>
  347. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  348. <Input placeholder={'分摊参数代码/名称'} allowClear
  349. suffix={
  350. <IconFont type="iconsousuo" style={{ color: '#99A6BF' }} onClick={() => tableDataSearchHandle('shareParamCode')} />
  351. }
  352. onChange={(e) => {
  353. set_tableDataSearchKeywords(e.target.value);
  354. if (e.target.value.length == 0) {
  355. set_tableDataFilterParams({
  356. ...tableDataFilterParams,
  357. shareParamCode: ''
  358. });
  359. }
  360. }}
  361. onPressEnter={(e) => {
  362. set_tableDataFilterParams({
  363. ...tableDataFilterParams,
  364. shareParamCode: (e.target as HTMLInputElement).value
  365. });
  366. }}
  367. />
  368. </div>
  369. {/* <div className="filterItem">
  370. {
  371. <div className="search">
  372. <span>核算年月:</span>
  373. <DatePicker
  374. onChange={(data, dateString) => {
  375. set_computeDate(dateString);
  376. set_tableDataFilterParams({
  377. ...tableDataFilterParams,
  378. computeDate: dateString,
  379. });
  380. }}
  381. picker="month"
  382. locale={locale}
  383. defaultValue={moment(`${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`, 'YYYY-MM')}
  384. format="YYYY-MM"
  385. placeholder="选择年月"
  386. />
  387. </div>
  388. }
  389. </div>
  390. <div className='filterItem' style={{ marginLeft: 16 }}>
  391. <span className='label'>分摊参数:</span>
  392. <ProFormSelect
  393. noStyle
  394. allowClear
  395. placeholder="请选择"
  396. style={{ width: 160, marginRight: 16 }}
  397. request={async (params) => {
  398. const resp = await getCostshareparamList({ ...params, pageSize: 500 });
  399. if (resp) return resp.list.map((item: any) => ({ label: item.shareParamName, value: item.shareParamCode }))
  400. return [];
  401. }}
  402. fieldProps={{
  403. onChange(value, option) {
  404. set_tableDataFilterParams({ ...tableDataFilterParams, shareParamCode: value })
  405. },
  406. }}
  407. />
  408. </div>
  409. <div className='filterItem' style={{ marginLeft: 16 }}>
  410. <span className='label'>责任中心:</span>
  411. <ProFormCascader
  412. noStyle
  413. allowClear
  414. placeholder="请选择"
  415. request={async () => {
  416. const resp = await getResponsibilityCenterList({ pageSize: 500 });
  417. if (resp) {
  418. return resp.list
  419. }
  420. return [];
  421. }}
  422. fieldProps={{
  423. fieldNames: { label: 'responsibilityName', value: 'responsibilityCode', children: 'child', },
  424. onChange(value: any, option: any) {
  425. set_tableDataFilterParams({ ...tableDataFilterParams, responsibilityCode: value ? value[value.length - 1] : '' })
  426. },
  427. }}
  428. />
  429. </div> */}
  430. </div>
  431. <div className='btnGroup'>
  432. <UpDataActBtn record type='COPY' />
  433. <span onClick={() => calculateHandle()}>计算</span>
  434. <UpDataActBtn record type='ADD' />
  435. {
  436. (ifShowCancelBtn && ifShowGetBtn) && (
  437. <Dropdown menu={{ items }} placement="bottomRight">
  438. <IconFont type="icongengduochuizhi" />
  439. </Dropdown>
  440. )
  441. }
  442. </div>
  443. </div>
  444. <div>
  445. <KCIMTable scroll={{y:`calc(100vh - 343px)`}} columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  446. </div>
  447. </KCIMPagecontainer>
  448. )
  449. }