import { useEffect, useState } from 'react' import { Button, Checkbox, DatePicker, Input, Select, message } from 'antd' import dayjs from 'dayjs' import Modal from './DraggableModal' import { FormField, FormGrid, FormSection } from './OrderFormLayout' import client, { apiPrefix, unwrap, type ApiResponse } from '../api/client' import { options } from '../pages/care/homesShared' import { statusOptions, PROGRESS_STATUS, GIFT_STATUS, GIFT_PLACE } from '../pages/care/receptionStatuses' type Props = { open: boolean selectedIds: number[] progressStatuses: string[] giftStatuses: string[] centerOptions?: string[] onCancel: () => void onSuccess: () => void } const GIFT_PLACES = Object.entries(GIFT_PLACE).map(([value, label]) => ({ value, label })) export default function ReceptionBulkModal({ open, selectedIds, progressStatuses, giftStatuses, centerOptions = [], onCancel, onSuccess, }: Props) { const [busy, setBusy] = useState(false) const [pgAdminOnly, setPgAdminOnly] = useState(false) const [pgStatus, setPgStatus] = useState() const [pgNotNotice, setPgNotNotice] = useState(false) const [pgCenterId, setPgCenterId] = useState() const [pgMemo, setPgMemo] = useState('') const [pgOpended, setPgOpended] = useState('') const [pgCanceled, setPgCanceled] = useState('') const [gPlace, setGPlace] = useState() const [gStatus, setGStatus] = useState() const [gProgressLog, setGProgressLog] = useState('') const [gDeliveryCompany, setGDeliveryCompany] = useState('') const [gTrackingNumber, setGTrackingNumber] = useState('') const [gRequested, setGRequested] = useState('') const [gSended, setGSended] = useState('') useEffect(() => { if (!open) return setPgAdminOnly(false) setPgStatus(undefined) setPgNotNotice(false) setPgCenterId(undefined) setPgMemo('') setPgOpended('') setPgCanceled('') setGPlace(undefined) setGStatus(undefined) setGProgressLog('') setGDeliveryCompany('') setGTrackingNumber('') setGRequested('') setGSended('') }, [open]) const need = () => { if (!selectedIds.length) { message.warning('대상 접수를 선택하세요.') return false } return true } const run = async (fn: () => Promise) => { setBusy(true) try { await fn() onSuccess() } catch (e: unknown) { message.error(e instanceof Error ? e.message : '일괄 처리에 실패했습니다.') } finally { setBusy(false) } } const runProgress = () => { if (!need()) return if (!pgStatus) { message.warning('진행상황을 선택하세요.') return } if (!window.confirm(`선택 ${selectedIds.length}건을 일괄 처리하시겠습니까?`)) return void run(async () => { const { data } = await client.post>(`${apiPrefix()}/homes/receptions/bulk-progress`, { ids: selectedIds, status: pgStatus, memo: pgMemo, centerId: pgCenterId || null, opended: pgOpended || null, canceled: pgCanceled || null, adminOnly: pgAdminOnly, notNotice: pgNotNotice, }) const res = unwrap(data) as { count: number } message.success(`${res.count}건 진행상황을 변경했습니다.`) }) } const runGift = () => { if (!need()) return if (!gStatus) { message.warning('사은품진행상황을 선택하세요.') return } if (!window.confirm(`선택 ${selectedIds.length}건을 일괄 처리하시겠습니까?`)) return void run(async () => { const { data } = await client.post>(`${apiPrefix()}/homes/receptions/bulk-gift`, { ids: selectedIds, place: gPlace || null, status: gStatus, giftProgressLog: gProgressLog, deliveryCompany: gDeliveryCompany || null, trackingNumber: gTrackingNumber || null, requested: gRequested || null, sended: gSended || null, }) const res = unwrap(data) as { count: number } message.success(`${res.count}건 사은품진행을 변경했습니다.`) }) } const runCenterWait = () => { if (!need()) return if (!window.confirm('입력처 정산대기로 일괄처리 하시겠습니까?')) return void run(async () => { const { data } = await client.post>(`${apiPrefix()}/homes/receptions/bulk-center-progress`, { ids: selectedIds, }) const res = unwrap(data) as { count: number } message.success(`${res.count}건을 입력처 정산대기로 변경했습니다.`) }) } return (
setPgAdminOnly(e.target.checked)}> 관리자 전용로그 ■ 관리자만 보이고 영업점은 보이지 않습니다.
setPgCenterId(v)} options={options(centerOptions.length ? centerOptions : ['본사'])} /> setPgMemo(e.target.value)} /> setPgOpended(d ? d.format('YYYY-MM-DD') : '')} style={{ width: '100%' }} /> setPgCanceled(d ? d.format('YYYY-MM-DD') : '')} style={{ width: '100%' }} />
setGStatus(v)} options={statusOptions( Object.fromEntries((giftStatuses.length ? giftStatuses : Object.keys(GIFT_STATUS)).map((c) => [c, GIFT_STATUS[c] || c])), )} /> setGProgressLog(e.target.value)} /> setGDeliveryCompany(e.target.value)} /> setGTrackingNumber(e.target.value)} /> setGRequested(d ? d.format('YYYY-MM-DD') : '')} style={{ width: '100%' }} /> setGSended(d ? d.format('YYYY-MM-DD') : '')} style={{ width: '100%' }} />

■ 개통완료된 고객중에 입력처 정산이 진행안된 고객은 입력처 정산대기로 일괄처리 진행할수 있습니다.

) }