/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Empty, Input, Select } from 'antd';
import { Table } from '@/components/ui';
import { Download, Search } from '@/components/common/icons/ActionIcons';
import {
ConsoleCard,
ConsoleFilterGrid,
ConsoleTabs,
} from '../../components/console/ConsolePrimitives';
import { ConsoleCollectionSearch } from '../../components/console/ConsoleCollection';
import { filterCommissionRows, matchesStatus } from './listFilters';
export default function ListPanel({
section,
rows,
columns,
partners,
searchableText,
onExport,
toolbarActions,
context,
server,
}) {
const { t } = useTranslation();
const [draft, setDraft] = useState({ query: '', type: '', partner: '' });
const [filters, setFilters] = useState({});
const [scopedIds, setScopedIds] = useState(context?.ids || null);
const [status, setStatus] = useState('all');
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const set = (key, value) =>
setDraft((current) => ({ ...current, [key]: value }));
const tabSets = {
assignments: [
['all', '全部'],
['protect', '保护中'],
['pending_conversion', '待确认转化'],
['formal', '正式归属'],
['history', '历史归属'],
],
bills: [
['all', '全部'],
['estimated', '本月预估'],
['checking', '待核对'],
['pending_confirmation', '待确认'],
['confirmed', '已确认'],
['completed', '已完成'],
],
adjustments: [
['all', '全部'],
['applied', '已生效'],
['voided', '已作废'],
],
tiers: [
['all', '全部档位'],
['enabled', '启用中'],
['scheduled', '待生效'],
['disabled', '已停用'],
],
};
const typeOptions =
section === 'partners'
? [
['company', '企业'],
['individual', '个人'],
]
: section === 'assignments'
? [
['organization', '企业'],
['user', 'C 端'],
]
: section === 'tiers'
? [
['level', '等级档位'],
['model', '模型档位'],
['channel', '渠道档位'],
]
: null;
const placeholders = {
partners: '搜索伙伴名称 / 编号 / 协议编号',
assignments: '搜索客户名称 / ID',
tiers: '搜索档位 / 模型 / 渠道',
bills: '搜索伙伴 / 账单号',
adjustments: '搜索调整单 / 客户 / 原因',
audit: '搜索操作 / 实体 / 操作人',
exceptions: '搜索异常码 / 计费事实 / 说明',
};
const scopedRows = scopedIds
? rows.filter((row) => scopedIds.includes(row.id))
: rows;
const filtered = server
? rows
: filterCommissionRows(
scopedRows,
{
...filters,
status: section === 'partners' ? filters.status : status,
},
section,
searchableText,
);
const query = () => {
setFilters(draft);
setPage(1);
server?.onChange({ ...draft, status, page: 1 });
};
const reset = () => {
setDraft({ query: '', type: '', partner: '' });
setFilters({});
setStatus('all');
server?.onChange({ status: 'all', page: 1 });
setScopedIds(null);
setPage(1);
};
return (
{tabSets[section] && (
{
setStatus(key);
setPage(1);
server?.onChange({ ...filters, status: key, page: 1 });
}}
items={tabSets[section].map(([key, label]) => ({
key,
label: (
{t(label)}{' '}
{server
? server.counts[
{ enabled: 'active', scheduled: 'pending' }[key] || key
] || 0
: rows.filter((row) => matchesStatus(row, key, section))
.length}
),
}))}
/>
)}
{scopedIds && (
{t('正在查看工作台待办筛选结果')}
)}
{typeOptions && (
)}
{section === 'partners' && (
)}
{['assignments', 'bills', 'adjustments'].includes(section) && (
)}
{t('共 {{count}} 条', {
count: server ? server.total : filtered.length,
})}
{onExport && (
}
loading={server?.exporting}
disabled={!!server?.busy}
onClick={() => onExport(filtered)}
>
{t('导出')}
)}
{toolbarActions}
({
width: 160,
...column,
...(/(?:_uyuan|_yuan|_bps|amount|count|quantity)$/.test(
column.dataIndex || '',
)
? { align: 'right' }
: {}),
}))}
dataSource={filtered}
size='middle'
scroll={{ x: 'max-content' }}
pagination={
(server ? server.total : filtered.length)
? {
size: 'small',
pageSize: server ? server.pageSize : pageSize,
total: server ? server.total : filtered.length,
currentPage: server ? server.page : page,
onPageChange: (next) => {
setPage(next);
server?.onChange({ ...filters, status, page: next });
},
onPageSizeChange: (nextSize) => {
setPage(1);
setPageSize(nextSize);
server?.onChange({
...filters,
status,
page: 1,
pageSize: nextSize,
});
},
}
: false
}
empty={
}
/>
);
}