新版开单页:编号分区卡片、内部区域金色标识、响应式网格、常用成本勾选卡片、底部常驻合计栏与校验定位
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eeea870963
commit
700bc82609
12 files changed
+529
-162
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { Button } from 'antd';
|
||||
import { CloseOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { ChargeState, LineState, OrderForm } from '../../shared';
|
||||
import { uuid } from './useOrderForm';
|
||||
import { ChoiceField, TextField } from './fields';
|
||||
import { ChoiceField, Help, TextField } from './fields';
|
||||
|
||||
type Update = (change: (form: OrderForm) => OrderForm) => void;
|
||||
|
||||
@@ -19,19 +20,24 @@ export function ChargeList({ index, line, update }: { index: number; line: LineS
|
||||
});
|
||||
return (
|
||||
<div className="sale-charges">
|
||||
<div className="panel-title">
|
||||
<strong>工费附加项目(选填)</strong>
|
||||
<div className="sub-title">
|
||||
<div className="sub-title-text">
|
||||
<strong>工费附加项目</strong>
|
||||
<span className="small muted">选填 · 编绳、证书、包装、快递</span>
|
||||
<Help label="关于工费附加项目">
|
||||
向客户收费预填:编绳55元、证书10元、包装10元、快递8元,均可修改;按填写金额自动加进本行销售额。
|
||||
</Help>
|
||||
</div>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<PlusOutlined />}
|
||||
data-action="add-charge"
|
||||
onClick={() => update(form => Model.addCharge(form, index, uuid))}
|
||||
>
|
||||
+ 添加附加项目
|
||||
添加附加项目
|
||||
</Button>
|
||||
</div>
|
||||
<p className="small muted">
|
||||
向客户收费预填:编绳55元、证书10元、包装10元、快递8元,均可修改;按填写金额自动加进本行销售额。
|
||||
</p>
|
||||
{line.charges.length > 0 && (
|
||||
<div className="charge-list">
|
||||
{line.charges.map((charge, j) => (
|
||||
<div className="charge-row" key={charge.id} data-charge={j}>
|
||||
@@ -62,6 +68,7 @@ export function ChargeList({ index, line, update }: { index: number; line: LineS
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={<CloseOutlined />}
|
||||
data-action="remove-charge"
|
||||
onClick={() =>
|
||||
update(form => {
|
||||
@@ -92,6 +99,7 @@ export function ChargeList({ index, line, update }: { index: number; line: LineS
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Alert, App as AntApp, Button, Spin, Typography } from 'antd';
|
||||
import { ClearOutlined } from '@ant-design/icons';
|
||||
import type { ApiError, LedgerClient, PendingJob } from '../../lib/api';
|
||||
import { clearDraft, loadDraft } from '../../lib/drafts';
|
||||
import { searchParam } from '../../lib/router';
|
||||
@@ -10,7 +11,8 @@ import { useOrderForm } from './useOrderForm';
|
||||
import { CustomerSection } from './CustomerSection';
|
||||
import { LineItems } from './LineItems';
|
||||
import { FeeCosts } from './FeeCosts';
|
||||
import { SummarySection } from './SummarySection';
|
||||
import { SubmitBar, SummarySection } from './SummarySection';
|
||||
import { focusInvalidField } from './invalidField';
|
||||
import { EntryTools } from './EntryTools';
|
||||
import { IssuedResult, type IssuedOrder } from './IssuedResult';
|
||||
|
||||
@@ -80,6 +82,7 @@ function CreateOrderForm({
|
||||
const [tagsStatus, setTagsStatus] = useState('正在读取快捷标签…');
|
||||
const busy = client.busy;
|
||||
const pending = client.pending();
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
|
||||
// 纸单号预览(旧页面 updatePaperNumber):旧草稿沿用原号(换日期时替换日期段),新单读取预计号码。
|
||||
const [preview, setPreview] = useState<{ date: string; number: string } | null>(null);
|
||||
@@ -126,6 +129,7 @@ function CreateOrderForm({
|
||||
if (e.code === 'ACCOUNT_CHANGED') setAccountChanged(true);
|
||||
setError(e.message);
|
||||
message.error(e.message);
|
||||
focusInvalidField(formRef.current, e.message);
|
||||
},
|
||||
[message],
|
||||
);
|
||||
@@ -198,14 +202,11 @@ function CreateOrderForm({
|
||||
<div className="create-page">
|
||||
<div className="page-heading">
|
||||
<div>
|
||||
<div className="eyebrow">NEW ORDER · 新版界面</div>
|
||||
<Typography.Title level={2}>开一张新单</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
开单即交付,一次记录全额收款、实际费用、出库和利润。订单列表、报表等其他功能请
|
||||
<a href="/">返回旧版界面</a>。
|
||||
</Typography.Paragraph>
|
||||
<div className="eyebrow">New Order · 新版界面</div>
|
||||
<Typography.Title level={1}>开一张新单</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">开单即交付,一次记录全额收款、实际费用、出库和利润。</Typography.Paragraph>
|
||||
</div>
|
||||
<Button data-action="clear-draft" disabled={busy} onClick={startNew}>
|
||||
<Button icon={<ClearOutlined />} data-action="clear-draft" disabled={busy} onClick={startNew}>
|
||||
清空表单
|
||||
</Button>
|
||||
</div>
|
||||
@@ -249,6 +250,7 @@ function CreateOrderForm({
|
||||
/>
|
||||
<form
|
||||
id="order-form"
|
||||
ref={formRef}
|
||||
className="order-form"
|
||||
noValidate
|
||||
onSubmit={event => {
|
||||
@@ -268,14 +270,13 @@ function CreateOrderForm({
|
||||
<FeeCosts form={form} state={state} summary={summary} update={update} />
|
||||
<SummarySection
|
||||
form={form}
|
||||
summary={summary}
|
||||
tags={tags}
|
||||
tagsStatus={tagsStatus}
|
||||
busy={busy}
|
||||
error={error}
|
||||
update={update}
|
||||
onError={text => message.error(text)}
|
||||
/>
|
||||
<SubmitBar form={form} summary={summary} busy={busy} error={error} />
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { Card, Typography } from 'antd';
|
||||
import { Row } from 'antd';
|
||||
import { CloudSyncOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { LedgerState, OrderForm } from '../../shared';
|
||||
import { ChoiceField, RadioField, TextField } from './fields';
|
||||
import { HALF_Q, QUARTER } from './layout';
|
||||
import { Section } from './Section';
|
||||
|
||||
// 客户与单据:业务日期、纸单号、客户、客户类型、开单人、订单归属、收款方式与收款人。
|
||||
export function CustomerSection({
|
||||
@@ -19,19 +22,29 @@ export function CustomerSection({
|
||||
const team = Model.teamMode(state);
|
||||
const card = form.payment.method === '信用卡';
|
||||
return (
|
||||
<Card
|
||||
className="panel"
|
||||
<Section
|
||||
step="01"
|
||||
title="客户与单据"
|
||||
help="生成单据即按成交合计记录全额收款,同时按所选货盘扣减黄金库存并计入实际利润。请核对商品已交付,选择实际收款方式与收款人;业务日期作为收款和出库日期。"
|
||||
extra={
|
||||
<span className="small muted">
|
||||
<span className="section-extra">
|
||||
<CloudSyncOutlined aria-hidden="true" />{' '}
|
||||
{form.id ? '补齐原草稿,生成销售单据后完成记账' : '填写内容自动暂存,生成单据即完成记账'}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<div className="grid four">
|
||||
<TextField label="业务日期" field="date" type="date" value={form.date} onChange={set('date')} />
|
||||
<TextField label="纸单编号(自动)" field="paper_number" value={paperNumber} readOnly />
|
||||
<Row gutter={[16, 14]}>
|
||||
<TextField span={HALF_Q} label="业务日期" field="date" type="date" value={form.date} onChange={set('date')} />
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="纸单编号(自动)"
|
||||
field="paper_number"
|
||||
value={paperNumber}
|
||||
readOnly
|
||||
help="前半段为业务日期,后半段序号持续累计,中间不加横线,换日期不归零;生成时分配。"
|
||||
/>
|
||||
<TextField
|
||||
span={QUARTER}
|
||||
label="客户称呼/代号(必填)"
|
||||
field="customer"
|
||||
value={form.customer}
|
||||
@@ -40,6 +53,7 @@ export function CustomerSection({
|
||||
onChange={set('customer')}
|
||||
/>
|
||||
<RadioField
|
||||
span={QUARTER}
|
||||
label={'客户类型' + (form.customerTypeRequired ? '(必选)' : '')}
|
||||
field="customer_type"
|
||||
value={form.customer_type}
|
||||
@@ -50,6 +64,7 @@ export function CustomerSection({
|
||||
onChange={set('customer_type')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="开单人(必填)"
|
||||
field="salesperson"
|
||||
value={form.salesperson}
|
||||
@@ -58,9 +73,10 @@ export function CustomerSection({
|
||||
/>
|
||||
{team &&
|
||||
(form.memberLocked ? (
|
||||
<TextField label="订单归属(经营款与业绩)" field="member" value={Model.memberName(state, form.member)} readOnly />
|
||||
<TextField span={HALF_Q} label="订单归属(经营款与业绩)" field="member" value={Model.memberName(state, form.member)} readOnly />
|
||||
) : (
|
||||
<ChoiceField
|
||||
span={HALF_Q}
|
||||
label="订单归属(经营款与业绩)"
|
||||
field="member"
|
||||
value={form.member}
|
||||
@@ -69,6 +85,7 @@ export function CustomerSection({
|
||||
/>
|
||||
))}
|
||||
<RadioField
|
||||
span={QUARTER}
|
||||
label="收款方式"
|
||||
field="payment_method"
|
||||
value={form.payment.method}
|
||||
@@ -76,6 +93,7 @@ export function CustomerSection({
|
||||
onChange={method => update(f => ({ ...f, payment: { ...f.payment, method } }))}
|
||||
/>
|
||||
<ChoiceField
|
||||
span={QUARTER}
|
||||
label="收款人"
|
||||
field="payment_recipient"
|
||||
value={form.payment.recipient}
|
||||
@@ -84,10 +102,7 @@ export function CustomerSection({
|
||||
hint={card && Model.creditCardAvailable(state) ? `信用卡统一由${Model.memberName(state, 'owner')}收款。` : undefined}
|
||||
onChange={recipient => update(f => ({ ...f, payment: { ...f.payment, recipient } }))}
|
||||
/>
|
||||
</div>
|
||||
<Typography.Paragraph type="secondary" className="small section-note">
|
||||
纸单号前半段为业务日期,后半段序号持续累计,中间不加横线,换日期不归零;生成时分配。生成单据即按成交合计记录全额收款,同时按所选货盘扣减黄金库存并计入实际利润。请核对商品已交付,选择实际收款方式与收款人;业务日期作为收款和出库日期。
|
||||
</Typography.Paragraph>
|
||||
</Card>
|
||||
</Row>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Button, Card, Checkbox, Input } from 'antd';
|
||||
import { Button, Checkbox, Input, Row } from 'antd';
|
||||
import { CloseOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { FormSummary, LedgerState, OrderForm } from '../../shared';
|
||||
import { uuid } from './useOrderForm';
|
||||
import { ChoiceField, Field, TextField } from './fields';
|
||||
import { HALF, QUARTER } from './layout';
|
||||
import { Section } from './Section';
|
||||
|
||||
type Update = (change: (form: OrderForm) => OrderForm) => void;
|
||||
|
||||
@@ -21,61 +24,84 @@ export function FeeCosts({
|
||||
const presets = form.presets;
|
||||
const catalog = Model.presetCatalogView(form, state);
|
||||
const defaults = { certificate: '4', packaging: '3', shipping: '6', ...state.shopSettings?.feeDefaults };
|
||||
return (
|
||||
<Card
|
||||
className="panel internal"
|
||||
title="实际费用(内部)"
|
||||
extra={
|
||||
<Button size="small" data-action="add-fee" onClick={() => update(f => Model.addManualFee(f, state, uuid))}>
|
||||
+ 添加其他成本
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<p className="small muted">
|
||||
{presets
|
||||
const help = presets
|
||||
? '按实际发生勾选,快递最多选一项;盒子按配置单价和数量计费。取消勾选不记成本,客户收费不受影响。'
|
||||
: form.feeCostMode === 'checkboxes'
|
||||
? '沿用本单已有费用、付款人与支付日期。普通费用按凭据核对;信用卡手续费金额和日期自动维护。'
|
||||
: `上方附加项目自动带入成本。证书默认${defaults.certificate}元、包装${defaults.packaging}元;快递按整单默认${defaults.shipping}元,均可修改。请填写实际已付金额,没有成本填0;不需要的整单费用可移除。开单时记录费用和付款人。`}{' '}
|
||||
客户单据不显示。
|
||||
</p>
|
||||
<div className="grid four">
|
||||
: `上方附加项目自动带入成本。证书默认${defaults.certificate}元、包装${defaults.packaging}元;快递按整单默认${defaults.shipping}元,均可修改。请填写实际已付金额,没有成本填0;不需要的整单费用可移除。开单时记录费用和付款人。`;
|
||||
return (
|
||||
<Section
|
||||
step="03"
|
||||
title="实际费用"
|
||||
internal
|
||||
testId="fee-costs"
|
||||
help={help + ' 客户单据不显示。'}
|
||||
extra={
|
||||
<Button
|
||||
size="small"
|
||||
icon={<PlusOutlined />}
|
||||
data-action="add-fee"
|
||||
onClick={() => update(f => Model.addManualFee(f, state, uuid))}
|
||||
>
|
||||
添加其他成本
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{!presets && <p className="small muted section-lead">{help}</p>}
|
||||
<Row gutter={[16, 14]}>
|
||||
<TextField
|
||||
span={QUARTER}
|
||||
label="费用实际支付日期"
|
||||
field="fees_date"
|
||||
type="date"
|
||||
value={form.fees_date}
|
||||
onChange={value => update(f => ({ ...f, fees_date: value }))}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
{presets && (
|
||||
<fieldset className="order-cost-presets" data-testid="cost-presets">
|
||||
<legend>常用成本 · 按实际发生勾选</legend>
|
||||
<p className="small muted">快递二选一,也可不选;取消勾选不记成本。</p>
|
||||
<legend>
|
||||
常用成本 <span className="small muted">按实际发生勾选 · 快递二选一,也可不选</span>
|
||||
</legend>
|
||||
<div className="order-cost-options">
|
||||
{catalog.length === 0 && <p>暂无启用的勾选成本,可在店铺配置中添加。</p>}
|
||||
{catalog.map(item => (
|
||||
<div className="order-cost-option" key={item.kind} data-preset={item.kind}>
|
||||
{catalog.length === 0 && <p className="muted">暂无启用的勾选成本,可在店铺配置中添加。</p>}
|
||||
{catalog.map(item => {
|
||||
const checked = !!presets.checked[item.kind];
|
||||
return (
|
||||
<div className={'order-cost-option' + (checked ? ' checked' : '')} key={item.kind} data-preset={item.kind}>
|
||||
<Checkbox
|
||||
checked={!!presets.checked[item.kind]}
|
||||
className="order-cost-check"
|
||||
checked={checked}
|
||||
onChange={event => update(f => Model.togglePreset(f, item.kind, event.target.checked, state, uuid))}
|
||||
>
|
||||
<strong>{item.name}</strong> <span className="order-cost-price">{item.price}</span>
|
||||
<small className="muted"> {item.kind === 'yt' && !presets.configured ? summary.presetNotes.ytPayer : item.payer}</small>
|
||||
<span className="order-cost-main">
|
||||
<strong>{item.name}</strong>
|
||||
<span className="order-cost-price num">{item.price}</span>
|
||||
</span>
|
||||
<small className="order-cost-payer">
|
||||
{item.kind === 'yt' && !presets.configured ? summary.presetNotes.ytPayer : item.payer}
|
||||
</small>
|
||||
</Checkbox>
|
||||
{item.byQuantity && (
|
||||
<Field label="数量(个)" field={'cost_' + item.kind + '_quantity'} hint={summary.presetNotes[item.kind]}>
|
||||
{item.byQuantity && checked && (
|
||||
<Field
|
||||
className="order-cost-quantity"
|
||||
label="数量(个)"
|
||||
field={'cost_' + item.kind + '_quantity'}
|
||||
hint={summary.presetNotes[item.kind]}
|
||||
>
|
||||
<Input
|
||||
name={'cost_' + item.kind + '_quantity'}
|
||||
aria-label={item.name + '数量(个)'}
|
||||
inputMode="numeric"
|
||||
className="num"
|
||||
value={presets.quantity[item.kind] ?? '1'}
|
||||
disabled={!presets.checked[item.kind]}
|
||||
onChange={event => update(f => Model.setPresetQuantity(f, item.kind, event.target.value))}
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</fieldset>
|
||||
)}
|
||||
@@ -116,6 +142,7 @@ export function FeeCosts({
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={<CloseOutlined />}
|
||||
data-action="remove-fee"
|
||||
onClick={() => update(f => Model.removeFeeRow(f, index))}
|
||||
>
|
||||
@@ -128,27 +155,28 @@ export function FeeCosts({
|
||||
{summary.card && (
|
||||
<div className="credit-card-preview" data-testid="credit-card-preview">
|
||||
<div className="credit-card-heading">
|
||||
<strong>信用卡手续费(内部)</strong>
|
||||
<strong>信用卡手续费</strong>
|
||||
<span className="small muted">自动计算 · 客户单据不显示</span>
|
||||
</div>
|
||||
<div className="grid two">
|
||||
<TextField label="手续费(元,自动)" field="credit_card_fee" value={summary.card.amountText} readOnly />
|
||||
<Row gutter={[16, 14]}>
|
||||
<TextField span={HALF} label="手续费(元,自动)" field="credit_card_fee" value={summary.card.amountText} readOnly />
|
||||
<ChoiceField
|
||||
span={HALF}
|
||||
label="手续费付款人"
|
||||
field="credit_card_fee_payer"
|
||||
value={form.credit_card_fee_payer}
|
||||
options={Model.memberOptions(state)}
|
||||
onChange={value => update(f => ({ ...f, credit_card_fee_payer: value }))}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
<p className="small muted" aria-live="polite">
|
||||
{summary.card.formula}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div className="small fees-total" data-testid="fees-total">
|
||||
<div className="fees-total num" data-testid="fees-total">
|
||||
{summary.feesText}
|
||||
</div>
|
||||
</Card>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Button } from 'antd';
|
||||
import { Button, Row } from 'antd';
|
||||
import { LockOutlined, ReloadOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { LedgerState, LineState, OrderForm } from '../../shared';
|
||||
import { ChoiceField, RadioField, TextField } from './fields';
|
||||
import { ChoiceField, Field, RadioField, TextField } from './fields';
|
||||
import { HALF_Q, QUARTER, THIRD } from './layout';
|
||||
|
||||
type Update = (change: (form: OrderForm) => OrderForm) => void;
|
||||
|
||||
@@ -30,9 +32,14 @@ export function InternalCosts({
|
||||
Model.memberKeys(state).includes(value) ? Model.memberOptions(state, false, { selected: value }) : payers;
|
||||
return (
|
||||
<div className="internal">
|
||||
<div className="internal-title">内部成本 · 客户单据不显示</div>
|
||||
<div className="grid two cost-source-fields">
|
||||
<div className="internal-title">
|
||||
<LockOutlined aria-hidden="true" />
|
||||
<strong>内部成本</strong>
|
||||
<span className="internal-tag">内部 · 客户不可见</span>
|
||||
</div>
|
||||
<Row gutter={[16, 14]} className="cost-source-fields">
|
||||
<ChoiceField
|
||||
span={THIRD}
|
||||
label="出库货盘(仅黄金)"
|
||||
field="pocket"
|
||||
value={line.pocket}
|
||||
@@ -40,6 +47,7 @@ export function InternalCosts({
|
||||
onChange={value => setLine(l => Model.setLineField(l, 'pocket', value))}
|
||||
/>
|
||||
<TextField
|
||||
span={THIRD}
|
||||
label="出库数量(对)"
|
||||
field="stockCount"
|
||||
numeric
|
||||
@@ -49,7 +57,7 @@ export function InternalCosts({
|
||||
hint={v.stockCountOptional ? '历史未记录对数,可保留空白;与计工费件数分别填写。' : '与计工费件数分别填写。'}
|
||||
onChange={value => setLine(l => Model.setLineField(l, 'stockCount', value))}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
{line.legacy ? (
|
||||
<TextField label="原单货品成本(旧版未分项)" field="cost" value={line.cost} readOnly />
|
||||
) : (
|
||||
@@ -57,9 +65,11 @@ export function InternalCosts({
|
||||
<div className="cost-fields">
|
||||
{line.pool && (
|
||||
<div className="material-source">
|
||||
<div className="grid three">
|
||||
<Row gutter={[16, 14]}>
|
||||
<RadioField
|
||||
span={THIRD}
|
||||
label="料费成本来源"
|
||||
help={line.pool.help}
|
||||
field="materialSource"
|
||||
value={line.pool.source}
|
||||
options={[
|
||||
@@ -70,6 +80,7 @@ export function InternalCosts({
|
||||
/>
|
||||
{pooled && (
|
||||
<ChoiceField
|
||||
span={THIRD}
|
||||
label="料价日期"
|
||||
field="materialPoolId"
|
||||
value={line.pool.poolId}
|
||||
@@ -80,15 +91,18 @@ export function InternalCosts({
|
||||
/>
|
||||
)}
|
||||
{pooled && (
|
||||
<div className="field">
|
||||
<label className="field-label"> </label>
|
||||
<Button size="small" data-action="reload-material-choices" onClick={onReloadPools}>
|
||||
<Field span={THIRD} label={'\u00a0'} field="reload-material-choices">
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
data-action="reload-material-choices"
|
||||
onClick={onReloadPools}
|
||||
className="reload-button"
|
||||
>
|
||||
刷新料价
|
||||
</Button>
|
||||
</div>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
<p className="small muted">{line.pool.help}</p>
|
||||
</Row>
|
||||
{pooled && line.view.poolNote && (
|
||||
<p className="small material-pool-note" aria-live="polite" data-testid="pool-note">
|
||||
{line.view.poolNote}
|
||||
@@ -96,9 +110,10 @@ export function InternalCosts({
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="grid four purchase-cost-grid">
|
||||
<Row gutter={[16, 14]} className="purchase-cost-grid">
|
||||
{v.materialMode && (
|
||||
<RadioField
|
||||
span={QUARTER}
|
||||
label="进货料费方式"
|
||||
field="cost-materialMode"
|
||||
value={p.materialMode}
|
||||
@@ -110,6 +125,7 @@ export function InternalCosts({
|
||||
/>
|
||||
)}
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label={pooled ? '加权进货料价(元/克,自动)' : '进货料价(元/克)'}
|
||||
field="cost-materialRate"
|
||||
numeric
|
||||
@@ -120,6 +136,7 @@ export function InternalCosts({
|
||||
onChange={setPurchase('materialRate')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label={pooled ? '耗用料费合计(元,自动)' : '料费成本合计(元)'}
|
||||
field="cost-material"
|
||||
numeric
|
||||
@@ -130,6 +147,7 @@ export function InternalCosts({
|
||||
/>
|
||||
{v.materialPayer ? (
|
||||
<ChoiceField
|
||||
span={QUARTER}
|
||||
label="料费付款人"
|
||||
field="cost-materialPayer"
|
||||
value={p.materialPayer}
|
||||
@@ -139,19 +157,21 @@ export function InternalCosts({
|
||||
/>
|
||||
) : (
|
||||
<TextField
|
||||
span={QUARTER}
|
||||
label={line.pool?.personal ? '材料原付款人' : '本批购料付款人'}
|
||||
field="cost-materialPoolPayer"
|
||||
value={line.pool?.payerText || ''}
|
||||
readOnly
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</Row>
|
||||
<p className="purchase-formula small muted" aria-live="polite">
|
||||
{line.view.materialFormula}
|
||||
</p>
|
||||
{line.view.materialOriginal && <p className="small muted">{line.view.materialOriginal}</p>}
|
||||
<div className="grid four purchase-cost-grid">
|
||||
<Row gutter={[16, 14]} className="purchase-cost-grid">
|
||||
<RadioField
|
||||
span={QUARTER}
|
||||
label="进货工费方式"
|
||||
field="cost-laborMode"
|
||||
value={p.laborMode}
|
||||
@@ -162,6 +182,7 @@ export function InternalCosts({
|
||||
onChange={setPurchase('laborMode')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="进货克工费(元/克)"
|
||||
field="cost-laborRate"
|
||||
numeric
|
||||
@@ -171,6 +192,7 @@ export function InternalCosts({
|
||||
onChange={setPurchase('laborRate')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="进货总工费(元)"
|
||||
field="cost-labor"
|
||||
numeric
|
||||
@@ -180,6 +202,7 @@ export function InternalCosts({
|
||||
onChange={setPurchase('labor')}
|
||||
/>
|
||||
<ChoiceField
|
||||
span={QUARTER}
|
||||
label="进货工费付款人"
|
||||
field="cost-laborPayer"
|
||||
value={p.laborPayer}
|
||||
@@ -187,15 +210,16 @@ export function InternalCosts({
|
||||
options={payerOptions(p.laborPayer)}
|
||||
onChange={setPurchase('laborPayer')}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
<p className="purchase-formula small muted" aria-live="polite">
|
||||
{line.view.laborFormula}
|
||||
</p>
|
||||
{v.extraCosts && (
|
||||
<div className="legacy-extra-costs">
|
||||
<p className="small muted">这里保留原来填写的货品成本,不要在下方实际费用重复登记。</p>
|
||||
<div className="grid three">
|
||||
<Row gutter={[16, 14]}>
|
||||
<TextField
|
||||
span={THIRD}
|
||||
label="配件成本(元,本行合计)"
|
||||
field="cost-accessories"
|
||||
numeric
|
||||
@@ -203,6 +227,7 @@ export function InternalCosts({
|
||||
onChange={setPurchase('accessories')}
|
||||
/>
|
||||
<TextField
|
||||
span={THIRD}
|
||||
label="其他货品成本(元,本行合计)"
|
||||
field="cost-other"
|
||||
numeric
|
||||
@@ -210,22 +235,25 @@ export function InternalCosts({
|
||||
onChange={setPurchase('other')}
|
||||
/>
|
||||
<ChoiceField
|
||||
span={THIRD}
|
||||
label="原有配件及其他成本付款人"
|
||||
field="payer"
|
||||
value={line.payer}
|
||||
options={payers}
|
||||
onChange={value => setLine(l => ({ ...l, payer: value }))}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
</div>
|
||||
)}
|
||||
<p className="cost-summary small">
|
||||
本行货品成本合计:
|
||||
<p className="cost-summary">
|
||||
<span>本行货品成本合计</span>
|
||||
<span className={'num' + (line.view.purchase?.total == null ? ' pending' : '')}>
|
||||
{line.view.purchase?.total == null
|
||||
? pooled
|
||||
? '料费待核算'
|
||||
: '请补齐(没有的项目填0)'
|
||||
: '¥' + Model.yuan(line.view.purchase.total)}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Button, Result, Space, Typography } from 'antd';
|
||||
import { Button, Card, Result, Space, Typography } from 'antd';
|
||||
import { FileTextOutlined, PlusOutlined, PrinterOutlined } from '@ant-design/icons';
|
||||
import { orderAmount } from '../../lib/format';
|
||||
|
||||
export interface IssuedOrder {
|
||||
@@ -25,6 +26,8 @@ export function IssuedResult({
|
||||
}) {
|
||||
const loaded = order.total !== undefined;
|
||||
return (
|
||||
<div className="issued-page">
|
||||
<Card className="issued-card">
|
||||
<Result
|
||||
status="success"
|
||||
title="销售单据已生成"
|
||||
@@ -38,31 +41,38 @@ export function IssuedResult({
|
||||
extra={
|
||||
<Space direction="vertical" size="large" style={{ width: '100%' }}>
|
||||
{loaded && (
|
||||
<div className="issued-summary" data-testid="issued-summary">
|
||||
<div>
|
||||
<dl className="issued-summary" data-testid="issued-summary">
|
||||
<div className="issued-item">
|
||||
<dt>
|
||||
<Typography.Text type="secondary">纸单号</Typography.Text>
|
||||
<div className="issued-value" data-testid="issued-paper-number">
|
||||
</dt>
|
||||
<dd className="issued-value num" data-testid="issued-paper-number">
|
||||
{order.paper_number || '未分配'}
|
||||
</dd>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="issued-item">
|
||||
<dt>
|
||||
<Typography.Text type="secondary">成交合计</Typography.Text>
|
||||
<div className="issued-value" data-testid="issued-total">
|
||||
</dt>
|
||||
<dd className="issued-value issued-total num" data-testid="issued-total">
|
||||
{orderAmount(order.total ?? null, order.rounding_mode || 'cent')}
|
||||
</div>
|
||||
</dd>
|
||||
</div>
|
||||
{order.customer && (
|
||||
<div>
|
||||
<div className="issued-item">
|
||||
<dt>
|
||||
<Typography.Text type="secondary">客户</Typography.Text>
|
||||
<div className="issued-value small">{order.customer}</div>
|
||||
</dt>
|
||||
<dd className="issued-value small">{order.customer}</dd>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</dl>
|
||||
)}
|
||||
<Space wrap className="issued-actions">
|
||||
<div className="issued-actions">
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
icon={<PrinterOutlined />}
|
||||
href={'/print/' + encodeURIComponent(order.id)}
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
@@ -70,16 +80,22 @@ export function IssuedResult({
|
||||
>
|
||||
打开打印预览
|
||||
</Button>
|
||||
<Button size="large" onClick={onNew} data-action="new-order">
|
||||
<Button size="large" icon={<PlusOutlined />} onClick={onNew} data-action="new-order">
|
||||
开始新的一单
|
||||
</Button>
|
||||
{!loaded && <Button onClick={onRetry}>重新读取订单</Button>}
|
||||
<Button size="large" href="/" type="link">
|
||||
{!loaded && (
|
||||
<Button size="large" onClick={onRetry}>
|
||||
重新读取订单
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button href="/" type="link" icon={<FileTextOutlined />}>
|
||||
到旧版界面查看订单
|
||||
</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Button, Card, Typography } from 'antd';
|
||||
import { Button, Col, Row, Typography } from 'antd';
|
||||
import { DeleteOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { LedgerState, LineState, OrderForm } from '../../shared';
|
||||
import { uuid } from './useOrderForm';
|
||||
import { ChoiceField, RadioField, TextField } from './fields';
|
||||
import { ChargeList } from './ChargeList';
|
||||
import { InternalCosts } from './InternalCosts';
|
||||
import { HALF, HALF_Q, QUARTER, type Span } from './layout';
|
||||
import { Section } from './Section';
|
||||
|
||||
const PRICING: Span = { xs: 24, sm: 12, xl: 8 };
|
||||
const UNIT: Span = { xs: 12, sm: 12, xl: 4 };
|
||||
|
||||
type Update = (change: (form: OrderForm) => OrderForm) => void;
|
||||
|
||||
@@ -30,7 +36,12 @@ export function LineItems({
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Card className="panel" title="商品明细" extra={<span className="small muted">金价与工费分开填写</span>}>
|
||||
<Section
|
||||
step="02"
|
||||
title="商品明细"
|
||||
help="金价与工费分开填写。银饰不扣黄金货盘;外配使用店内金料时,选实际出库货盘。"
|
||||
extra={<span className="section-extra">共 {form.lines.length} 件商品</span>}
|
||||
>
|
||||
{form.lines.map((line, index) => (
|
||||
<LineCard
|
||||
key={index}
|
||||
@@ -47,12 +58,17 @@ export function LineItems({
|
||||
/>
|
||||
))}
|
||||
<div className="form-actions">
|
||||
<Button data-action="add-line" onClick={() => guarded(f => Model.addLine(f, { st: state, uuid }))}>
|
||||
+ 添加商品
|
||||
<Button
|
||||
className="add-line-button"
|
||||
icon={<PlusOutlined />}
|
||||
data-action="add-line"
|
||||
onClick={() => guarded(f => Model.addLine(f, { st: state, uuid }))}
|
||||
>
|
||||
添加商品
|
||||
</Button>
|
||||
<span className="small muted">银饰不扣黄金货盘;外配使用店内金料时,选实际出库货盘。</span>
|
||||
<span className="small muted">银饰不扣黄金货盘;外配用店内金料时选实际出库货盘。</span>
|
||||
</div>
|
||||
</Card>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,13 +96,25 @@ function LineCard({
|
||||
return (
|
||||
<section className="line-item" data-line={index} aria-label={'商品 ' + (index + 1)}>
|
||||
<div className="line-top">
|
||||
<div className="line-heading">
|
||||
<span className="line-no">{String(index + 1).padStart(2, '0')}</span>
|
||||
<strong>商品 {String(index + 1).padStart(2, '0')}</strong>
|
||||
<Button type="text" size="small" data-action="remove-line" disabled={!canRemove} onClick={onRemove}>
|
||||
<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>
|
||||
<div className="grid four">
|
||||
<Row gutter={[16, 14]}>
|
||||
<ChoiceField
|
||||
span={QUARTER}
|
||||
label="商品名称"
|
||||
field="nameType"
|
||||
value={line.nameType}
|
||||
@@ -94,6 +122,7 @@ function LineCard({
|
||||
onChange={set('nameType')}
|
||||
/>
|
||||
<TextField
|
||||
span={QUARTER}
|
||||
label="其他商品名称"
|
||||
field="customName"
|
||||
hidden={!v.customName}
|
||||
@@ -102,6 +131,7 @@ function LineCard({
|
||||
onChange={set('customName')}
|
||||
/>
|
||||
<RadioField
|
||||
span={PRICING}
|
||||
label="计价方式"
|
||||
field="pricingMode"
|
||||
value={line.pricingMode}
|
||||
@@ -112,6 +142,7 @@ function LineCard({
|
||||
onChange={set('pricingMode')}
|
||||
/>
|
||||
<RadioField
|
||||
span={UNIT}
|
||||
label="单位"
|
||||
field="unit"
|
||||
value={line.unit}
|
||||
@@ -121,10 +152,18 @@ function LineCard({
|
||||
]}
|
||||
onChange={set('unit')}
|
||||
/>
|
||||
<TextField label="克重/数量" field="quantity" numeric value={line.quantity} onChange={set('quantity')} />
|
||||
</div>
|
||||
<div className="grid four sale-inputs">
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="克重/数量"
|
||||
field="quantity"
|
||||
numeric
|
||||
value={line.quantity}
|
||||
onChange={set('quantity')}
|
||||
/>
|
||||
</Row>
|
||||
<Row gutter={[16, 14]} className="sale-inputs">
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="金价/银价(元/克)"
|
||||
field="goldPrice"
|
||||
numeric
|
||||
@@ -133,6 +172,7 @@ function LineCard({
|
||||
onChange={set('goldPrice')}
|
||||
/>
|
||||
<RadioField
|
||||
span={HALF_Q}
|
||||
label="销售工费方式"
|
||||
field="laborMode"
|
||||
hidden={!v.laborMode}
|
||||
@@ -144,6 +184,7 @@ function LineCard({
|
||||
onChange={set('laborMode')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="销售工费"
|
||||
field="laborRate"
|
||||
numeric
|
||||
@@ -152,6 +193,7 @@ function LineCard({
|
||||
onChange={set('laborRate')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF_Q}
|
||||
label="计工费件数"
|
||||
field="pieces"
|
||||
numeric
|
||||
@@ -160,6 +202,7 @@ function LineCard({
|
||||
onChange={set('pieces')}
|
||||
/>
|
||||
<TextField
|
||||
span={HALF}
|
||||
label="销售单价说明(客户可见)"
|
||||
field="priceNote"
|
||||
hidden={!v.priceNote}
|
||||
@@ -168,6 +211,7 @@ function LineCard({
|
||||
onChange={set('priceNote')}
|
||||
/>
|
||||
<TextField
|
||||
span={QUARTER}
|
||||
label="商品基础金额(不含附加项目)"
|
||||
field="baseSale"
|
||||
numeric
|
||||
@@ -175,14 +219,23 @@ function LineCard({
|
||||
value={line.baseSale}
|
||||
onChange={set('baseSale')}
|
||||
/>
|
||||
</div>
|
||||
</Row>
|
||||
<ChargeList index={index} line={line} update={update} />
|
||||
<div className="grid two sale-result">
|
||||
<TextField label="本行销售额(元,含附加项目)" field="sale" value={line.sale} readOnly />
|
||||
<Row gutter={[16, 8]} className="sale-result" align="bottom">
|
||||
<TextField
|
||||
span={{ xs: 24, md: 10, xl: 8 }}
|
||||
className="sale-field"
|
||||
label="本行销售额(元,含附加项目)"
|
||||
field="sale"
|
||||
value={line.sale}
|
||||
readOnly
|
||||
/>
|
||||
<Col xs={24} md={14} xl={16}>
|
||||
<Typography.Paragraph className="calculation small" aria-live="polite" data-testid="line-calculation">
|
||||
{line.view.calculation}
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<InternalCosts index={index} line={line} state={state} update={update} onReloadPools={onReloadPools} />
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Card } from 'antd';
|
||||
import { Help, InternalTag } from './fields';
|
||||
|
||||
// 开单页分区卡片:编号(沿用旧界面 01 02… 的样式)、标题、可选说明与右侧操作;内部分区用金色左边框与暖色底。
|
||||
export function Section({
|
||||
step,
|
||||
title,
|
||||
help,
|
||||
extra,
|
||||
internal,
|
||||
className,
|
||||
testId,
|
||||
children,
|
||||
}: {
|
||||
step: string;
|
||||
title: ReactNode;
|
||||
help?: ReactNode;
|
||||
extra?: ReactNode;
|
||||
internal?: boolean;
|
||||
className?: string;
|
||||
testId?: string;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card
|
||||
className={'panel' + (internal ? ' panel-internal' : '') + (className ? ' ' + className : '')}
|
||||
data-testid={testId}
|
||||
title={
|
||||
<div className="section-title">
|
||||
<span className="step-no" aria-hidden="true">
|
||||
{step}
|
||||
</span>
|
||||
<h2>{title}</h2>
|
||||
{help ? <Help label={'关于' + (typeof title === 'string' ? title : '本区')}>{help}</Help> : null}
|
||||
{internal ? <InternalTag /> : null}
|
||||
</div>
|
||||
}
|
||||
extra={extra}
|
||||
>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,76 +1,76 @@
|
||||
import { Alert, Button, Card, Input } from 'antd';
|
||||
import { Alert, Button, Input, Row } from 'antd';
|
||||
import { CheckOutlined, LockOutlined } from '@ant-design/icons';
|
||||
import { Model } from '../../shared';
|
||||
import type { FormSummary, OrderForm } from '../../shared';
|
||||
import { TextField, Field } from './fields';
|
||||
import { Section } from './Section';
|
||||
|
||||
type Update = (change: (form: OrderForm) => OrderForm) => void;
|
||||
|
||||
// 整单优惠、客户单备注、内部备注(快捷标签)、成交合计与提交。
|
||||
// 整单优惠、客户单备注、内部备注(快捷标签)。
|
||||
export function SummarySection({
|
||||
form,
|
||||
summary,
|
||||
tags,
|
||||
tagsStatus,
|
||||
busy,
|
||||
error,
|
||||
update,
|
||||
onError,
|
||||
}: {
|
||||
form: OrderForm;
|
||||
summary: FormSummary;
|
||||
tags: string[];
|
||||
tagsStatus: string;
|
||||
busy: boolean;
|
||||
error: string;
|
||||
update: Update;
|
||||
onError: (message: string) => void;
|
||||
}) {
|
||||
const shown = Model.filterNoteTags(tags, form.internal_note);
|
||||
const query = /(?:^|[\s,。;、])#([\p{L}\p{N}_-]*)$/u.test(form.internal_note);
|
||||
return (
|
||||
<Card className="panel">
|
||||
<div className="grid two">
|
||||
<Section step="04" title="优惠与备注">
|
||||
<Row gutter={[16, 14]}>
|
||||
<TextField
|
||||
span={{ xs: 24, md: 8 }}
|
||||
label="整单优惠/抹零(元)"
|
||||
field="discount"
|
||||
numeric
|
||||
value={form.discount}
|
||||
onChange={value => update(f => ({ ...f, discount: value }))}
|
||||
/>
|
||||
<Field label="客户单备注" field="note">
|
||||
<Field span={{ xs: 24, md: 16 }} label="客户单备注" field="note" id="order-note">
|
||||
<Input.TextArea
|
||||
id="order-note"
|
||||
name="note"
|
||||
aria-label="客户单备注"
|
||||
maxLength={240}
|
||||
rows={2}
|
||||
autoSize={{ minRows: 1, maxRows: 4 }}
|
||||
placeholder="只写可让客户看到的内容"
|
||||
value={form.note}
|
||||
onChange={event => update(f => ({ ...f, note: event.target.value }))}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
</Row>
|
||||
<div className="internal internal-note">
|
||||
<Field
|
||||
label={
|
||||
<>
|
||||
内部备注(客户不可见)<span className="small muted">必填,至少3个字符(含#号),最多500字</span>
|
||||
<LockOutlined aria-hidden="true" /> 内部备注 <span className="small muted">必填,至少3个字符(含#号),最多500字</span>
|
||||
</>
|
||||
}
|
||||
help="输入 #词语 添加标签,例如 #补货、#客户自提。保存订单后可复用,点击下方标签即可填入。内部备注不会出现在客户销售单或打印件中。"
|
||||
field="internal_note"
|
||||
id="order-internal-note"
|
||||
>
|
||||
<Input.TextArea
|
||||
id="order-internal-note"
|
||||
name="internal_note"
|
||||
aria-label="内部备注"
|
||||
maxLength={500}
|
||||
rows={3}
|
||||
autoSize={{ minRows: 2, maxRows: 6 }}
|
||||
placeholder="仅供内部跟进,不会出现在客户销售单或打印件中"
|
||||
value={form.internal_note}
|
||||
onChange={event => update(f => ({ ...f, internal_note: event.target.value }))}
|
||||
/>
|
||||
</Field>
|
||||
<div className="order-note-tags">
|
||||
<p className="small muted">
|
||||
输入 #词语 添加标签,例如 #补货、#客户自提。保存订单后可复用,点击下方标签即可填入。
|
||||
</p>
|
||||
<div className="order-note-tag-options" aria-label="内部备注快捷标签" data-testid="note-tags">
|
||||
{tagsStatus ? (
|
||||
<span className="small muted">{tagsStatus}</span>
|
||||
@@ -79,6 +79,7 @@ export function SummarySection({
|
||||
<Button
|
||||
key={tag}
|
||||
size="small"
|
||||
className="note-tag"
|
||||
data-note-tag={tag}
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
@@ -100,23 +101,57 @@ export function SummarySection({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="create-submit-bar">
|
||||
<div>
|
||||
<span className="small muted">成交合计</span>
|
||||
<div className="summary-amount" data-testid="create-total">
|
||||
{summary.totalText}
|
||||
</div>
|
||||
<div className="small muted" aria-live="polite" data-testid="rounding-note">
|
||||
{summary.roundingHint}
|
||||
</div>
|
||||
</div>
|
||||
<Button type="primary" htmlType="submit" size="large" loading={busy} data-action="issue">
|
||||
生成销售单据
|
||||
</Button>
|
||||
</div>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
|
||||
// 底部常驻操作栏:成交合计(大号等宽数字)、取整说明、整单优惠与“生成销售单据”。桌面与手机都贴在视口底部。
|
||||
export function SubmitBar({
|
||||
form,
|
||||
summary,
|
||||
busy,
|
||||
error,
|
||||
}: {
|
||||
form: OrderForm;
|
||||
summary: FormSummary;
|
||||
busy: boolean;
|
||||
error: string;
|
||||
}) {
|
||||
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" />
|
||||
)}
|
||||
</Card>
|
||||
<div className="submit-bar-row">
|
||||
<div className="submit-total">
|
||||
<span className="submit-label">成交合计</span>
|
||||
<div className={'summary-amount num' + (summary.total == null ? ' pending' : '')} data-testid="create-total">
|
||||
{summary.totalText}
|
||||
</div>
|
||||
</div>
|
||||
<div className="submit-facts">
|
||||
<span className="fact">
|
||||
{form.lines.length} 件商品
|
||||
{discountCents > 0 ? <> · 整单优惠 −¥{Model.yuan(discountCents)}</> : null}
|
||||
</span>
|
||||
<span className="fact muted" aria-live="polite" data-testid="rounding-note">
|
||||
{summary.roundingHint}
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
size="large"
|
||||
icon={<CheckOutlined />}
|
||||
loading={busy}
|
||||
data-action="issue"
|
||||
className="issue-button"
|
||||
>
|
||||
生成销售单据
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,24 +1,67 @@
|
||||
// 表单小部件:带标签的文本、数字、选择与单选。每个字段外层带 data-field,便于核对与自动化操作。
|
||||
import type { ReactNode } from 'react';
|
||||
import { Input, Radio, Select } from 'antd';
|
||||
// 传入 span 时字段包在 antd Col 里,由外层 Row 排成响应式网格;标签通过 htmlFor / aria-labelledby 与控件关联。
|
||||
import { useId, type ReactNode } from 'react';
|
||||
import { Col, Input, Radio, Select, Tooltip } from 'antd';
|
||||
import type { Span } from './layout';
|
||||
import { LockOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
||||
|
||||
// “?”说明:悬停、聚焦或点按显示。长说明放这里,页面上只留必要文字。
|
||||
export function Help({ children, label = '查看说明' }: { children: ReactNode; label?: string }) {
|
||||
return (
|
||||
<Tooltip title={children} trigger={['hover', 'focus', 'click']} placement="top">
|
||||
<span className="help-icon" role="button" tabIndex={0} aria-label={label}>
|
||||
<QuestionCircleOutlined />
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
// 内部区域标记:客户单据和打印件中不出现。
|
||||
export function InternalTag() {
|
||||
return (
|
||||
<span className="internal-tag">
|
||||
<LockOutlined aria-hidden="true" /> 内部 · 客户不可见
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
interface Base {
|
||||
label: ReactNode;
|
||||
field: string;
|
||||
hint?: ReactNode;
|
||||
help?: ReactNode;
|
||||
hidden?: boolean;
|
||||
className?: string;
|
||||
span?: Span;
|
||||
}
|
||||
export function Field({ label, field, hint, hidden, className, children }: Base & { children: ReactNode }) {
|
||||
export function Field({
|
||||
label,
|
||||
field,
|
||||
hint,
|
||||
help,
|
||||
hidden,
|
||||
className,
|
||||
span,
|
||||
id,
|
||||
labelId,
|
||||
children,
|
||||
}: Base & { children: ReactNode; id?: string; labelId?: string }) {
|
||||
if (hidden) return null;
|
||||
return (
|
||||
const body = (
|
||||
<div className={'field ' + (className || '')} data-field={field}>
|
||||
<label className="field-label">{label}</label>
|
||||
<div className="field-label-row">
|
||||
<label className="field-label" htmlFor={id} id={labelId}>
|
||||
{label}
|
||||
</label>
|
||||
{help ? <Help>{help}</Help> : null}
|
||||
</div>
|
||||
{children}
|
||||
{hint ? <div className="field-hint">{hint}</div> : null}
|
||||
</div>
|
||||
);
|
||||
return span ? <Col {...span}>{body}</Col> : body;
|
||||
}
|
||||
const ariaLabel = (base: Base) => (typeof base.label === 'string' ? base.label : base.field);
|
||||
|
||||
export function TextField({
|
||||
value,
|
||||
onChange,
|
||||
@@ -39,11 +82,13 @@ export function TextField({
|
||||
maxLength?: number;
|
||||
type?: string;
|
||||
}) {
|
||||
const id = useId();
|
||||
return (
|
||||
<Field {...base}>
|
||||
<Field {...base} id={id}>
|
||||
<Input
|
||||
id={id}
|
||||
name={base.field}
|
||||
aria-label={typeof base.label === 'string' ? base.label : base.field}
|
||||
aria-label={ariaLabel(base)}
|
||||
value={value}
|
||||
type={type}
|
||||
inputMode={numeric ? 'decimal' : undefined}
|
||||
@@ -52,7 +97,7 @@ export function TextField({
|
||||
disabled={disabled}
|
||||
placeholder={placeholder}
|
||||
maxLength={maxLength}
|
||||
className={readOnly ? 'readonly-input' : undefined}
|
||||
className={(readOnly ? 'readonly-input' : '') + (numeric ? ' num' : '')}
|
||||
onChange={event => onChange?.(event.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
@@ -72,10 +117,12 @@ export function ChoiceField({
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
}) {
|
||||
const id = useId();
|
||||
return (
|
||||
<Field {...base}>
|
||||
<Field {...base} id={id}>
|
||||
<Select
|
||||
aria-label={typeof base.label === 'string' ? base.label : base.field}
|
||||
id={id}
|
||||
aria-label={ariaLabel(base)}
|
||||
value={value === '' && placeholder ? undefined : value}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
@@ -99,14 +146,17 @@ export function RadioField({
|
||||
onChange: (value: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const labelId = useId();
|
||||
return (
|
||||
<Field {...base}>
|
||||
<Field {...base} labelId={labelId}>
|
||||
<Radio.Group
|
||||
value={value}
|
||||
disabled={disabled}
|
||||
optionType="button"
|
||||
buttonStyle="solid"
|
||||
size="middle"
|
||||
block
|
||||
{...{ role: 'radiogroup' }}
|
||||
aria-labelledby={labelId}
|
||||
onChange={event => onChange(event.target.value)}
|
||||
options={options.map(([v, label, off]) => ({ value: v, label, disabled: !!off }))}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// 校验失败时定位第一个出问题的字段:按提示文字中最先出现的问题找到对应 data-field,滚动到视口中部、
|
||||
// 高亮并聚焦。只影响显示,不改变校验与提交内容;找不到对应字段时什么也不做。
|
||||
type Finder = (root: HTMLElement, match: RegExpExecArray) => Element | null;
|
||||
|
||||
const field = (scope: ParentNode | null, ...names: string[]) => {
|
||||
for (const name of names) {
|
||||
const el = scope?.querySelector(`[data-field="${name}"]`);
|
||||
if (el && !el.querySelector('input[readonly]')) return el;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const line = (root: HTMLElement, match: RegExpExecArray) => root.querySelector(`[data-line="${Number(match[1]) - 1}"]`);
|
||||
const emptyIn = (scope: ParentNode | null, rowSelector: string, name: string) => {
|
||||
for (const row of scope?.querySelectorAll(rowSelector) || []) {
|
||||
const el = row.querySelector(`[data-field="${name}"]`);
|
||||
if (el && !el.querySelector('input')?.value) return el;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const RULES: [RegExp, Finder][] = [
|
||||
[/客户称呼/, root => field(root, 'customer')],
|
||||
[/客户类型/, root => field(root, 'customer_type')],
|
||||
[/开单人/, root => field(root, 'salesperson')],
|
||||
[/内部备注/, root => field(root, 'internal_note')],
|
||||
[/费用实际支付日期/, root => field(root, 'fees_date')],
|
||||
[/业务日期/, root => field(root, 'date')],
|
||||
[/整单优惠/, root => field(root, 'discount')],
|
||||
[/盒子数量|数量请填写正整数/, root => root.querySelector('[data-field^="cost_"][data-field$="_quantity"]')],
|
||||
[/商品 (\d+)的名称/, (root, m) => field(line(root, m), 'customName', 'nameType')],
|
||||
[/商品 (\d+)的克重/, (root, m) => field(line(root, m), 'quantity')],
|
||||
[/商品 (\d+)的计工费件数/, (root, m) => field(line(root, m), 'pieces')],
|
||||
[/商品 (\d+)的金价/, (root, m) => field(line(root, m), 'goldPrice')],
|
||||
[/商品 (\d+)的销售工费/, (root, m) => field(line(root, m), 'laborRate')],
|
||||
[/商品 (\d+)的基础金额/, (root, m) => field(line(root, m), 'baseSale')],
|
||||
[/商品 (\d+)出库数量/, (root, m) => field(line(root, m), 'stockCount')],
|
||||
[/商品 (\d+)(?:附加项目|的.+收费)/, (root, m) => emptyIn(line(root, m), '[data-charge]', 'chargeAmount')],
|
||||
[/商品 (\d+)请选择料费付款人|商品 (\d+)请选择料费和/, (root, m) => field(line(root, m), 'cost-materialPayer')],
|
||||
[/商品 (\d+)请选择进货工费付款人/, (root, m) => field(line(root, m), 'cost-laborPayer')],
|
||||
[/商品 (\d+)请选择不晚于/, (root, m) => field(line(root, m), 'materialPoolId')],
|
||||
[/商品 (\d+)的料费成本/, (root, m) => field(line(root, m), 'cost-materialRate', 'cost-material')],
|
||||
[/商品 (\d+)的进货工费/, (root, m) => field(line(root, m), 'cost-laborRate', 'cost-labor')],
|
||||
[/商品 (\d+)的(?:配件成本)/, (root, m) => field(line(root, m), 'cost-accessories')],
|
||||
[/商品 (\d+)的(?:其他货品成本)/, (root, m) => field(line(root, m), 'cost-other')],
|
||||
[/商品 (\d+)的货品成本/, (root, m) => field(line(root, m), 'cost')],
|
||||
[/商品 (\d+):/, (root, m) => line(root, m)],
|
||||
[/的实际成本|实际成本/, root => emptyIn(root, '.fee-row', 'feeAmount') || field(root.querySelector('.fee-row'), 'feeAmount')],
|
||||
];
|
||||
|
||||
export function findInvalidField(root: HTMLElement, message: string): Element | null {
|
||||
let best: { index: number; el: Element } | null = null;
|
||||
for (const [pattern, find] of RULES) {
|
||||
const match = pattern.exec(message);
|
||||
if (!match || (best && match.index >= best.index)) continue;
|
||||
// 第二组用于“料费和”这类替代写法,统一成第一组。
|
||||
if (match[1] === undefined && match[2] !== undefined) match[1] = match[2];
|
||||
const el = find(root, match);
|
||||
if (el) best = { index: match.index, el };
|
||||
}
|
||||
return best?.el || null;
|
||||
}
|
||||
|
||||
export function focusInvalidField(root: HTMLElement | null, message: string) {
|
||||
if (!root || !message) return;
|
||||
const target = findInvalidField(root, message);
|
||||
if (!target) return;
|
||||
root.querySelectorAll('.field-invalid').forEach(el => el.classList.remove('field-invalid'));
|
||||
target.classList.add('field-invalid');
|
||||
target.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
|
||||
const control = target.querySelector<HTMLElement>('input:not([type=hidden]):not([readonly]), textarea');
|
||||
window.setTimeout(() => control?.focus({ preventScroll: true }), 350);
|
||||
const clear = () => {
|
||||
target.classList.remove('field-invalid');
|
||||
target.removeEventListener('input', clear);
|
||||
target.removeEventListener('click', clear);
|
||||
};
|
||||
target.addEventListener('input', clear);
|
||||
target.addEventListener('click', clear);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// 表单网格列宽(antd Col 断点):桌面四列/三列/两列,平板两列,手机一列或半列。
|
||||
import type { ColProps } from 'antd';
|
||||
|
||||
export type Span = Pick<ColProps, 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'>;
|
||||
export const QUARTER: Span = { xs: 24, sm: 12, xl: 6 };
|
||||
export const HALF_Q: Span = { xs: 12, sm: 12, xl: 6 };
|
||||
export const THIRD: Span = { xs: 24, sm: 12, xl: 8 };
|
||||
export const HALF: Span = { xs: 24, md: 12 };
|
||||
export const FULL: Span = { xs: 24 };
|
||||
|
||||
Reference in new issue
Block a user