Commit 05f66fda by chenwq

feat: 优化搜索表单初始值设置,支持下拉框默认选项

1 parent 900f24c7
Pipeline #471 for 05f66fda failed in 0 seconds
...@@ -218,11 +218,7 @@ export default function Assessment() { ...@@ -218,11 +218,7 @@ export default function Assessment() {
] ]
: []; : [];
return ( return (
<PageShell <PageShell fill title="评估管理">
fill
title="评估管理"
description="查询评估单、查看车辆信息与评估进度。"
>
<UCard className="uj-filter-card" size="small"> <UCard className="uj-filter-card" size="small">
<SearchForm <SearchForm
fields={fields} fields={fields}
...@@ -261,7 +257,6 @@ export default function Assessment() { ...@@ -261,7 +257,6 @@ export default function Assessment() {
rowActions={rowActions} rowActions={rowActions}
actions={actions} actions={actions}
actionColumnWidth={250} actionColumnWidth={250}
toolbarTitle={`共 ${list.data?.total ?? 0} 条评估单`}
pagination={{ pagination={{
current: page.current, current: page.current,
pageSize: page.size, pageSize: page.size,
......
...@@ -175,21 +175,18 @@ export default function Leads() { ...@@ -175,21 +175,18 @@ export default function Leads() {
name: 'cluesNo', name: 'cluesNo',
label: '线索 ID', label: '线索 ID',
type: 'input', type: 'input',
placeholder: '请输入线索 ID',
essential: true, essential: true,
}, },
{ {
name: 'carOwnerName', name: 'carOwnerName',
label: '车主姓名', label: '车主姓名',
type: 'input', type: 'input',
placeholder: '请输入车主姓名',
essential: true, essential: true,
}, },
{ {
name: 'carOwnerPhone', name: 'carOwnerPhone',
label: '车主电话', label: '车主电话',
type: 'input', type: 'input',
placeholder: '请输入车主电话',
essential: true, essential: true,
}, },
{ {
...@@ -202,7 +199,7 @@ export default function Leads() { ...@@ -202,7 +199,7 @@ export default function Leads() {
})), })),
essential: true, essential: true,
}, },
{ name: 'sellerName', label: '销售顾问', type: 'input', placeholder: '请输入推荐销售顾问' }, { name: 'sellerName', label: '销售顾问', type: 'input' },
{ {
name: 'customerIntentLevelList', name: 'customerIntentLevelList',
label: '意向等级', label: '意向等级',
...@@ -217,7 +214,7 @@ export default function Leads() { ...@@ -217,7 +214,7 @@ export default function Leads() {
}, },
{ name: 'createTimeRange', label: '创建时间', type: 'dateRange' }, { name: 'createTimeRange', label: '创建时间', type: 'dateRange' },
{ name: 'lastFollowUpTimeRange', label: '最后跟进时间', type: 'dateRange' }, { name: 'lastFollowUpTimeRange', label: '最后跟进时间', type: 'dateRange' },
{ name: 'conversionName', label: '评估师', type: 'input', placeholder: '请输入评估师姓名' }, { name: 'conversionName', label: '评估师', type: 'input' },
{ {
name: 'enterType', name: 'enterType',
label: '录线索人员', label: '录线索人员',
...@@ -231,7 +228,6 @@ export default function Leads() { ...@@ -231,7 +228,6 @@ export default function Leads() {
name: 'carModel', name: 'carModel',
label: '评估品牌车型', label: '评估品牌车型',
type: 'input', type: 'input',
placeholder: '请输入品牌车型关键词',
}, },
], ],
[merchants.data?.records], [merchants.data?.records],
...@@ -364,10 +360,7 @@ export default function Leads() { ...@@ -364,10 +360,7 @@ export default function Leads() {
: []; : [];
return ( return (
<PageShell <PageShell fill title="线索管理">
fill
title="线索管理"
>
{reminders.data?.nearlyExpiredCount || reminders.data?.expiredCount ? ( {reminders.data?.nearlyExpiredCount || reminders.data?.expiredCount ? (
<div className="uc-lead-reminder"> <div className="uc-lead-reminder">
{reminders.data.nearlyExpiredCount ? ( {reminders.data.nearlyExpiredCount ? (
......
...@@ -44,6 +44,15 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -44,6 +44,15 @@ export function SearchForm<T extends Record<string, unknown>>({
defaultExpanded = false, defaultExpanded = false,
}: SearchFormProps<T>) { }: SearchFormProps<T>) {
const [form] = UForm.useForm(); const [form] = UForm.useForm();
// 普通单选下拉以空值代表「全部」。除了补选项外,也要把未指定的初始值设为空,
// 否则组件只会显示占位状态,看起来像没有选中「全部」。
const formInitialValues = fields.reduce<Record<string, unknown>>(
(values, field) => {
if (field.type === 'select' && values[field.name] === undefined) values[field.name] = '';
return values;
},
{ ...initialValues },
) as Partial<T>;
// 空数组 = 监听整张表单。用于「收起状态下已设条件」的角标计数: // 空数组 = 监听整张表单。用于「收起状态下已设条件」的角标计数:
// 收起了不等于没生效,用户必须看得见自己身上还挂着几个条件。 // 收起了不等于没生效,用户必须看得见自己身上还挂着几个条件。
const values = UForm.useWatch([], form) as Partial<T> | undefined; const values = UForm.useWatch([], form) as Partial<T> | undefined;
...@@ -83,25 +92,35 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -83,25 +92,35 @@ export function SearchForm<T extends Record<string, unknown>>({
// 两个数字分开算:总数是「收了多少」,生效数是「其中填了几个」。 // 两个数字分开算:总数是「收了多少」,生效数是「其中填了几个」。
// 后者排除 initialValues 里的默认值,并按 filterGroup 把组合字段归并成 1 个业务条件。 // 后者排除 initialValues 里的默认值,并按 filterGroup 把组合字段归并成 1 个业务条件。
const extraTotal = extraFields.length; const extraTotal = extraFields.length;
const activeExtraCount = countActiveConditions(extraFields, values, initialValues); const activeExtraCount = countActiveConditions(extraFields, values, formInitialValues);
const control = (field: FieldSchema<T>) => { const control = (field: FieldSchema<T>) => {
const label = typeof field.label === 'string' ? field.label : '';
const isTextInput = field.type === 'input' || field.type === 'textarea';
const common = { const common = {
disabled: typeof field.disabled === 'boolean' ? field.disabled : false, disabled: typeof field.disabled === 'boolean' ? field.disabled : false,
placeholder: field.placeholder, placeholder:
field.placeholder ?? (isTextInput ? (label ? `请输入${label}` : '请输入') : undefined),
}; };
const width = field.width ?? '100%'; const width = field.width ?? '100%';
if (field.type === 'select' || field.type === 'selectMultiple') if (field.type === 'select' || field.type === 'selectMultiple') {
const options = field.options ?? [];
const hasAllOption = options.some((option) => option.label === '全部' || option.value === '');
return ( return (
<USelect <USelect
{...common} {...common}
allowClear={false} allowClear={false}
style={{ width }} style={{ width }}
options={field.options} options={
field.type === 'select' && !hasAllOption
? [{ label: '全部', value: '' }, ...options]
: options
}
mode={field.type === 'selectMultiple' ? 'multiple' : undefined} mode={field.type === 'selectMultiple' ? 'multiple' : undefined}
{...field.selectProps} {...field.selectProps}
/> />
); );
}
if (field.type === 'cascader') if (field.type === 'cascader')
return <UCascader {...common} style={{ width }} options={field.options} allowClear={false} />; return <UCascader {...common} style={{ width }} options={field.options} allowClear={false} />;
if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />; if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />;
...@@ -133,7 +152,7 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -133,7 +152,7 @@ export function SearchForm<T extends Record<string, unknown>>({
return ( return (
<UForm <UForm
form={form} form={form}
initialValues={initialValues} initialValues={formInitialValues}
// 标签在左、控件在右:标签列宽固定,四组控件的左缘落在同一条竖线上。 // 标签在左、控件在右:标签列宽固定,四组控件的左缘落在同一条竖线上。
// 竖排标签会把筛选区抬高一整行,横向排列后整条筛选带只占控件本身的高度。 // 竖排标签会把筛选区抬高一整行,横向排列后整条筛选带只占控件本身的高度。
layout="horizontal" layout="horizontal"
...@@ -188,14 +207,14 @@ export function SearchForm<T extends Record<string, unknown>>({ ...@@ -188,14 +207,14 @@ export function SearchForm<T extends Record<string, unknown>>({
size="small" size="small"
onClick={() => { onClick={() => {
const resetValues = fields.reduce<Record<string, unknown>>((acc, field) => { const resetValues = fields.reduce<Record<string, unknown>>((acc, field) => {
const initialValue = initialValues?.[field.name]; const initialValue = formInitialValues?.[field.name];
acc[field.name] = acc[field.name] =
initialValue ?? initialValue ??
(field.type === 'input' || field.type === 'textarea' ? '' : undefined); (field.type === 'input' || field.type === 'textarea' ? '' : undefined);
return acc; return acc;
}, {}); }, {});
form.setFieldsValue(resetValues); form.setFieldsValue(resetValues);
onReset?.(initialValues ?? {}, searchPagination); onReset?.(formInitialValues, searchPagination);
}} }}
> >
重置 重置
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!