选客户自动补全
灵感:能力工具箱 customer-autofill(自研)。
> 小四原创:选客户 → 按映射表填空字段;默认不覆盖用户已手改的非空值(可开关「强制覆盖」)。
何时使用
- 商机/合同/跟进单先选客户再填联系方式
- 减少重复录入电话地址
- 与「客户自动关联」串联:关联后立刻补全
硬约束
- 补全字段可配置:
contactmobileemailaddress等。 - 默认
fill-empty:目标字段已有值则跳过。 - 多联系人时:取主联系人或弹选择器,勿 silently 乱选。
- 实现要点注释标 小四原创。
- 与自动关联区分:本包假设 已有 customerId。
推荐实现
export type CustomerDetail = {
id: string
company: string
contact?: string
mobile?: string
email?: string
address?: string
}
export type FormPatch = Partial<Record<string, string>>
// 小四原创:空位补全
export function autofillFromCustomer(
form: FormPatch,
customer: CustomerDetail,
opts?: { overwrite?: boolean; map?: Record<string, keyof CustomerDetail> },
): FormPatch {
const overwrite = opts?.overwrite ?? false
const map = opts?.map ?? {
contact: 'contact',
mobile: 'mobile',
email: 'email',
address: 'address',
company: 'company',
}
const next = { ...form }
for (const [formKey, custKey] of Object.entries(map)) {
const val = customer[custKey]
if (val == null || val === '') continue
const cur = next[formKey]
if (!overwrite && cur != null && String(cur).trim() !== '') continue
next[formKey] = String(val)
}
next.customerId = customer.id
return next
}
Agent 步骤
- 客户选择器
change时拉详情(或用列表行缓存)。 - 调用
autofillFromCustomer;Toast「已补全 N 项」。 - 提供「清空并重填」给需要覆盖的场景。
- 自测:空表补全、已填电话不被覆盖、强制覆盖开关。
不要做
- 选客户时静默清空用户长备注。
- 多联系人不提示就随便带一个敏感字段。
附加
- README.md · reference.md · templates/usage.md