Commit 05f66fda by chenwq

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

1 parent 900f24c7
Pipeline #471 for 05f66fda failed in 0 seconds
......@@ -218,11 +218,7 @@ export default function Assessment() {
]
: [];
return (
<PageShell
fill
title="评估管理"
description="查询评估单、查看车辆信息与评估进度。"
>
<PageShell fill title="评估管理">
<UCard className="uj-filter-card" size="small">
<SearchForm
fields={fields}
......@@ -261,7 +257,6 @@ export default function Assessment() {
rowActions={rowActions}
actions={actions}
actionColumnWidth={250}
toolbarTitle={`共 ${list.data?.total ?? 0} 条评估单`}
pagination={{
current: page.current,
pageSize: page.size,
......
......@@ -175,21 +175,18 @@ export default function Leads() {
name: 'cluesNo',
label: '线索 ID',
type: 'input',
placeholder: '请输入线索 ID',
essential: true,
},
{
name: 'carOwnerName',
label: '车主姓名',
type: 'input',
placeholder: '请输入车主姓名',
essential: true,
},
{
name: 'carOwnerPhone',
label: '车主电话',
type: 'input',
placeholder: '请输入车主电话',
essential: true,
},
{
......@@ -202,7 +199,7 @@ export default function Leads() {
})),
essential: true,
},
{ name: 'sellerName', label: '销售顾问', type: 'input', placeholder: '请输入推荐销售顾问' },
{ name: 'sellerName', label: '销售顾问', type: 'input' },
{
name: 'customerIntentLevelList',
label: '意向等级',
......@@ -217,7 +214,7 @@ export default function Leads() {
},
{ name: 'createTimeRange', label: '创建时间', type: 'dateRange' },
{ name: 'lastFollowUpTimeRange', label: '最后跟进时间', type: 'dateRange' },
{ name: 'conversionName', label: '评估师', type: 'input', placeholder: '请输入评估师姓名' },
{ name: 'conversionName', label: '评估师', type: 'input' },
{
name: 'enterType',
label: '录线索人员',
......@@ -231,7 +228,6 @@ export default function Leads() {
name: 'carModel',
label: '评估品牌车型',
type: 'input',
placeholder: '请输入品牌车型关键词',
},
],
[merchants.data?.records],
......@@ -364,10 +360,7 @@ export default function Leads() {
: [];
return (
<PageShell
fill
title="线索管理"
>
<PageShell fill title="线索管理">
{reminders.data?.nearlyExpiredCount || reminders.data?.expiredCount ? (
<div className="uc-lead-reminder">
{reminders.data.nearlyExpiredCount ? (
......
......@@ -44,6 +44,15 @@ export function SearchForm<T extends Record<string, unknown>>({
defaultExpanded = false,
}: SearchFormProps<T>) {
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;
......@@ -83,25 +92,35 @@ export function SearchForm<T extends Record<string, unknown>>({
// 两个数字分开算:总数是「收了多少」,生效数是「其中填了几个」。
// 后者排除 initialValues 里的默认值,并按 filterGroup 把组合字段归并成 1 个业务条件。
const extraTotal = extraFields.length;
const activeExtraCount = countActiveConditions(extraFields, values, initialValues);
const activeExtraCount = countActiveConditions(extraFields, values, formInitialValues);
const control = (field: FieldSchema<T>) => {
const label = typeof field.label === 'string' ? field.label : '';
const isTextInput = field.type === 'input' || field.type === 'textarea';
const common = {
disabled: typeof field.disabled === 'boolean' ? field.disabled : false,
placeholder: field.placeholder,
placeholder:
field.placeholder ?? (isTextInput ? (label ? `请输入${label}` : '请输入') : undefined),
};
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 (
<USelect
{...common}
allowClear={false}
style={{ width }}
options={field.options}
options={
field.type === 'select' && !hasAllOption
? [{ label: '全部', value: '' }, ...options]
: options
}
mode={field.type === 'selectMultiple' ? 'multiple' : undefined}
{...field.selectProps}
/>
);
}
if (field.type === 'cascader')
return <UCascader {...common} style={{ width }} options={field.options} allowClear={false} />;
if (field.type === 'date') return <UDatePicker {...common} style={{ width }} />;
......@@ -133,7 +152,7 @@ export function SearchForm<T extends Record<string, unknown>>({
return (
<UForm
form={form}
initialValues={initialValues}
initialValues={formInitialValues}
// 标签在左、控件在右:标签列宽固定,四组控件的左缘落在同一条竖线上。
// 竖排标签会把筛选区抬高一整行,横向排列后整条筛选带只占控件本身的高度。
layout="horizontal"
......@@ -188,14 +207,14 @@ export function SearchForm<T extends Record<string, unknown>>({
size="small"
onClick={() => {
const resetValues = fields.reduce<Record<string, unknown>>((acc, field) => {
const initialValue = initialValues?.[field.name];
const initialValue = formInitialValues?.[field.name];
acc[field.name] =
initialValue ??
(field.type === 'input' || field.type === 'textarea' ? '' : undefined);
return acc;
}, {});
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!