import { useRef, useState } from 'react'; import { Radio, Switch, Tag, message } from 'antd'; import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea, ProTable, type ActionType, type ProColumns, } from '@ant-design/pro-components'; import PageContainer from '@/components/common/PageContainer'; import PermissionButton from '@/components/common/PermissionButton'; import { ruleApi, ExceptionCodeResp, ExceptionCodeSaveReq } from '@/api/rule'; const DIRECTION_COLOR = { PLUS: 'success', MINUS: 'error' } as const; const CATEGORY_OPTIONS = [ { value: 'BONUS', label: '보너스' }, { value: 'PENALTY', label: '패널티' }, { value: 'ADJUSTMENT', label: '조정' }, { value: 'OTHER', label: '기타' }, ]; export default function ExceptionCodeList() { const actionRef = useRef(); const [modal, setModal] = useState<{ open: boolean; editCode?: string }>({ open: false }); const [editRecord, setEditRecord] = useState(null); const openCreate = () => { setEditRecord(null); setModal({ open: true }); }; const openEdit = (record: ExceptionCodeResp) => { setEditRecord(record); setModal({ open: true, editCode: record.exceptionCode }); }; const onSubmit = async (v: any) => { const req: ExceptionCodeSaveReq = { ...v, autoCalcYn: v.autoCalcYn ? 'Y' : 'N', approvalRequired: v.approvalRequired ? 'Y' : 'N', taxIncluded: v.taxIncluded ? 'Y' : 'N', isActive: v.isActive ? 'Y' : 'N', }; if (modal.editCode) { await ruleApi.updateExceptionCode(modal.editCode, req); message.success('수정 완료'); } else { await ruleApi.createExceptionCode(req); message.success('등록 완료'); } setModal({ open: false }); actionRef.current?.reload(); return true; }; const columns: ProColumns[] = [ { title: '예외코드', dataIndex: 'exceptionCode', width: 120, search: false, render: (_, r) => {r.exceptionCode} }, { title: '예외명', dataIndex: 'exceptionName', width: 160, search: false }, { title: '카테고리', dataIndex: 'category', width: 110, search: false }, { title: '방향', dataIndex: 'direction', width: 80, align: 'center', search: false, render: (_, r) => {r.direction === 'PLUS' ? '가산 (+)' : '차감 (-)'}, }, { title: '자동계산', dataIndex: 'autoCalcYn', width: 90, align: 'center', search: false, render: (_, r) => r.autoCalcYn === 'Y' ? 자동 : 수동, }, { title: '승인 필요', dataIndex: 'approvalRequired', width: 90, align: 'center', search: false, render: (_, r) => r.approvalRequired === 'Y' ? 필요 : 불요, }, { title: '과세', dataIndex: 'taxIncluded', width: 80, align: 'center', search: false, render: (_, r) => r.taxIncluded === 'Y' ? 과세 : 비과세, }, { title: '설명', dataIndex: 'description', ellipsis: true, search: false }, { title: '활성', dataIndex: 'isActive', width: 70, align: 'center', search: false, render: (_, r) => {r.isActive === 'Y' ? 'Y' : 'N'}, }, { title: '액션', valueType: 'option', width: 100, fixed: 'right', render: (_, r) => [ openEdit(r)}>수정, ], }, ]; return ( actionRef={actionRef} rowKey="exceptionCode" columns={columns} search={false} request={async () => { const list = await ruleApi.exceptionCodes(); return { data: list, total: list.length, success: true }; }} pagination={{ pageSize: 50, showTotal: (t) => `총 ${t}건` }} options={{ density: false, fullScreen: true, reload: true, setting: true }} toolBarRender={() => [ + 예외코드 등록, ]} dateFormatter="string" /> !o && setModal({ open: false })} width={580} layout="vertical" key={modal.editCode ?? 'new'} initialValues={editRecord ? { ...editRecord, autoCalcYn: editRecord.autoCalcYn === 'Y', approvalRequired: editRecord.approvalRequired === 'Y', taxIncluded: editRecord.taxIncluded === 'Y', isActive: editRecord.isActive === 'Y', } : { direction: 'PLUS', autoCalcYn: false, approvalRequired: false, taxIncluded: false, isActive: true }} onFinish={onSubmit} submitter={{ searchConfig: { submitText: modal.editCode ? '수정' : '등록', resetText: '취소' } }} modalProps={{ destroyOnClose: true, maskClosable: false }} > 가산 (+) 차감 (-) ); }