feat(customer-form): 新增/编辑表单分区(基本/生日/其它)
- 加 FormSection helper(灰色小标题,复用 --color-muted-foreground,不新增组件文件) - 字段拆成 基本(商户名称/联系人/结算人/业务员/联系电话/报单日期) / 生日(类型/归属/生日) / 其它(押金/买断/产品明细/备注) - 保留紧凑网格(sm:2/lg:3),生日三字段独立成块;录入密度不降 - 与查看弹窗分区心智一致;required/校验/提交行 不变 校验:tsc --noEmit 通过;next build 全路由编译通过。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,24 @@ function Field({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 表单分区:小标题 + 内容;块间靠外层 space-y-6 分隔,不加灰线(录入场景保持紧凑)
|
||||||
|
function FormSection({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<section className="space-y-3">
|
||||||
|
<h4 className="text-xs font-semibold tracking-wide text-[var(--color-muted-foreground)]">
|
||||||
|
{title}
|
||||||
|
</h4>
|
||||||
|
{children}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function CustomerForm({
|
export function CustomerForm({
|
||||||
action,
|
action,
|
||||||
defaultValues,
|
defaultValues,
|
||||||
@@ -79,38 +97,40 @@ export function CustomerForm({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<form action={formAction} className="space-y-6">
|
<form action={formAction} className="space-y-6">
|
||||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
<FormSection title="基本">
|
||||||
<Field
|
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
label="商户名称"
|
<Field
|
||||||
name="customerName"
|
label="商户名称"
|
||||||
defaultValue={v.customerName}
|
name="customerName"
|
||||||
required
|
defaultValue={v.customerName}
|
||||||
pattern={requireAll ? "\\S+" : undefined}
|
required
|
||||||
title={requireAll ? "商户名称不能包含空格" : undefined}
|
pattern={requireAll ? "\\S+" : undefined}
|
||||||
/>
|
title={requireAll ? "商户名称不能包含空格" : undefined}
|
||||||
<Field label="联系人" name="contacts" defaultValue={v.contacts} required />
|
/>
|
||||||
<Field label="结算人" name="balanceUser" defaultValue={v.balanceUser} required />
|
<Field label="联系人" name="contacts" defaultValue={v.contacts} required />
|
||||||
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
<Field label="结算人" name="balanceUser" defaultValue={v.balanceUser} required />
|
||||||
<Field
|
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
||||||
label="联系电话"
|
<Field
|
||||||
name="phone"
|
label="联系电话"
|
||||||
defaultValue={v.phone}
|
name="phone"
|
||||||
required={requireAll}
|
defaultValue={v.phone}
|
||||||
pattern={requireAll ? "1\\d{10}" : undefined}
|
required={requireAll}
|
||||||
inputMode={requireAll ? "numeric" : undefined}
|
pattern={requireAll ? "1\\d{10}" : undefined}
|
||||||
title={requireAll ? "请输入 11 位手机号" : undefined}
|
inputMode={requireAll ? "numeric" : undefined}
|
||||||
/>
|
title={requireAll ? "请输入 11 位手机号" : undefined}
|
||||||
<Field
|
/>
|
||||||
label="报单日期"
|
<Field
|
||||||
name="reportDate"
|
label="报单日期"
|
||||||
type="date"
|
name="reportDate"
|
||||||
defaultValue={fmtDate(v.reportDate)}
|
type="date"
|
||||||
required
|
defaultValue={fmtDate(v.reportDate)}
|
||||||
/>
|
required
|
||||||
<Field label="押金" name="deposit" defaultValue={v.deposit} required={requireAll} />
|
/>
|
||||||
<Field label="买断" name="buy" defaultValue={v.buy} required={requireAll} />
|
</div>
|
||||||
{/* 生日类型 + 生日归属,同行两个下拉框 */}
|
</FormSection>
|
||||||
<div className="grid grid-cols-2 gap-3">
|
|
||||||
|
<FormSection title="生日">
|
||||||
|
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="birthdayType">生日类型</Label>
|
<Label htmlFor="birthdayType">生日类型</Label>
|
||||||
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
|
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
|
||||||
@@ -125,27 +145,32 @@ export function CustomerForm({
|
|||||||
<option value="2">联系人</option>
|
<option value="2">联系人</option>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
<Field
|
||||||
|
label="生日"
|
||||||
|
name="birthday"
|
||||||
|
type="date"
|
||||||
|
defaultValue={fmtDate(v.birthday)}
|
||||||
|
required={requireAll}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Field
|
</FormSection>
|
||||||
label="生日"
|
|
||||||
name="birthday"
|
|
||||||
type="date"
|
|
||||||
defaultValue={fmtDate(v.birthday)}
|
|
||||||
required={requireAll}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-1.5">
|
<FormSection title="其它">
|
||||||
<Label htmlFor="detail">
|
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2">
|
||||||
产品明细<span className="ml-0.5 text-[var(--color-danger)]">*</span>
|
<Field label="押金" name="deposit" defaultValue={v.deposit} required={requireAll} />
|
||||||
</Label>
|
<Field label="买断" name="buy" defaultValue={v.buy} required={requireAll} />
|
||||||
<Textarea id="detail" name="detail" defaultValue={v.detail ?? ""} rows={3} />
|
</div>
|
||||||
</div>
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="detail">
|
||||||
<div className="space-y-1.5">
|
产品明细<span className="ml-0.5 text-[var(--color-danger)]">*</span>
|
||||||
<Label htmlFor="remark">备注</Label>
|
</Label>
|
||||||
<Textarea id="remark" name="remark" defaultValue={v.remark ?? ""} rows={2} />
|
<Textarea id="detail" name="detail" defaultValue={v.detail ?? ""} rows={3} />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="remark">备注</Label>
|
||||||
|
<Textarea id="remark" name="remark" defaultValue={v.remark ?? ""} rows={2} />
|
||||||
|
</div>
|
||||||
|
</FormSection>
|
||||||
|
|
||||||
{state.error && (
|
{state.error && (
|
||||||
<p className="rounded-md bg-[var(--color-danger-soft)] px-3 py-2 text-sm text-[var(--color-danger)]">
|
<p className="rounded-md bg-[var(--color-danger-soft)] px-3 py-2 text-sm text-[var(--color-danger)]">
|
||||||
|
|||||||
Reference in New Issue
Block a user