fix(table): 统一筛选交互并补齐移动视口覆盖
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { formatIdReference } from '../../helpers/safeDisplay';
|
||||
|
||||
import { useFilterSearch } from '../../hooks/common/useFilterSearch';
|
||||
import { useFilteredTableRows } from '../../hooks/common/useFilteredTableRows';
|
||||
import { ConsoleCollectionSearch } from '@/components/console/ConsoleCollection';
|
||||
import {
|
||||
ConsoleFilterField,
|
||||
@@ -136,6 +138,27 @@ export default function PartnerPortal({
|
||||
const [customerStatus, setCustomerStatus] = useState('all');
|
||||
const [billMonth, setBillMonth] = useState('all');
|
||||
const [billStatus, setBillStatus] = useState('all');
|
||||
const [appliedDetail, setAppliedDetail] = useState('');
|
||||
const [appliedCustomer, setAppliedCustomer] = useState({
|
||||
keyword: '',
|
||||
status: 'all',
|
||||
});
|
||||
const [appliedBill, setAppliedBill] = useState({
|
||||
month: 'all',
|
||||
status: 'all',
|
||||
});
|
||||
const detailSearch = useFilterSearch(() =>
|
||||
setAppliedDetail(query.toLowerCase()),
|
||||
);
|
||||
const customerSearch = useFilterSearch(() =>
|
||||
setAppliedCustomer({
|
||||
keyword: customerQuery.toLowerCase(),
|
||||
status: customerStatus,
|
||||
}),
|
||||
);
|
||||
const billSearch = useFilterSearch(() =>
|
||||
setAppliedBill({ month: billMonth, status: billStatus }),
|
||||
);
|
||||
const [billPage, setBillPage] = useState(1);
|
||||
const [customerPage, setCustomerPage] = useState(1);
|
||||
const [detailPage, setDetailPage] = useState(1);
|
||||
@@ -243,6 +266,9 @@ export default function PartnerPortal({
|
||||
setDetailLoading(true);
|
||||
setError('');
|
||||
setQuery('');
|
||||
detailSearch.cancelPendingSearch();
|
||||
setQuery('');
|
||||
setAppliedDetail('');
|
||||
setDetailPage(1);
|
||||
setAction(null);
|
||||
setReason('');
|
||||
@@ -369,9 +395,9 @@ export default function PartnerPortal({
|
||||
const currentStatements = rows.filter(
|
||||
(row) => row.statement_month === currentMonth,
|
||||
);
|
||||
const detailItems = items.filter(
|
||||
const matchesDetail = useCallback(
|
||||
(item) =>
|
||||
!query ||
|
||||
!appliedDetail ||
|
||||
[
|
||||
item.customer_name,
|
||||
item.model_name,
|
||||
@@ -380,24 +406,32 @@ export default function PartnerPortal({
|
||||
].some((value) =>
|
||||
String(value || '')
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase()),
|
||||
.includes(appliedDetail),
|
||||
),
|
||||
[appliedDetail],
|
||||
);
|
||||
const visibleCustomers = customers.filter(
|
||||
const detailItems = useFilteredTableRows(items, matchesDetail);
|
||||
const matchesCustomer = useCallback(
|
||||
(row) =>
|
||||
(customerStatus === 'all' || row.status === customerStatus) &&
|
||||
(!customerQuery ||
|
||||
(appliedCustomer.status === 'all' ||
|
||||
row.status === appliedCustomer.status) &&
|
||||
(!appliedCustomer.keyword ||
|
||||
[row.customer_name, row.subject_name, row.subject_id].some((value) =>
|
||||
String(value || '')
|
||||
.toLowerCase()
|
||||
.includes(customerQuery.toLowerCase()),
|
||||
.includes(appliedCustomer.keyword),
|
||||
)),
|
||||
[appliedCustomer],
|
||||
);
|
||||
const visibleBills = rows.filter(
|
||||
const visibleCustomers = useFilteredTableRows(customers, matchesCustomer);
|
||||
const matchesBill = useCallback(
|
||||
(row) =>
|
||||
(billMonth === 'all' || row.statement_month === billMonth) &&
|
||||
(billStatus === 'all' || row.status === billStatus),
|
||||
(appliedBill.month === 'all' ||
|
||||
row.statement_month === appliedBill.month) &&
|
||||
(appliedBill.status === 'all' || row.status === appliedBill.status),
|
||||
[appliedBill],
|
||||
);
|
||||
const visibleBills = useFilteredTableRows(rows, matchesBill);
|
||||
const adjustmentImpact = adjustments
|
||||
.filter((row) => row.status !== 'voided')
|
||||
.reduce(
|
||||
@@ -553,20 +587,19 @@ export default function PartnerPortal({
|
||||
<ConsoleCollectionSearch>
|
||||
<ConsoleFilterGrid
|
||||
onReset={() => {
|
||||
billSearch.cancelPendingSearch();
|
||||
setAppliedBill({ month: 'all', status: 'all' });
|
||||
setBillMonth('all');
|
||||
setBillStatus('all');
|
||||
setBillPage(1);
|
||||
}}
|
||||
onSearch={() => setBillPage(1)}
|
||||
onSearch={billSearch.submitSearch}
|
||||
>
|
||||
<ConsoleFilterField label={t('账期')} id='partner-bill-month'>
|
||||
<Select
|
||||
id='partner-bill-month'
|
||||
value={billMonth}
|
||||
onChange={(value) => {
|
||||
setBillMonth(value);
|
||||
setBillPage(1);
|
||||
}}
|
||||
onChange={billSearch.changeFilter(setBillMonth)}
|
||||
optionList={[
|
||||
{ value: 'all', label: t('全部账期') },
|
||||
...Array.from(new Set(rows.map((row) => row.statement_month)))
|
||||
@@ -580,10 +613,7 @@ export default function PartnerPortal({
|
||||
<Select
|
||||
id='partner-bill-status'
|
||||
value={billStatus}
|
||||
onChange={(value) => {
|
||||
setBillStatus(value);
|
||||
setBillPage(1);
|
||||
}}
|
||||
onChange={billSearch.changeFilter(setBillStatus)}
|
||||
optionList={[
|
||||
{ value: 'all', label: t('全部状态') },
|
||||
...Array.from(new Set(rows.map((row) => row.status))).map(
|
||||
@@ -609,8 +639,13 @@ export default function PartnerPortal({
|
||||
dataSource={visibleBills}
|
||||
columns={billColumns}
|
||||
pagination={
|
||||
visibleBills.length > 0
|
||||
? { pageSize: 10, current: billPage, onPageChange: setBillPage }
|
||||
visibleBills.length > 0 || billPage > 1
|
||||
? {
|
||||
pageSize: 10,
|
||||
current: billPage,
|
||||
onPageChange: setBillPage,
|
||||
preservePage: true,
|
||||
}
|
||||
: false
|
||||
}
|
||||
scroll={{ x: 1120 }}
|
||||
@@ -738,10 +773,12 @@ export default function PartnerPortal({
|
||||
<ConsoleCollectionSearch>
|
||||
<ConsoleFilterGrid
|
||||
onReset={() => {
|
||||
detailSearch.cancelPendingSearch();
|
||||
setQuery('');
|
||||
setAppliedDetail('');
|
||||
setDetailPage(1);
|
||||
}}
|
||||
onSearch={() => setDetailPage(1)}
|
||||
onSearch={detailSearch.submitSearch}
|
||||
>
|
||||
<ConsoleFilterField
|
||||
label={t('搜索关键字')}
|
||||
@@ -751,10 +788,7 @@ export default function PartnerPortal({
|
||||
id='partner-bill-detail-query'
|
||||
prefix={<Search size={16} />}
|
||||
value={query}
|
||||
onChange={(value) => {
|
||||
setQuery(value);
|
||||
setDetailPage(1);
|
||||
}}
|
||||
onChange={detailSearch.changeFilter(setQuery)}
|
||||
placeholder={t('搜索客户、模型、计费记录或档位')}
|
||||
showClear
|
||||
/>
|
||||
@@ -767,8 +801,9 @@ export default function PartnerPortal({
|
||||
columns={BillingColumns(t, money, formatDateTime)}
|
||||
scroll={{ x: 1800 }}
|
||||
pagination={
|
||||
detailItems.length > 0
|
||||
detailItems.length > 0 || detailPage > 1
|
||||
? {
|
||||
preservePage: true,
|
||||
pageSize: 10,
|
||||
current: detailPage,
|
||||
onPageChange: setDetailPage,
|
||||
@@ -1000,11 +1035,13 @@ export default function PartnerPortal({
|
||||
<ConsoleCollectionSearch>
|
||||
<ConsoleFilterGrid
|
||||
onReset={() => {
|
||||
customerSearch.cancelPendingSearch();
|
||||
setAppliedCustomer({ keyword: '', status: 'all' });
|
||||
setCustomerQuery('');
|
||||
setCustomerStatus('all');
|
||||
setCustomerPage(1);
|
||||
}}
|
||||
onSearch={() => setCustomerPage(1)}
|
||||
onSearch={customerSearch.submitSearch}
|
||||
>
|
||||
<ConsoleFilterField
|
||||
label={t('搜索关键字')}
|
||||
@@ -1014,10 +1051,7 @@ export default function PartnerPortal({
|
||||
id='partner-customer-query'
|
||||
prefix={<Search size={16} />}
|
||||
value={customerQuery}
|
||||
onChange={(value) => {
|
||||
setCustomerQuery(value);
|
||||
setCustomerPage(1);
|
||||
}}
|
||||
onChange={customerSearch.changeFilter(setCustomerQuery)}
|
||||
showClear
|
||||
placeholder={t('搜索客户名称或编号')}
|
||||
/>
|
||||
@@ -1026,10 +1060,7 @@ export default function PartnerPortal({
|
||||
<Select
|
||||
id='partner-customer-status'
|
||||
value={customerStatus}
|
||||
onChange={(value) => {
|
||||
setCustomerStatus(value);
|
||||
setCustomerPage(1);
|
||||
}}
|
||||
onChange={customerSearch.changeFilter(setCustomerStatus)}
|
||||
optionList={[
|
||||
{ value: 'all', label: t('全部状态') },
|
||||
...Array.from(new Set(customers.map((row) => row.status))).map(
|
||||
@@ -1054,8 +1085,9 @@ export default function PartnerPortal({
|
||||
rowKey='id'
|
||||
dataSource={visibleCustomers}
|
||||
pagination={
|
||||
visibleCustomers.length > 0
|
||||
visibleCustomers.length > 0 || customerPage > 1
|
||||
? {
|
||||
preservePage: true,
|
||||
pageSize: 10,
|
||||
current: customerPage,
|
||||
onPageChange: setCustomerPage,
|
||||
|
||||
Reference in New Issue
Block a user