/* * @Author: code4eat awesomedema@gmail.com * @Date: 2023-03-03 11:30:33 * @LastEditors: code4eat awesomedema@gmail.com * @LastEditTime: 2024-07-31 15:01:30 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ import KCIMPagecontainer from '@/components/KCIMPageContainer'; import { KCIMTable } from '@/components/KCIMTable'; import { createFromIconfontCN } from '@ant-design/icons'; import { ActionType, ProFormInstance, ProFormText, ProFormSelect, ProFormCascader, ProFormDigit, ProFormDatePicker } from '@ant-design/pro-components'; import { ModalForm } from '@ant-design/pro-form' import { ProColumns } from '@ant-design/pro-table'; import { Input, message, Popconfirm, Dropdown } from 'antd'; import type { MenuProps } from 'antd'; import { Key, useEffect, useRef, useState } from 'react'; import 'moment/locale/zh-cn'; import locale from 'antd/es/date-picker/locale/zh_CN'; import { addData, calculateMonthCostShareData, copyMonthCostShareData, delData, editData, getMonthCostShareDataList } from './service'; import './style.less'; import moment from 'moment'; import { getCostshareparamList } from '../costAllocationParamsSet/service'; import { getResponsibilityCenterList } from '../../responsibilityCenterSet/responsibilityCenter/service'; import { renameChildListToChildren } from '@/utils/tooljs'; import { tableColumnsWidObj } from '@/constant'; const IconFont = createFromIconfontCN({ scriptUrl: '', }); const currentData = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`; export default function CostAllocationParamsDeal( { date, ifShowGetBtn, ifShowCancelBtn,responsibilityCode, cancelHandle,getHandle }: { date: string, ifShowGetBtn: boolean, ifShowCancelBtn: boolean,responsibilityCode:string, cancelHandle: () => Promise, getHandle:() => Promise, } ) { const [tableDataFilterParams, set_tableDataFilterParams] = useState({ computeDate: currentData }); const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState(''); const tableRef = useRef(); const formRef = useRef(); const [computeDate, set_computeDate] = useState(currentData); const [currentEditRow, set_currentEditRow] = useState(undefined); const columns: ProColumns[] = [ { title: '分摊参数', dataIndex: 'shareParamName', renderText(text, record, index, action) { const {shareParamCode,shareParamName} = record; return `[${shareParamCode}]${shareParamName}` }, }, { title: '数值', dataIndex: 'valueNum', renderText(num, record, index, action) { return (
{ (currentEditRow && currentEditRow.id == record.id) && ( <> updateTable({ ...record, ...currentEditRow }, 'EDIT')} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../static/confirmIcon.png')} /> ) } { (!currentEditRow || (currentEditRow && currentEditRow.id != record.id)) && ( <>
{num}
set_currentEditRow(record)} style={{ width: 16, height: 16, display: 'inline-block', marginLeft: 8, cursor: 'pointer' }} src={require('../../../../../static/editIcon.png')} /> ) }
) }, }, { title: '责任中心', dataIndex: 'responsibilityName', renderText(text, record, index, action) { const {responsibilityCode,responsibilityName} = record; return `[${responsibilityCode}]${responsibilityName}` }, }, { title: '操作', key: 'option', width: 90, fixed: 'right', valueType: 'option', render: (_: any, record: any) => { return [ , delTableData(record)} > 删除 ] }, }, ] const items: MenuProps['items'] = [ { key: '1', label: ( cancelHandle().then((isok)=>{ if(isok)tableRef.current?.reload(); })} style={{ display: ifShowCancelBtn ? 'inline-block' : 'none' }}> 撤销 ), }, { key: '2', label: ( getHandle().then((isok)=>{ if(isok){ tableRef.current?.reload() }; })} style={{ display: ifShowGetBtn ? 'inline-block' : 'none' }}> 获取 ), }, ]; const getTableData = async (params: any) => { const {computeDate,responsibilityCode} = params; if(computeDate&&responsibilityCode){ const resp = await getMonthCostShareDataList({ ...params }); if (resp) { return { data: resp.list, success: true, total: resp.totalCount, pageSize: resp.pageSize, totalPage: resp.totalPage, } } } return [] } const delTableData = async (record: any) => { const resp = await delData([record.id]); if (resp) { message.success('操作成功!'); tableRef.current?.reload(); // message.success('操作成功!'); } } const tableDataSearchHandle = (paramName: string) => { set_tableDataFilterParams({ ...tableDataFilterParams, [`${paramName}`]: tableDataSearchKeywords }) } const updateTable = async (formVal: any, type: 'EDIT' | "ADD" | "COPY") => { const result = { date: computeDate.replace('-', ''), shareParamCode: formVal.shareParamCode, valueNum: formVal.valueNum, }; if (type == 'ADD') { const resp = await addData({ ...result, responsibilityCode: formVal.responsibilityCode[formVal.responsibilityCode.length - 1] }); if (resp) { tableRef.current?.reload(); message.success('操作成功!'); } } if (type == 'EDIT') { try { const resp = await editData({ ...result, id: formVal.id, responsibilityCode: typeof formVal.responsibilityCode == 'string' ? formVal.responsibilityCode : formVal.responsibilityCode[formVal.responsibilityCode.length - 1] }); if (resp) { tableRef.current?.reload(); message.success('操作成功!'); } } catch (error) { console.log({ error }); } } if (type == 'COPY') { const { dataSourceType, toDate, date: fromDate } = formVal; const resp = await copyMonthCostShareData({ dataSourceType, toDate: moment(toDate).format('yyyyMM'), fromDate: moment(fromDate).format('yyyyMM') }); if (resp) { tableRef.current?.reload(); message.success('操作成功!'); } } return true; } const calculateHandle = async () => { const resp = await calculateMonthCostShareData({ date: computeDate.replace('-', '') }); if (resp) { message.success('计算成功!'); tableRef?.current?.reload(); } }; useEffect(() => { if (date&&responsibilityCode) { set_computeDate(date); set_tableDataFilterParams({ ...tableDataFilterParams, computeDate: date, responsibilityCode:responsibilityCode }); } }, [date,responsibilityCode]) const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' | 'COPY' }) => { return ( 编辑 : type == 'COPY' ? 复制 : 新增 } onFinish={(val) => { return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type); }} modalProps={{ destroyOnClose: true }} colProps={{ span: 24 }} grid > { type == 'COPY' && ( <> ) } { type != 'COPY' && ( <> { const resp = await getCostshareparamList({ ...params, pageSize: 500 }); if (resp) { return resp.list.map((item: any) => ({ label: item.shareParamName, value: item.shareParamCode })) } }} placeholder="请选择" rules={[{ required: true, message: '分摊参数是必选项!' }]} /> { const resp = await getResponsibilityCenterList({ pageSize: 500 }); if (resp) { return resp.list } return []; }} fieldProps={{ fieldNames: { label: 'responsibilityName', value: 'responsibilityCode', children: 'child', }, }} /> ) } ) } return (
检索: tableDataSearchHandle('shareParamCode')} /> } onChange={(e) => { set_tableDataSearchKeywords(e.target.value); if (e.target.value.length == 0) { set_tableDataFilterParams({ ...tableDataFilterParams, shareParamCode: '' }); } }} onPressEnter={(e) => { set_tableDataFilterParams({ ...tableDataFilterParams, shareParamCode: (e.target as HTMLInputElement).value }); }} />
{/*
{
核算年月: { set_computeDate(dateString); set_tableDataFilterParams({ ...tableDataFilterParams, computeDate: dateString, }); }} picker="month" locale={locale} defaultValue={moment(`${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}`, 'YYYY-MM')} format="YYYY-MM" placeholder="选择年月" />
}
分摊参数: { const resp = await getCostshareparamList({ ...params, pageSize: 500 }); if (resp) return resp.list.map((item: any) => ({ label: item.shareParamName, value: item.shareParamCode })) return []; }} fieldProps={{ onChange(value, option) { set_tableDataFilterParams({ ...tableDataFilterParams, shareParamCode: value }) }, }} />
责任中心: { const resp = await getResponsibilityCenterList({ pageSize: 500 }); if (resp) { return resp.list } return []; }} fieldProps={{ fieldNames: { label: 'responsibilityName', value: 'responsibilityCode', children: 'child', }, onChange(value: any, option: any) { set_tableDataFilterParams({ ...tableDataFilterParams, responsibilityCode: value ? value[value.length - 1] : '' }) }, }} />
*/}
calculateHandle()}>计算 { (ifShowCancelBtn && ifShowGetBtn) && ( ) }
getTableData(params)} />
) }