Commit 4da57903 by chenwq

优化搜索表单,清空条件时同时清除选择器字段,调整控件布局

1 parent 0a0a7047
Pipeline #604 for 4da57903 failed in 0 seconds
import { useMemo, useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import type { Dayjs } from 'dayjs';
import dayjs, { type Dayjs } from 'dayjs';
import { UAlert, UButton, UCard, UResult, UTag } from '@uj/ui';
import { downloadCenter } from '@uj/platform-sdk';
import {
......@@ -37,14 +37,14 @@ type Filters = Record<string, unknown> & {
type Row = Record<string, unknown> & { id: string | number; deliveryOrderId?: string };
type Result = { records: Row[]; total: number };
const status = [
{ value: '-1', label: '已取消' },
{ value: '0', label: '待交付' },
{ value: '1', label: '交付中' },
{ value: '2', label: '交付完成' },
{ value: '-1', label: '已取消', color: 'red' },
{ value: '0', label: '待交付', color: 'orange' },
{ value: '1', label: '交付中', color: 'blue' },
{ value: '2', label: '交付完成', color: 'green' },
];
const payment = [
{ value: '0', label: '待支付' },
{ value: '1', label: '已结清' },
{ value: '0', label: '待支付', color: 'orange' },
{ value: '1', label: '已结清', color: 'green' },
];
const delivery = [
{ value: '0', label: '客户自提' },
......@@ -53,6 +53,8 @@ const delivery = [
const txt = (v: unknown) => (v === undefined || v === null || v === '' ? '-' : String(v));
const label = (o: readonly { value: string; label: string }[], v: unknown) =>
o.find((x) => x.value === String(v))?.label ?? '-';
const colorOf = (o: readonly { value: string; color: string }[], v: unknown) =>
o.find((x) => x.value === String(v))?.color;
function paramsOf(f: Filters) {
const { dateRange, dateType, personKeyword, personType, phoneKeyword, phoneType, ...rest } = f;
const r = (v: [Dayjs, Dayjs] | undefined, s: string, e: string) =>
......@@ -115,9 +117,8 @@ export default function Delivery() {
// 控件较宽,统一收进「更多筛选」,避免收起时换行、展开时与另一个同形控件看起来重复。
fields.splice(4, 0, {
name: 'personKeyword',
label: '姓名',
label: '',
type: 'input',
placeholder: '请输入交付专员姓名',
selector: {
name: 'personType',
options: [
......@@ -130,9 +131,8 @@ export default function Delivery() {
});
fields.splice(5, 0, {
name: 'phoneKeyword',
label: '电话',
label: '',
type: 'input',
placeholder: '请输入交付专员电话',
selector: {
name: 'phoneType',
options: [
......@@ -162,6 +162,7 @@ export default function Delivery() {
],
},
filterGroup: 'date',
disabledDate: (date) => date.isAfter(dayjs(), 'day'),
},
);
const columns = [
......@@ -193,13 +194,13 @@ export default function Delivery() {
title: '交付状态',
dataIndex: 'orderStatus',
width: 120,
render: (v: unknown) => <UTag>{label(status, v)}</UTag>,
render: (v: unknown) => <UTag color={colorOf(status, v)}>{label(status, v)}</UTag>,
},
{
title: '付款状态',
dataIndex: 'paymentStatus',
width: 120,
render: (v: unknown) => <UTag>{label(payment, v)}</UTag>,
render: (v: unknown) => <UTag color={colorOf(payment, v)}>{label(payment, v)}</UTag>,
},
{
title: '交付方式',
......
......@@ -170,7 +170,9 @@ export function SearchForm<T extends Record<string, unknown>>({
/** 全部清空走 onReset:页面侧把列表过滤条件一起清掉并回到第 1 页。 */
const clearAllConditions = () => {
clearFields(fields.map((field) => field.name));
clearFields(
fields.flatMap((field) => [field.name, ...(field.selector ? [field.selector.name] : [])]),
);
setActivePopoverOpen(false);
onReset?.(formInitialValues, { ...searchPagination, current: 1 });
};
......@@ -308,7 +310,9 @@ export function SearchForm<T extends Record<string, unknown>>({
options={field.selector.options}
/>
</UFormItem>
<div style={{ minWidth: 0, flex: 1 }}>{picker}</div>
<UFormItem name={field.name as string} noStyle>
{picker}
</UFormItem>
</div>
);
}
......@@ -329,7 +333,9 @@ export function SearchForm<T extends Record<string, unknown>>({
options={field.selector.options}
/>
</UFormItem>
<div style={{ minWidth: 0, flex: 1 }}>{input}</div>
<UFormItem name={field.name as string} noStyle>
{input}
</UFormItem>
</div>
);
};
......@@ -343,8 +349,17 @@ export function SearchForm<T extends Record<string, unknown>>({
const span = field.span ?? 1;
const style: React.CSSProperties = { marginBottom: 0, minWidth: 0 };
if (span > 1) style.gridColumn = `span ${span}`;
const nestedName = Boolean(
field.selector &&
(field.type === 'input' || field.type === 'textarea' || field.type === 'dateRange'),
);
return (
<UFormItem key={field.name} name={field.name as string} label={field.label} style={style}>
<UFormItem
key={field.name}
name={nestedName ? undefined : (field.name as string)}
label={field.label}
style={style}
>
{control(field)}
</UFormItem>
);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!