import { useState } from 'react' import { useMutation, useQuery } from '@tanstack/react-query' import { useNavigate, useParams } from 'react-router-dom' import dayjs, { type Dayjs } from 'dayjs' import { Button, Card, DatePicker, Select, Space, Typography, message } from 'antd' import CareTable from '../../components/CareTable' import { ArrowLeftOutlined, SearchOutlined } from '@ant-design/icons' import client, { apiPrefix, unwrap, type ApiResponse } from '../../api/client' const hours = Array.from({ length: 24 }, (_, i) => ({ value: i, label: `${String(i).padStart(2, '0')}시` })) const minutes = [0, 10, 20, 30, 40, 50].map((v) => ({ value: v, label: `${String(v).padStart(2, '0')}분` })) const money = (v: unknown) => (v == null || v === '' ? '-' : Number(v).toLocaleString()) type OpenRow = Record & { id: number } export default function OpenUnitCostApplyPage() { const { id } = useParams() const navigate = useNavigate() const tableId = Number(id) const [from, setFrom] = useState(dayjs()) const [to, setTo] = useState(dayjs()) const [fromHour, setFromHour] = useState() const [fromMinute, setFromMinute] = useState() const [toHour, setToHour] = useState() const [toMinute, setToMinute] = useState() const [searched, setSearched] = useState(false) const [filters, setFilters] = useState>({}) const [selected, setSelected] = useState([]) const enabled = searched && !!filters.dateFrom && !!filters.dateTo const query = useQuery({ queryKey: ['unitcost-apply', tableId, filters], queryFn: async () => { const { data } = await client.get }>>( `${apiPrefix()}/unitcosts/${tableId}/apply-search`, { params: filters }, ) return unwrap(data) }, enabled: enabled && Number.isFinite(tableId) }) const apply = useMutation({ mutationFn: async () => { if (!selected.length) throw new Error('적용할 개통을 선택하세요.') const { data } = await client.post(`${apiPrefix()}/unitcosts/${tableId}/apply`, { ids: selected }) return unwrap(data as ApiResponse<{ updated: number }>) }, onSuccess: (data) => { message.success(`${data.updated}건에 정책단가를 적용했습니다.`) setSelected([]) query.refetch() }, onError: (e: Error) => message.error(e.message) }) const onSearch = () => { if (!from || !to) { message.warning('개통일을 선택하세요.') return } if (to.diff(from, 'day') > 2) { message.warning('최대 3일까지 조회할 수 있습니다.') return } setSearched(true) setSelected([]) setFilters({ dateFrom: from.format('YYYY-MM-DD'), dateTo: to.format('YYYY-MM-DD'), fromHour, fromMinute, toHour, toMinute }) } const tableLabel = query.data?.table ? `${query.data.table.telecom ?? ''} (${query.data.table.incompanyName ?? ''})` : '' const columns = [ { title: '개통일', dataIndex: 'opendate', width: 100 }, { title: '통신사', dataIndex: 'telecom', width: 70 }, { title: '출고처', dataIndex: 'outcompanyName', width: 110, ellipsis: true }, { title: '고객명', dataIndex: 'name', width: 90 }, { title: '종류', dataIndex: 'openhow', width: 80 }, { title: '모델명', dataIndex: 'pmodel', width: 140, ellipsis: true }, { title: '요금제', dataIndex: 'plan', width: 120, ellipsis: true }, { title: '기본정책', dataIndex: 'basicprice1', width: 100, align: 'right' as const, render: money }, ] return (

정책단가표

통신사별로 정책단가표를 작성하여 기본정책금액을 일괄적으로 적용하실 수 있습니다.

v && setFrom(v)} /> ~ v && setTo(v)} /> * 최대 3일 {!enabled ? (
단가표를 적용할 개통일자를 선택 후 검색해주세요.
(신규/MNP/기변/보상 개통자료만 검색됩니다. 유심개통제외)
) : ( <>
검색된 개통 {query.data?.total ?? 0}
setSelected(keys.map(Number)) }} pagination={{ pageSize: 15, showTotal: (total) => `총 ${total}건` }} /> )}
) }