import type { ButtonHTMLAttributes, InputHTMLAttributes, ReactNode, SelectHTMLAttributes } from 'react'; import type { ChargeState, LedgerState } from '../../shared'; interface TextField extends Omit, 'name' | 'value'> { label: ReactNode; name: string; value?: string | number | null; update?: (value: string) => void; } type Option = string | readonly [string, string, boolean?]; interface ChoiceProps extends Omit, 'value'> { label: ReactNode; value?: string | null; options: readonly Option[]; update?: (value: string) => void; } interface CheckProps extends Omit, 'value'> { value?: boolean; update: (v: boolean) => void; } import type { LockPayment } from './formValues'; interface PaymentProps { state: LedgerState; payment: LockPayment; change: (p: LockPayment) => void; } import { Model, Cards } from '../../shared'; import { LedgerButton, LedgerInput, LedgerSelect } from '../../components/BusinessControls'; export function Field({ label, name, value = '', type = 'text', update, hidden = false, children, ...props }: TextField) { return ( ); } export function Money(props: TextField) { return ; } export function Choice({ label, name, value, options, update, children, hidden, ...props }: ChoiceProps) { return ( ); } export function Check({ name, value, update, children, hidden, ...props }: CheckProps) { return ( ); } export function Act({ name, onClick, children, className = '', ...props }: ButtonHTMLAttributes) { return ( {children} ); } export function Heading({ title, kicker, desc, children, }: { title: string; kicker: string; desc: string; children?: ReactNode; }) { return (
{kicker}

{title}

{desc}

{children}
); } export function Charges({ rows, change, title = '客户附加项目(选填)', restore, }: { rows: ChargeState[]; change: (rows: ChargeState[]) => void; title?: string; restore?: (i: number) => void; }) { const set = (i: number, charge: ChargeState) => change(rows.map((r, n) => (n === i ? charge : r))); return (
{title} change([...rows, Model.newCharge({}, () => crypto.randomUUID())])}> + 添加附加项目
{rows.map((r, i) => (
set(i, Model.changeChargeType(r, v))} />
))}
); } export function AccountFields({ state, payment, change, methodLabel = '收款方式', recipientLabel = '收款人', disabled = false, required = false, }: PaymentProps & { methodLabel?: string; recipientLabel?: string; disabled?: boolean; required?: boolean }) { const card = payment.method === '信用卡'; return ( <> change({ ...payment, method })} options={Model.paymentMethods(state)} disabled={disabled} required={required} /> change({ ...payment, recipient })} disabled={card || disabled} required={required} > {Model.creditCardAvailable(state) && ( )} ); } export function CardPreview({ id, state, payment, cents, change, enabled = true, }: PaymentProps & { id: string; cents: number | null; enabled?: boolean }) { const visible = enabled && payment.method === '信用卡', rate = Model.creditCardRate(state); let amount = null; if (visible && cents !== null && Number.isSafeInteger(cents) && cents >= 0) amount = Cards.amount(cents, rate); return ( ); }