Booking: choose services like in the current MIS
- «Выбор услуг» dialog: doctor's / internal / all services, funding and category filters, search, checkboxes, selected total; already added services are marked - booking form: services table with quantity, price, sum, category totals; profile's main service is added automatically; at least one service required; amount due in the summary and on the ticket - appointment sheet in Schedule: services with payment status (не оплачено / оплачено / возвращено / отказ), totals and refunds - demo price list (ОМС, платные, ДМС, внутренние) with codes from the MIS - kit: ServicePicker, ServiceLinesTable (editable and compact modes); FormField accepts className; formatMoney Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
835fa7bd99
commit
13960689fd
|
|
@ -1,5 +1,6 @@
|
|||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Label } from "@/components/ui/label"
|
||||
|
||||
/** Подзаголовок группы полей формы. */
|
||||
|
|
@ -18,16 +19,18 @@ export function FormField({
|
|||
htmlFor,
|
||||
hint,
|
||||
error,
|
||||
className,
|
||||
children,
|
||||
}: {
|
||||
label: string
|
||||
htmlFor?: string
|
||||
hint?: string
|
||||
error?: string
|
||||
className?: string
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-1.5">
|
||||
<div className={cn("space-y-1.5", className)}>
|
||||
<Label htmlFor={htmlFor}>{label}</Label>
|
||||
{children}
|
||||
{error ? (
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ export * from "./patient-picker"
|
|||
export * from "./person-chip"
|
||||
export * from "./save-bar"
|
||||
export * from "./search-input"
|
||||
export * from "./service-lines"
|
||||
export * from "./service-picker"
|
||||
export * from "./stat-tile"
|
||||
export * from "./status-badge"
|
||||
export * from "./stepper"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,194 @@
|
|||
import { MinusIcon, PlusIcon, Trash2Icon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { formatMoney } from "@/lib/format"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||
import { StatusBadge, type StatusTone } from "./status-badge"
|
||||
|
||||
export type ServiceLineStatus = "unpaid" | "paid" | "refunded" | "declined"
|
||||
|
||||
export interface ServiceLine {
|
||||
readonly code: string
|
||||
readonly name: string
|
||||
readonly category: string
|
||||
readonly price: number
|
||||
readonly quantity: number
|
||||
readonly status?: ServiceLineStatus
|
||||
}
|
||||
|
||||
export const SERVICE_LINE_STATUS: Record<ServiceLineStatus, { label: string; tone: StatusTone }> = {
|
||||
unpaid: { label: "Не оплачено", tone: "warning" },
|
||||
paid: { label: "Оплачено", tone: "positive" },
|
||||
refunded: { label: "Возвращено", tone: "negative" },
|
||||
declined: { label: "Отказ от услуги", tone: "neutral" },
|
||||
}
|
||||
|
||||
/** Возвращённые и отклонённые в итог не входят. */
|
||||
const counts = (line: ServiceLine) => line.status !== "refunded" && line.status !== "declined"
|
||||
|
||||
export function serviceLinesTotal(lines: readonly ServiceLine[]) {
|
||||
return lines.filter(counts).reduce((sum, l) => sum + l.price * l.quantity, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Таблица услуг: код и название с категорией, количество, стоимость, сумма
|
||||
* со статусом оплаты; внизу итог, разбивка по категориям и возвраты.
|
||||
* `editable` — можно менять количество и удалять строки (оформление записи),
|
||||
* `onStatusChange` — колонка «Статус услуги» (касса, приём).
|
||||
*/
|
||||
export function ServiceLinesTable({
|
||||
lines,
|
||||
editable = false,
|
||||
onQuantityChange,
|
||||
onRemove,
|
||||
onStatusChange,
|
||||
compact = false,
|
||||
className,
|
||||
}: {
|
||||
lines: readonly ServiceLine[]
|
||||
/** Узкое место (боковая панель): количество и цена — под названием. */
|
||||
compact?: boolean
|
||||
editable?: boolean
|
||||
onQuantityChange?: (code: string, quantity: number) => void
|
||||
onRemove?: (code: string) => void
|
||||
onStatusChange?: (code: string, status: ServiceLineStatus) => void
|
||||
className?: string
|
||||
}) {
|
||||
const total = serviceLinesTotal(lines)
|
||||
const refunded = lines.filter((l) => !counts(l)).reduce((sum, l) => sum + l.price * l.quantity, 0)
|
||||
const byCategory = [...new Set(lines.filter(counts).map((l) => l.category))].map((category) => ({
|
||||
category,
|
||||
sum: lines.filter((l) => counts(l) && l.category === category).reduce((s, l) => s + l.price * l.quantity, 0),
|
||||
}))
|
||||
const showStatus = lines.some((l) => l.status) || Boolean(onStatusChange)
|
||||
|
||||
return (
|
||||
<div className={cn("overflow-hidden rounded-xl border bg-card", className)}>
|
||||
<table className="w-full text-sm">
|
||||
<thead className="border-b bg-muted/40 text-left text-xs text-muted-foreground">
|
||||
<tr className="[&>th]:px-3 [&>th]:py-2 [&>th]:font-medium">
|
||||
<th>Услуга</th>
|
||||
{!compact && <th className="w-24 text-center">Кол-во</th>}
|
||||
{!compact && <th className="w-24 text-right">Стоимость</th>}
|
||||
<th className="w-28 text-right">Сумма</th>
|
||||
{onStatusChange && <th className={compact ? "w-36" : "w-44"}>Статус услуги</th>}
|
||||
{editable && onRemove && <th className="w-9" />}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-border/60">
|
||||
{lines.map((line) => {
|
||||
const status = line.status ?? "unpaid"
|
||||
const struck = !counts(line)
|
||||
return (
|
||||
<tr key={line.code} className={cn("align-top [&>td]:px-3 [&>td]:py-2.5", struck && "text-muted-foreground")}>
|
||||
<td>
|
||||
<div className={cn(struck && "line-through decoration-muted-foreground/50")}>
|
||||
<span className="font-mono text-xs text-muted-foreground">{line.code}</span> {line.name}
|
||||
</div>
|
||||
<span className="mt-1 inline-block rounded bg-muted px-1.5 py-px text-[11px] font-medium text-muted-foreground">
|
||||
{line.category}
|
||||
</span>
|
||||
{compact && line.price > 0 && (
|
||||
<span className="ml-2 text-xs text-muted-foreground tabular">
|
||||
{line.quantity} × {formatMoney(line.price)}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
{!compact && (
|
||||
<td className="text-center">
|
||||
{editable && onQuantityChange ? (
|
||||
<div className="inline-flex items-center rounded-lg border">
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Меньше"
|
||||
disabled={line.quantity <= 1}
|
||||
onClick={() => onQuantityChange(line.code, line.quantity - 1)}
|
||||
className="grid size-7 place-items-center text-muted-foreground transition hover:text-foreground disabled:opacity-30"
|
||||
>
|
||||
<MinusIcon className="size-3" />
|
||||
</button>
|
||||
<span className="w-6 text-center tabular">{line.quantity}</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Больше"
|
||||
onClick={() => onQuantityChange(line.code, line.quantity + 1)}
|
||||
className="grid size-7 place-items-center text-muted-foreground transition hover:text-foreground"
|
||||
>
|
||||
<PlusIcon className="size-3" />
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<span className="tabular">{line.quantity}</span>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
{!compact && <td className="text-right whitespace-nowrap tabular">{line.price ? formatMoney(line.price) : "—"}</td>}
|
||||
<td className="text-right whitespace-nowrap">
|
||||
<div className="font-medium tabular">{line.price ? formatMoney(line.price * line.quantity) : "ОМС"}</div>
|
||||
{showStatus && line.price > 0 && (
|
||||
<StatusBadge tone={SERVICE_LINE_STATUS[status].tone} dot={false} className="mt-1 px-1.5 text-[11px]">
|
||||
{SERVICE_LINE_STATUS[status].label}
|
||||
</StatusBadge>
|
||||
)}
|
||||
</td>
|
||||
{onStatusChange && (
|
||||
<td>
|
||||
{/* Бесплатную услугу (ОМС) оплачивать не нужно — статуса нет */}
|
||||
{line.price === 0 ? (
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
) : (
|
||||
<Select value={status} onValueChange={(v) => onStatusChange(line.code, v as ServiceLineStatus)}>
|
||||
<SelectTrigger size="sm" className="w-full" aria-label="Статус услуги">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{(Object.keys(SERVICE_LINE_STATUS) as ServiceLineStatus[]).map((s) => (
|
||||
<SelectItem key={s} value={s}>
|
||||
{SERVICE_LINE_STATUS[s].label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
{editable && onRemove && (
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Убрать ${line.name}`}
|
||||
onClick={() => onRemove(line.code)}
|
||||
className="grid size-7 place-items-center rounded-md text-muted-foreground transition hover:bg-muted hover:text-destructive"
|
||||
>
|
||||
<Trash2Icon className="size-3.5" />
|
||||
</button>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div className="space-y-1 border-t bg-muted/30 px-3 py-2.5 text-sm">
|
||||
<div className="flex items-baseline justify-end gap-6">
|
||||
<span className="text-muted-foreground">Итого</span>
|
||||
<span className="min-w-32 text-right text-base font-semibold tabular">{formatMoney(total)}</span>
|
||||
</div>
|
||||
{byCategory.length > 1 &&
|
||||
byCategory.map((c) => (
|
||||
<div key={c.category} className="flex justify-end gap-6 text-xs text-muted-foreground">
|
||||
<span>{c.category}</span>
|
||||
<span className="min-w-32 text-right tabular">{formatMoney(c.sum)}</span>
|
||||
</div>
|
||||
))}
|
||||
{refunded > 0 && (
|
||||
<div className="flex justify-end gap-6 text-xs text-coral">
|
||||
<span>Возвращено / отказ</span>
|
||||
<span className="min-w-32 text-right tabular">{formatMoney(refunded)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,221 @@
|
|||
import * as React from "react"
|
||||
import { CheckIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { formatMoney } from "@/lib/format"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
|
||||
import { ContentTabs } from "./content-tabs"
|
||||
import { SearchInput } from "./search-input"
|
||||
|
||||
export interface ServiceOption {
|
||||
readonly code: string
|
||||
readonly name: string
|
||||
readonly category: string
|
||||
readonly price: number
|
||||
readonly funding?: string
|
||||
}
|
||||
|
||||
export interface ServiceScope<T extends ServiceOption = ServiceOption> {
|
||||
readonly id: string
|
||||
readonly label: string
|
||||
readonly match: (item: T) => boolean
|
||||
}
|
||||
|
||||
const ANY = "__any"
|
||||
|
||||
/**
|
||||
* Диалог «Выбор услуг» как в МИС: набор (услуги врача / внутренние / все),
|
||||
* источник финансирования, категория, поиск, отметки и итог выбранного.
|
||||
* Уже добавленные услуги показаны отмеченными и недоступны.
|
||||
*/
|
||||
export function ServicePicker<T extends ServiceOption>({
|
||||
open,
|
||||
onOpenChange,
|
||||
items,
|
||||
scopes,
|
||||
defaultScope,
|
||||
defaultFunding,
|
||||
added = [],
|
||||
onAdd,
|
||||
title = "Выбор услуг",
|
||||
}: {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
items: readonly T[]
|
||||
scopes: readonly ServiceScope<T>[]
|
||||
defaultScope?: string
|
||||
defaultFunding?: string | null
|
||||
/** Коды уже выбранных услуг. */
|
||||
added?: readonly string[]
|
||||
onAdd: (items: T[]) => void
|
||||
title?: string
|
||||
}) {
|
||||
const [scope, setScope] = React.useState(defaultScope ?? scopes[0]?.id ?? "")
|
||||
const [funding, setFunding] = React.useState<string>(defaultFunding ?? ANY)
|
||||
const [category, setCategory] = React.useState<string>(ANY)
|
||||
const [query, setQuery] = React.useState("")
|
||||
const [selected, setSelected] = React.useState<Set<string>>(new Set())
|
||||
|
||||
// Каждое открытие — с чистого листа и с фильтрами по умолчанию.
|
||||
React.useEffect(() => {
|
||||
if (!open) return
|
||||
setScope(defaultScope ?? scopes[0]?.id ?? "")
|
||||
setFunding(defaultFunding ?? ANY)
|
||||
setCategory(ANY)
|
||||
setQuery("")
|
||||
setSelected(new Set())
|
||||
}, [open, defaultScope, defaultFunding, scopes])
|
||||
|
||||
const fundings = [...new Set(items.map((i) => i.funding).filter(Boolean))] as string[]
|
||||
const scoped = items.filter((i) => scopes.find((s) => s.id === scope)?.match(i) ?? true)
|
||||
const categories = [...new Set(scoped.map((i) => i.category))]
|
||||
const q = query.trim().toLowerCase()
|
||||
const visible = scoped.filter(
|
||||
(i) =>
|
||||
(funding === ANY || i.funding === funding) &&
|
||||
(category === ANY || i.category === category) &&
|
||||
(!q || `${i.code} ${i.name}`.toLowerCase().includes(q)),
|
||||
)
|
||||
const picked = items.filter((i) => selected.has(i.code))
|
||||
const pickedSum = picked.reduce((sum, i) => sum + i.price, 0)
|
||||
|
||||
const toggle = (code: string) =>
|
||||
setSelected((set) => {
|
||||
const next = new Set(set)
|
||||
if (next.has(code)) next.delete(code)
|
||||
else next.add(code)
|
||||
return next
|
||||
})
|
||||
|
||||
const submit = () => {
|
||||
if (!picked.length) return
|
||||
onAdd(picked)
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="flex max-h-[88vh] flex-col gap-0 p-0 sm:max-w-3xl">
|
||||
<DialogHeader className="border-b px-5 py-4">
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Отметьте услуги и нажмите «Добавить услуги»</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-2.5 border-b px-5 py-3">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<ContentTabs
|
||||
variant="pill"
|
||||
tabs={scopes.map((s) => ({ id: s.id, label: s.label, count: items.filter(s.match).length }))}
|
||||
value={scope}
|
||||
onValueChange={(v) => {
|
||||
setScope(v)
|
||||
setCategory(ANY)
|
||||
}}
|
||||
/>
|
||||
<Select value={funding} onValueChange={setFunding}>
|
||||
<SelectTrigger size="sm" className="min-w-48 flex-1" aria-label="Источник финансирования">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={ANY}>Любой источник финансирования</SelectItem>
|
||||
{fundings.map((f) => (
|
||||
<SelectItem key={f} value={f}>
|
||||
{f}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Select value={category} onValueChange={setCategory}>
|
||||
<SelectTrigger size="sm" className="w-56" aria-label="Категория услуг">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={ANY}>Все категории</SelectItem>
|
||||
{categories.map((c) => (
|
||||
<SelectItem key={c} value={c}>
|
||||
{c}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<SearchInput
|
||||
autoFocus
|
||||
size="sm"
|
||||
className="min-w-56 flex-1"
|
||||
value={query}
|
||||
onValueChange={setQuery}
|
||||
placeholder="Поиск по коду или названию"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="h-[52vh]">
|
||||
<ul className="divide-y divide-border/60">
|
||||
{visible.map((item) => {
|
||||
const already = added.includes(item.code)
|
||||
const checked = already || selected.has(item.code)
|
||||
return (
|
||||
<li key={item.code}>
|
||||
<label
|
||||
className={cn(
|
||||
"flex cursor-pointer items-start gap-3 px-5 py-2.5 transition",
|
||||
already ? "cursor-default opacity-60" : "hover:bg-muted/50",
|
||||
selected.has(item.code) && "bg-accent/40",
|
||||
)}
|
||||
>
|
||||
<Checkbox
|
||||
checked={checked}
|
||||
disabled={already}
|
||||
onCheckedChange={() => toggle(item.code)}
|
||||
className="mt-0.5"
|
||||
aria-label={item.name}
|
||||
/>
|
||||
<span className="min-w-0 flex-1 text-sm">
|
||||
<span className="font-mono text-xs text-muted-foreground">{item.code}</span>{" "}
|
||||
<span className="font-medium">{item.name}</span>
|
||||
<span className="mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground">
|
||||
{item.funding}
|
||||
<span className="rounded bg-muted px-1.5 py-px text-[11px] font-medium">{item.category}</span>
|
||||
{already && (
|
||||
<span className="inline-flex items-center gap-0.5 text-primary">
|
||||
<CheckIcon className="size-3" /> уже добавлена
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
<span className="shrink-0 text-sm font-medium tabular">
|
||||
{item.price ? formatMoney(item.price) : <span className="text-success">бесплатно</span>}
|
||||
</span>
|
||||
</label>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
{!visible.length && <li className="px-5 py-12 text-center text-sm text-muted-foreground">Услуги не найдены</li>}
|
||||
</ul>
|
||||
</ScrollArea>
|
||||
|
||||
<DialogFooter className="items-center border-t px-5 py-3 sm:justify-between">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{picked.length ? (
|
||||
<>
|
||||
Выбрано <b className="text-foreground tabular">{picked.length}</b> на{" "}
|
||||
<b className="text-foreground tabular">{formatMoney(pickedSum)}</b>
|
||||
</>
|
||||
) : (
|
||||
"Отметьте услуги в списке"
|
||||
)}
|
||||
</span>
|
||||
<Button disabled={!picked.length} onClick={submit}>
|
||||
Добавить услуги{picked.length ? ` (${picked.length})` : ""}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
|
@ -23,3 +23,8 @@ export function formatBytes(bytes: number) {
|
|||
}
|
||||
return `${value.toFixed(1)} ${units[unit]}`
|
||||
}
|
||||
|
||||
/** «1 300,00 ₽» */
|
||||
export function formatMoney(value: number) {
|
||||
return `${new Intl.NumberFormat("ru-RU", { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value)} ₽`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue