331 lines
10 KiB
React
331 lines
10 KiB
React
/*
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
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 (
|
|
<div className={`commission-list commission-list--${section}`}>
|
|
{tabSets[section] && (
|
|
<ConsoleTabs
|
|
className='commission-list-tabs'
|
|
activeKey={status}
|
|
onChange={(key) => {
|
|
setStatus(key);
|
|
setPage(1);
|
|
server?.onChange({ ...filters, status: key, page: 1 });
|
|
}}
|
|
items={tabSets[section].map(([key, label]) => ({
|
|
key,
|
|
label: (
|
|
<span>
|
|
{t(label)}{' '}
|
|
<span className='commission-tab-count'>
|
|
{server
|
|
? server.counts[
|
|
{ enabled: 'active', scheduled: 'pending' }[key] || key
|
|
] || 0
|
|
: rows.filter((row) => matchesStatus(row, key, section))
|
|
.length}
|
|
</span>
|
|
</span>
|
|
),
|
|
}))}
|
|
/>
|
|
)}
|
|
{scopedIds && (
|
|
<div className='commission-context-filter'>
|
|
{t('正在查看工作台待办筛选结果')}
|
|
<Button
|
|
type='link'
|
|
size='small'
|
|
onClick={() => {
|
|
setScopedIds(null);
|
|
setPage(1);
|
|
}}
|
|
>
|
|
{t('查看全部')}
|
|
</Button>
|
|
</div>
|
|
)}
|
|
<ConsoleCollectionSearch className='commission-filter-card'>
|
|
<ConsoleFilterGrid
|
|
onReset={reset}
|
|
onSearch={query}
|
|
loading={server?.busy}
|
|
>
|
|
<label className='console-search-field commission-search-field'>
|
|
<span>{t('搜索')}</span>
|
|
<Input
|
|
prefix={<Search size={16} aria-hidden />}
|
|
value={draft.query}
|
|
onChange={(event) => set('query', event.target.value)}
|
|
allowClear
|
|
placeholder={t(placeholders[section])}
|
|
aria-label={t(placeholders[section])}
|
|
/>
|
|
</label>
|
|
{typeOptions && (
|
|
<label className='console-search-field commission-search-field'>
|
|
<span>{t('类型筛选')}</span>
|
|
<Select
|
|
aria-label={t('类型筛选')}
|
|
value={draft.type}
|
|
onChange={(value) => set('type', value)}
|
|
options={[
|
|
{
|
|
value: '',
|
|
label: t(
|
|
section === 'assignments'
|
|
? '全部客户类型'
|
|
: section === 'tiers'
|
|
? '全部来源'
|
|
: '全部类型',
|
|
),
|
|
},
|
|
...typeOptions.map(([value, label]) => ({
|
|
value,
|
|
label: t(label),
|
|
})),
|
|
]}
|
|
/>
|
|
</label>
|
|
)}
|
|
{section === 'partners' && (
|
|
<label className='console-search-field commission-search-field'>
|
|
<span>{t('状态筛选')}</span>
|
|
<Select
|
|
aria-label={t('状态筛选')}
|
|
value={draft.status || ''}
|
|
onChange={(value) => set('status', value)}
|
|
options={['', 'draft', 'active', 'suspended', 'terminated'].map(
|
|
(value, i) => ({
|
|
value,
|
|
label: t(
|
|
['全部状态', '草稿', '生效中', '已暂停', '已终止'][i],
|
|
),
|
|
}),
|
|
)}
|
|
/>
|
|
</label>
|
|
)}
|
|
{['assignments', 'bills', 'adjustments'].includes(section) && (
|
|
<label className='console-search-field commission-search-field'>
|
|
<span>{t('合作伙伴筛选')}</span>
|
|
<Select
|
|
aria-label={t('合作伙伴筛选')}
|
|
showSearch={{ optionFilterProp: 'label' }}
|
|
value={draft.partner}
|
|
onChange={(value) => set('partner', value)}
|
|
options={[
|
|
{ value: '', label: t('全部合作伙伴') },
|
|
...partners.map((row) => ({
|
|
value: row.id,
|
|
label: row.name,
|
|
})),
|
|
]}
|
|
/>
|
|
</label>
|
|
)}
|
|
</ConsoleFilterGrid>
|
|
</ConsoleCollectionSearch>
|
|
<ConsoleCard className='commission-card commission-list-card'>
|
|
<div className='console-list-tools commission-filter-end'>
|
|
<span>
|
|
{t('共 {{count}} 条', {
|
|
count: server ? server.total : filtered.length,
|
|
})}
|
|
</span>
|
|
<div className='console-list-tool-actions'>
|
|
{onExport && (
|
|
<Button
|
|
icon={<Download size={16} />}
|
|
loading={server?.exporting}
|
|
disabled={!!server?.busy}
|
|
onClick={() => onExport(filtered)}
|
|
>
|
|
{t('导出')}
|
|
</Button>
|
|
)}
|
|
{toolbarActions}
|
|
</div>
|
|
</div>
|
|
<Table
|
|
rowKey='id'
|
|
loading={server?.busy}
|
|
columns={columns.map((column) => ({
|
|
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={
|
|
<Empty
|
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
description={t('暂无数据')}
|
|
/>
|
|
}
|
|
/>
|
|
</ConsoleCard>
|
|
</div>
|
|
);
|
|
}
|