完善新版开单交互与移动布局,修复纸单号复制反馈

This commit is contained in:
黄健铭 committed 2026-12-04 21:52:39 -08:00
1 parent c594bf296f
commit f1a4e69f0d
20 files changed
+567 -91

No files matched your search

@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Alert, App as AntApp, Button, Spin, Typography } from 'antd';
import { Alert, App as AntApp, Button, Popconfirm, Spin, Typography } from 'antd';
import { ClearOutlined } from '@ant-design/icons';
import type { ApiError, LedgerClient, PendingJob } from '../../lib/api';
import { clearDraft, loadDraft } from '../../lib/drafts';
@@ -188,6 +188,36 @@ function CreateOrderForm({
setError('');
reset(null);
}
const hasDraftInput = useMemo(
() =>
Boolean(
form.id ||
form.customer.trim() ||
form.customer_type ||
form.note.trim() ||
form.internal_note.trim() ||
(form.discount.trim() && form.discount.trim() !== '0') ||
form.lines.length > 1 ||
form.lines.some(
line =>
line.quantity.trim() ||
line.goldPrice.trim() ||
line.laborRate.trim() ||
line.baseSale.trim() ||
line.charges.length > 0,
) ||
form.feeRows.length > 0 ||
Object.values(form.presets?.checked || {}).some(Boolean),
),
[form],
);
const feeCount = useMemo(() => {
const presetCount = Object.values(form.presets?.checked || {}).filter(Boolean).length;
return presetCount + form.feeRows.length;
}, [form.presets, form.feeRows.length]);
const jumpTo = useCallback((id: string) => {
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, []);
if (issued)
return (
@@ -206,9 +236,35 @@ function CreateOrderForm({
<Typography.Title level={1}>开一张新单</Typography.Title>
<Typography.Paragraph type="secondary">开单即交付,一次记录全额收款、实际费用、出库和利润。</Typography.Paragraph>
</div>
<Button icon={<ClearOutlined />} data-action="clear-draft" disabled={busy} onClick={startNew}>
清空表单
</Button>
{hasDraftInput ? (
<Popconfirm
title="确定清空当前表单?"
description="已填写的商品、费用与备注都会清除,且无法撤销。"
okText="确认清空"
cancelText="保留"
okButtonProps={{ danger: true }}
onConfirm={() => {
startNew();
message.success('表单已清空');
}}
>
<Button icon={<ClearOutlined />} data-action="clear-draft" disabled={busy}>
清空表单
</Button>
</Popconfirm>
) : (
<Button
icon={<ClearOutlined />}
data-action="clear-draft"
disabled={busy}
onClick={() => {
startNew();
message.info('当前表单已是空白');
}}
>
清空表单
</Button>
)}
</div>
{pending && (
<Alert
@@ -248,6 +304,22 @@ function CreateOrderForm({
update={update}
reset={draft => reset(draft)}
/>
<nav className="section-nav" aria-label="表单分区快捷跳转">
<button type="button" className="section-pill" onClick={() => jumpTo('section-customer')}>
<span className="section-pill-no">01</span> 客户与单据
</button>
<button type="button" className="section-pill" onClick={() => jumpTo('section-lines')}>
<span className="section-pill-no">02</span> 商品明细
<span className="section-pill-badge">{form.lines.length}</span>
</button>
<button type="button" className="section-pill section-pill-internal" onClick={() => jumpTo('section-fees')}>
<span className="section-pill-no">03</span> 实际费用
{feeCount > 0 ? <span className="section-pill-badge">{feeCount}</span> : null}
</button>
<button type="button" className="section-pill" onClick={() => jumpTo('section-summary')}>
<span className="section-pill-no">04</span> 优惠与备注
</button>
</nav>
<form
id="order-form"
ref={formRef}
@@ -276,7 +348,14 @@ function CreateOrderForm({
update={update}
onError={text => message.error(text)}
/>
<SubmitBar form={form} summary={summary} busy={busy} error={error} />
<SubmitBar
form={form}
summary={summary}
busy={busy}
error={error}
onClearError={() => setError('')}
onLocateError={() => focusInvalidField(formRef.current, error)}
/>
</fieldset>
</form>
</div>
@@ -23,6 +23,7 @@ export function CustomerSection({
const card = form.payment.method === '信用卡';
return (
<Section
id="section-customer"
step="01"
title="客户与单据"
help="生成单据即按成交合计记录全额收款,同时按所选货盘扣减黄金库存并计入实际利润。请核对商品已交付,选择实际收款方式与收款人;业务日期作为收款和出库日期。"
@@ -202,11 +202,18 @@ function TemplatePanel({
aria-label="选择模板"
data-testid="template-select"
style={{ minWidth: 220 }}
allowClear
value={selected || undefined}
placeholder={rows ? '选择后自动填入预设' : '正在读取模板…'}
disabled={!rows}
options={(rows || []).map(row => ({ value: row.id, label: row.name }))}
onChange={id => apply(id).catch(err => setStatus({ text: (err as Error).message, error: true }))}
onChange={id => {
if (!id) {
setSelected('');
return;
}
apply(id).catch(err => setStatus({ text: (err as Error).message, error: true }));
}}
/>
<Button onClick={() => setDialog({ kind: 'new', name: '', error: '' })}>保存为新模板</Button>
<Button
@@ -240,9 +247,11 @@ function TemplatePanel({
<Input
aria-label="模板名称"
maxLength={60}
autoFocus
placeholder="例如:足金手链常用报价"
value={dialog?.name || ''}
onChange={event => setDialog(current => current && { ...current, name: event.target.value })}
onPressEnter={() => void save()}
/>
{dialog?.error && <Alert type="error" showIcon message={dialog.error} style={{ marginTop: 12 }} />}
</Modal>
@@ -312,12 +321,28 @@ function FormulaPanel({ form, ctx, update }: { form: OrderForm; ctx: SyncContext
placeholder={'0.79×822+120=769\n0.58×(822+45)+55=558\n769+558=1327'}
value={text}
onChange={event => setText(event.target.value)}
onKeyDown={event => {
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter' && text.trim()) {
event.preventDefault();
fill(false);
}
}}
/>
<Space style={{ marginTop: 8 }}>
<Space wrap style={{ marginTop: 8 }}>
<Button type="primary" onClick={() => fill(false)}>
识别并预填
</Button>
{result?.kind === 'warning' && <Button onClick={() => fill(true)}>按计算金额预填</Button>}
{text && (
<Button
onClick={() => {
setText('');
setResult(null);
}}
>
清空公式
</Button>
)}
</Space>
<p className="small muted">
括号内是克工费;金价乘克重后加的是一件工费,再加的金额记为附加费。合计行只校验,不增加商品。客户、货盘及内部成本仍按实际填写。
@@ -31,6 +31,7 @@ export function FeeCosts({
: `上方附加项目自动带入成本。证书默认${defaults.certificate}元、包装${defaults.packaging}元;快递按整单默认${defaults.shipping}元,均可修改。请填写实际已付金额,没有成本填0;不需要的整单费用可移除。开单时记录费用和付款人。`;
return (
<Section
id="section-fees"
step="03"
title="实际费用"
internal
@@ -41,7 +42,15 @@ export function FeeCosts({
size="small"
icon={<PlusOutlined />}
data-action="add-fee"
onClick={() => update(f => Model.addManualFee(f, state, uuid))}
onClick={() => {
update(f => Model.addManualFee(f, state, uuid));
window.requestAnimationFrame(() => {
const rows = document.querySelectorAll('.fee-row [data-field="feeNote"] input');
const last = rows[rows.length - 1] as HTMLInputElement | undefined;
last?.scrollIntoView?.({ behavior: 'smooth', block: 'nearest' });
last?.focus?.({ preventScroll: true });
});
}}
>
添加其他成本
</Button>
@@ -1,5 +1,6 @@
import { Button, Card, Result, Space, Typography } from 'antd';
import { FileTextOutlined, PlusOutlined, PrinterOutlined } from '@ant-design/icons';
import { useState } from 'react';
import { App as AntApp, Button, Card, Result, Space, Tooltip, Typography } from 'antd';
import { CheckOutlined, CopyOutlined, FileTextOutlined, PlusOutlined, PrinterOutlined } from '@ant-design/icons';
import { orderAmount } from '../../lib/format';
export interface IssuedOrder {
@@ -24,7 +25,21 @@ export function IssuedResult({
onRetry: () => void;
onNew: () => void;
}) {
const { message } = AntApp.useApp();
const [copied, setCopied] = useState(false);
const loaded = order.total !== undefined;
async function copyPaperNumber() {
if (!order.paper_number) return;
try {
await navigator.clipboard.writeText(order.paper_number);
setCopied(true);
message.success('已复制纸单号 ' + order.paper_number);
window.setTimeout(() => setCopied(false), 1800);
} catch {
setCopied(false);
message.info('请手动选择纸单号复制');
}
}
return (
<div className="issued-page">
<Card className="issued-card">
@@ -46,8 +61,22 @@ export function IssuedResult({
<dt>
<Typography.Text type="secondary">纸单号</Typography.Text>
</dt>
<dd className="issued-value num" data-testid="issued-paper-number">
{order.paper_number || '未分配'}
<dd className="issued-value-row">
<span className="issued-value num" data-testid="issued-paper-number">
{order.paper_number || '未分配'}
</span>
{order.paper_number && (
<Tooltip title={copied ? '已复制' : '复制纸单号'}>
<Button
type="text"
size="small"
className="issued-copy-btn"
aria-label="复制纸单号"
icon={copied ? <CheckOutlined /> : <CopyOutlined />}
onClick={() => void copyPaperNumber()}
/>
</Tooltip>
)}
</dd>
</div>
<div className="issued-item">
@@ -37,6 +37,7 @@ export function LineItems({
};
return (
<Section
id="section-lines"
step="02"
title="商品明细"
help="金价与工费分开填写。银饰不扣黄金货盘;外配使用店内金料时,选实际出库货盘。"
@@ -62,7 +63,15 @@ export function LineItems({
className="add-line-button"
icon={<PlusOutlined />}
data-action="add-line"
onClick={() => guarded(f => Model.addLine(f, { st: state, uuid }))}
onClick={() => {
const nextIndex = form.lines.length;
guarded(f => Model.addLine(f, { st: state, uuid }));
window.requestAnimationFrame(() => {
document
.querySelector(`[data-line="${nextIndex}"]`)
?.scrollIntoView?.({ behavior: 'smooth', block: 'nearest' });
});
}}
>
添加商品
</Button>
@@ -101,16 +110,29 @@ function LineCard({
<strong>商品 {String(index + 1).padStart(2, '0')}</strong>
<span className="line-name muted">{line.nameType === '其他' ? line.customName : line.nameType}</span>
</div>
<Button
type="text"
size="small"
icon={<DeleteOutlined />}
data-action="remove-line"
disabled={!canRemove}
onClick={onRemove}
>
移除
</Button>
<div className="line-top-right">
{line.sale && (
<span className="line-subtotal-chip num">
{line.quantity ? (
<span className="line-qty-meta">
{line.quantity}
{line.unit}
</span>
) : null}
<span>¥{line.sale}</span>
</span>
)}
<Button
type="text"
size="small"
icon={<DeleteOutlined />}
data-action="remove-line"
disabled={!canRemove}
onClick={onRemove}
>
移除
</Button>
</div>
</div>
<Row gutter={[16, 14]}>
<ChoiceField
@@ -4,6 +4,7 @@ import { Help, InternalTag } from './fields';
// 开单页分区卡片:编号(沿用旧界面 01 02… 的样式)、标题、可选说明与右侧操作;内部分区用金色左边框与暖色底。
export function Section({
id,
step,
title,
help,
@@ -13,6 +14,7 @@ export function Section({
testId,
children,
}: {
id?: string;
step: string;
title: ReactNode;
help?: ReactNode;
@@ -24,6 +26,7 @@ export function Section({
}) {
return (
<Card
id={id}
className={'panel' + (internal ? ' panel-internal' : '') + (className ? ' ' + className : '')}
data-testid={testId}
title={
@@ -1,4 +1,6 @@
import { useRef } from 'react';
import { Alert, Button, Input, Row } from 'antd';
import type { TextAreaRef } from 'antd/es/input/TextArea';
import { CheckOutlined, LockOutlined } from '@ant-design/icons';
import { Model } from '../../shared';
import type { FormSummary, OrderForm } from '../../shared';
@@ -25,8 +27,9 @@ export function SummarySection({
}) {
const shown = Model.filterNoteTags(tags, form.internal_note);
const query = /(?:^|[\s,。;、])#([\p{L}\p{N}_-]*)$/u.test(form.internal_note);
const internalNoteRef = useRef<TextAreaRef>(null);
return (
<Section step="04" title="优惠与备注">
<Section id="section-summary" step="04" title="优惠与备注">
<Row gutter={[16, 14]}>
<TextField
span={{ xs: 24, md: 8 }}
@@ -61,6 +64,7 @@ export function SummarySection({
id="order-internal-note"
>
<Input.TextArea
ref={internalNoteRef}
id="order-internal-note"
name="internal_note"
aria-label="内部备注"
@@ -75,25 +79,30 @@ export function SummarySection({
{tagsStatus ? (
<span className="small muted">{tagsStatus}</span>
) : shown.length ? (
shown.map(tag => (
<Button
key={tag}
size="small"
className="note-tag"
data-note-tag={tag}
disabled={busy}
onClick={() => {
try {
const next = Model.insertNoteTag(form.internal_note, tag);
update(f => ({ ...f, internal_note: next }));
} catch (err) {
onError((err as Error).message);
}
}}
>
{tag}
</Button>
))
shown.map(tag => {
const active = form.internal_note.includes(tag);
return (
<Button
key={tag}
size="small"
className={'note-tag' + (active ? ' note-tag-active' : '')}
data-note-tag={tag}
aria-pressed={active}
disabled={busy}
onClick={() => {
try {
const next = Model.insertNoteTag(form.internal_note, tag);
update(f => ({ ...f, internal_note: next }));
window.setTimeout(() => internalNoteRef.current?.focus(), 0);
} catch (err) {
onError((err as Error).message);
}
}}
>
{tag}
</Button>
);
})
) : (
<span className="small muted">
{query ? '没有匹配标签,可继续输入新标签。' : '暂无已保存标签,填写 #词语 并保存订单后即可复用。'}
@@ -111,18 +120,38 @@ export function SubmitBar({
summary,
busy,
error,
onClearError,
onLocateError,
}: {
form: OrderForm;
summary: FormSummary;
busy: boolean;
error: string;
onClearError?: () => void;
onLocateError?: () => void;
}) {
const discount = String(form.discount).trim();
const discountCents = /^\d+(?:\.\d{1,2})?$/.test(discount) ? Math.round(Number(discount) * 100) : 0;
return (
<div className="submit-bar" role="region" aria-label="成交合计与提交">
{error && (
<Alert type="error" showIcon message={error} className="order-error" role="alert" data-testid="order-error" />
<Alert
type="error"
showIcon
closable={!!onClearError}
onClose={onClearError}
message={error}
action={
onLocateError ? (
<Button size="small" type="link" danger onClick={onLocateError}>
定位问题项
</Button>
) : undefined
}
className="order-error"
role="alert"
data-testid="order-error"
/>
)}
<div className="submit-bar-row">
<div className="submit-total">
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { Alert, Button, Card, Form, Input, Select, Typography } from 'antd';
import { useRef, useState } from 'react';
import { Alert, Button, Card, Form, Input, Select, Typography, type InputRef } from 'antd';
import { ArrowRightOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
import { BrandMark } from '../../components/BrandMark';
import { modeLabel } from '../../lib/format';
@@ -105,6 +105,7 @@ function LoginForm({
}) {
const [member, setMember] = useState('');
const [password, setPassword] = useState('');
const passwordRef = useRef<InputRef>(null);
return (
<form
className="login-form"
@@ -122,11 +123,15 @@ function LoginForm({
value={member || undefined}
placeholder="请选择账号"
options={options.map(row => ({ value: row.member, label: row.label }))}
onChange={setMember}
onChange={value => {
setMember(value);
window.setTimeout(() => passwordRef.current?.focus(), 0);
}}
/>
</Form.Item>
<Form.Item label="密码" required>
<Input.Password
ref={passwordRef}
name="password"
aria-label="密码"
prefix={<LockOutlined className="input-icon" />}