1542 lines
51 KiB
React
1542 lines
51 KiB
React
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,
|
||
ConsoleFilterGrid,
|
||
} from '@/components/console/ConsolePrimitives';
|
||
import React, {
|
||
useCallback,
|
||
useEffect,
|
||
useLayoutEffect,
|
||
useMemo,
|
||
useRef,
|
||
useState,
|
||
} from 'react';
|
||
import { useLocation, useSearchParams } from 'react-router-dom';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { Button, Empty, Layout, Spin, Tag, Typography } from 'antd';
|
||
// 存量 Semi 契约(受控值 onChange(value)、visible、empty、Tabs.TabPane 等)与控制台
|
||
// 作用域(ConsoleCard / ConsoleModal / ConsoleTable / ConsoleTabs / ConsoleAlert)由适配层统一映射。
|
||
import {
|
||
Alert,
|
||
Card,
|
||
Input,
|
||
Modal,
|
||
Select,
|
||
Table,
|
||
Tabs,
|
||
TextArea,
|
||
} from '@/components/ui';
|
||
import {
|
||
ArrowLeft as ActionArrowLeft,
|
||
Download,
|
||
Search,
|
||
RefreshCw as ActionRefresh,
|
||
} from '@/components/common/icons/ActionIcons';
|
||
import {
|
||
Bell,
|
||
ChevronRight,
|
||
CircleDollarSign,
|
||
FileText,
|
||
Home,
|
||
ScrollText,
|
||
TrendingUp,
|
||
Users,
|
||
} from 'lucide-react';
|
||
import { BillingColumns, AdjustmentColumns } from './operations';
|
||
import { commissionLabel } from './labels';
|
||
import { PARTNER_NAVIGATION, partnerView } from './partnerNavigation';
|
||
import './partnerPortal.css';
|
||
import OrgPageHeader from '../Organization/components/OrgPageHeader';
|
||
import OrgModal from '../Organization/components/OrgModal';
|
||
import { useCommissionThemeStyle } from './commissionTheme';
|
||
|
||
const { Content } = Layout;
|
||
const { Title, Text } = Typography;
|
||
const PROTECTED = ['protected', 'protected_extended', 'pending_conversion'];
|
||
const NAV_ICONS = {
|
||
overview: Home,
|
||
customers: Users,
|
||
estimate: TrendingUp,
|
||
bills: FileText,
|
||
rules: ScrollText,
|
||
};
|
||
const NAVIGATION = PARTNER_NAVIGATION.map((item) => ({
|
||
...item,
|
||
icon: NAV_ICONS[item.key],
|
||
}));
|
||
const protectionUntil = (row) =>
|
||
Number(row.extended_until || row.protected_until || 0);
|
||
|
||
function Metric({ label, value, note, primary = false }) {
|
||
return (
|
||
<div className={`partner-portal-metric${primary ? ' is-primary' : ''}`}>
|
||
<div className='partner-portal-metric-label'>{label}</div>
|
||
<div className='partner-portal-metric-value'>{value}</div>
|
||
{note && <div className='partner-portal-metric-note'>{note}</div>}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export default function PartnerPortal({
|
||
fetchJSON,
|
||
mutateJSON,
|
||
money,
|
||
date,
|
||
formatDateTime,
|
||
exportDetails,
|
||
TierSummary,
|
||
PaymentTable,
|
||
tag,
|
||
embedded = false,
|
||
}) {
|
||
const themeStyle = useCommissionThemeStyle();
|
||
const PartnerModal = embedded ? OrgModal : Modal;
|
||
const { t } = useTranslation();
|
||
const location = useLocation();
|
||
const [searchParams, setSearchParams] = useSearchParams();
|
||
const [localActive, setLocalActive] = useState('overview');
|
||
const active = embedded ? partnerView(location.search) : localActive;
|
||
const internalSearch = useRef(null);
|
||
const setActive = (key) => {
|
||
if (!embedded) {
|
||
setLocalActive(key);
|
||
return;
|
||
}
|
||
if (active === key) return;
|
||
const next = new URLSearchParams(searchParams);
|
||
next.set('view', key);
|
||
internalSearch.current = `?${next}`;
|
||
setSearchParams(next);
|
||
};
|
||
const [loading, setLoading] = useState(true);
|
||
const [loaded, setLoaded] = useState(false);
|
||
const [error, setError] = useState('');
|
||
const [data, setData] = useState({
|
||
rows: [],
|
||
realtime: [],
|
||
customers: [],
|
||
summary: {},
|
||
});
|
||
const [selected, setSelected] = useState(null);
|
||
const [details, setDetails] = useState({
|
||
items: [],
|
||
adjustments: [],
|
||
payments: [],
|
||
});
|
||
const [detailLoading, setDetailLoading] = useState(false);
|
||
const [mutationLoading, setMutationLoading] = useState(false);
|
||
const [exportingId, setExportingId] = useState(null);
|
||
const [action, setAction] = useState(null);
|
||
const [reason, setReason] = useState('');
|
||
const [actionError, setActionError] = useState('');
|
||
const [query, setQuery] = useState('');
|
||
const [customerQuery, setCustomerQuery] = useState('');
|
||
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);
|
||
const loadVersion = useRef(0);
|
||
const detailVersion = useRef(0);
|
||
const selectedId = useRef(null);
|
||
const mounted = useRef(true);
|
||
const mutationBusy = useRef(false);
|
||
// Sidebar links and browser history must dismiss old details/confirmations.
|
||
// Internal overview -> statement navigation preserves the detail being opened.
|
||
useLayoutEffect(() => {
|
||
if (!embedded) return;
|
||
const internal = internalSearch.current === location.search;
|
||
internalSearch.current = null;
|
||
if (internal) return;
|
||
detailVersion.current++;
|
||
selectedId.current = null;
|
||
setSelected(null);
|
||
setDetailLoading(false);
|
||
setAction(null);
|
||
setActionError('');
|
||
}, [embedded, location.key, location.search]);
|
||
const { rows, realtime, customers, summary } = data;
|
||
const { items, adjustments, payments } = details;
|
||
|
||
const load = useCallback(async () => {
|
||
const version = ++loadVersion.current;
|
||
setLoading(true);
|
||
setError('');
|
||
try {
|
||
const [statements, estimate, assignments, overview] = await Promise.all([
|
||
fetchJSON('/api/partner/v2/statements'),
|
||
fetchJSON('/api/partner/v2/realtime'),
|
||
fetchJSON('/api/partner/v2/assignments'),
|
||
fetchJSON('/api/partner/v2/summary'),
|
||
]);
|
||
if (mounted.current && version === loadVersion.current) {
|
||
setData({
|
||
rows: statements,
|
||
realtime: estimate,
|
||
customers: assignments,
|
||
summary: overview,
|
||
});
|
||
setLoaded(true);
|
||
}
|
||
} catch (err) {
|
||
if (mounted.current && version === loadVersion.current)
|
||
setError(err.message);
|
||
} finally {
|
||
if (mounted.current && version === loadVersion.current) setLoading(false);
|
||
}
|
||
}, [fetchJSON]);
|
||
|
||
const invalidateRequests = useCallback(() => {
|
||
loadVersion.current++;
|
||
detailVersion.current++;
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
mounted.current = true;
|
||
load();
|
||
return () => {
|
||
mounted.current = false;
|
||
invalidateRequests();
|
||
};
|
||
}, [load, invalidateRequests]);
|
||
|
||
const readDetail = useCallback(
|
||
async (id) => {
|
||
const [statement, statementItems, changes, paymentRows] =
|
||
await Promise.all([
|
||
fetchJSON(`/api/partner/v2/statements/${id}`),
|
||
fetchJSON(`/api/partner/v2/statements/${id}/items`),
|
||
fetchJSON(`/api/partner/v2/statements/${id}/adjustments`),
|
||
fetchJSON(`/api/partner/v2/statements/${id}/payments`),
|
||
]);
|
||
return {
|
||
statement,
|
||
items: statementItems,
|
||
adjustments: changes,
|
||
payments: paymentRows,
|
||
};
|
||
},
|
||
[fetchJSON],
|
||
);
|
||
|
||
const navigate = (key) => {
|
||
if (mutationBusy.current) return;
|
||
detailVersion.current++;
|
||
selectedId.current = null;
|
||
setSelected(null);
|
||
setDetailLoading(false);
|
||
setActive(key);
|
||
setAction(null);
|
||
setActionError('');
|
||
};
|
||
|
||
const open = async (row, nextAction = null) => {
|
||
if (mutationBusy.current) return;
|
||
const version = ++detailVersion.current;
|
||
selectedId.current = row.id;
|
||
setActive('bills');
|
||
setSelected(row);
|
||
setDetails({ items: [], adjustments: [], payments: [] });
|
||
setDetailLoading(true);
|
||
setError('');
|
||
setQuery('');
|
||
detailSearch.cancelPendingSearch();
|
||
setQuery('');
|
||
setAppliedDetail('');
|
||
setDetailPage(1);
|
||
setAction(null);
|
||
setReason('');
|
||
setActionError('');
|
||
try {
|
||
const result = await readDetail(row.id);
|
||
if (!mounted.current || version !== detailVersion.current) return;
|
||
setSelected(result.statement);
|
||
setDetails(result);
|
||
if (nextAction && result.statement.status === 'pending_confirmation')
|
||
setAction(nextAction);
|
||
} catch (err) {
|
||
if (!mounted.current || version !== detailVersion.current) return;
|
||
selectedId.current = null;
|
||
setSelected(null);
|
||
setError(err.message);
|
||
} finally {
|
||
if (mounted.current && version === detailVersion.current)
|
||
setDetailLoading(false);
|
||
}
|
||
};
|
||
|
||
const transition = async () => {
|
||
if (
|
||
!mounted.current ||
|
||
mutationBusy.current ||
|
||
!selected ||
|
||
selected.status !== 'pending_confirmation' ||
|
||
!action
|
||
)
|
||
return;
|
||
if (action === 'reject' && !reason.trim()) {
|
||
setActionError(t('请填写驳回原因'));
|
||
return;
|
||
}
|
||
const id = selected.id;
|
||
mutationBusy.current = true;
|
||
setMutationLoading(true);
|
||
setActionError('');
|
||
let committed = false;
|
||
try {
|
||
await mutateJSON('post', `/api/partner/v2/statements/${id}/transition`, {
|
||
to: action === 'reject' ? 'checking' : 'confirmed',
|
||
reason: reason.trim(),
|
||
});
|
||
committed = true;
|
||
if (!mounted.current) return;
|
||
setAction(null);
|
||
setReason('');
|
||
// Invalidate any detail request made before the mutation committed.
|
||
const version = ++detailVersion.current;
|
||
setDetailLoading(true);
|
||
await Promise.all([
|
||
load(),
|
||
readDetail(id).then((result) => {
|
||
if (
|
||
mounted.current &&
|
||
version === detailVersion.current &&
|
||
selectedId.current === id
|
||
) {
|
||
setSelected(result.statement);
|
||
setDetails(result);
|
||
}
|
||
}),
|
||
]);
|
||
} catch (err) {
|
||
if (mounted.current) {
|
||
setActionError(err.message);
|
||
setError(err.message);
|
||
if (committed) {
|
||
detailVersion.current++;
|
||
selectedId.current = null;
|
||
setSelected(null);
|
||
}
|
||
}
|
||
} finally {
|
||
mutationBusy.current = false;
|
||
if (mounted.current) {
|
||
setMutationLoading(false);
|
||
setDetailLoading(false);
|
||
}
|
||
}
|
||
};
|
||
|
||
const exportStatement = async (row) => {
|
||
if (exportingId !== null || mutationBusy.current) return;
|
||
setExportingId(row.id);
|
||
setError('');
|
||
try {
|
||
const result = await readDetail(row.id);
|
||
if (mounted.current)
|
||
exportDetails(result.items, result.adjustments, result.statement, t);
|
||
} catch (err) {
|
||
if (mounted.current) setError(err.message);
|
||
} finally {
|
||
if (mounted.current) setExportingId(null);
|
||
}
|
||
};
|
||
|
||
const totals = useMemo(
|
||
() =>
|
||
realtime.reduce(
|
||
(sum, row) => ({
|
||
sales: sum.sales + Number(row.base_amount_uyuan || 0),
|
||
commission: sum.commission + Number(row.estimated_uyuan || 0),
|
||
count: sum.count + Number(row.detail_count || 0),
|
||
}),
|
||
{ sales: 0, commission: 0, count: 0 },
|
||
),
|
||
[realtime],
|
||
);
|
||
const pending = rows.filter((row) => row.status === 'pending_confirmation');
|
||
const formalCount = customers.filter((row) => row.status === 'formal').length;
|
||
const protectedCount = customers.filter((row) =>
|
||
PROTECTED.includes(row.status),
|
||
).length;
|
||
const earliestDeadline = pending.reduce((min, row) => {
|
||
const value = Number(row.confirmation_deadline || 0);
|
||
return value > 0 && (!min || value < min) ? value : min;
|
||
}, 0);
|
||
const currentMonth =
|
||
realtime[0]?.statement_month ||
|
||
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, '0')}`;
|
||
const currentStatements = rows.filter(
|
||
(row) => row.statement_month === currentMonth,
|
||
);
|
||
const matchesDetail = useCallback(
|
||
(item) =>
|
||
!appliedDetail ||
|
||
[
|
||
item.customer_name,
|
||
item.model_name,
|
||
item.billing_record_id,
|
||
item.tier_key,
|
||
].some((value) =>
|
||
String(value || '')
|
||
.toLowerCase()
|
||
.includes(appliedDetail),
|
||
),
|
||
[appliedDetail],
|
||
);
|
||
const detailItems = useFilteredTableRows(items, matchesDetail);
|
||
const matchesCustomer = useCallback(
|
||
(row) =>
|
||
(appliedCustomer.status === 'all' ||
|
||
row.status === appliedCustomer.status) &&
|
||
(!appliedCustomer.keyword ||
|
||
[row.customer_name, row.subject_name, row.subject_id].some((value) =>
|
||
String(value || '')
|
||
.toLowerCase()
|
||
.includes(appliedCustomer.keyword),
|
||
)),
|
||
[appliedCustomer],
|
||
);
|
||
const visibleCustomers = useFilteredTableRows(customers, matchesCustomer);
|
||
const matchesBill = useCallback(
|
||
(row) =>
|
||
(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(
|
||
(sum, row) =>
|
||
sum +
|
||
Number(
|
||
row.commission_impact_uyuan ??
|
||
(row.type === 'commission_amount' ? row.amount_uyuan : 0),
|
||
),
|
||
0,
|
||
);
|
||
const recentMonths = useMemo(() => {
|
||
const months = new Map();
|
||
for (const row of rows)
|
||
months.set(
|
||
row.statement_month,
|
||
(months.get(row.statement_month) || 0) +
|
||
Number(row.estimated_uyuan || 0),
|
||
);
|
||
return Array.from(months, ([month, amount]) => ({ month, amount }))
|
||
.sort((a, b) => a.month.localeCompare(b.month))
|
||
.slice(-6);
|
||
}, [rows]);
|
||
const chartMax = Math.max(
|
||
1,
|
||
...recentMonths.map((row) => Math.abs(row.amount)),
|
||
);
|
||
const expiringCustomers = customers.filter(
|
||
(row) =>
|
||
PROTECTED.includes(row.status) &&
|
||
protectionUntil(row) > Date.now() / 1000 &&
|
||
protectionUntil(row) < Date.now() / 1000 + 7 * 86400,
|
||
);
|
||
const agreementExpiring =
|
||
summary.agreement_expires_at > Date.now() / 1000 &&
|
||
summary.agreement_expires_at < Date.now() / 1000 + 30 * 86400;
|
||
const pageTitle = selected
|
||
? '提成账单详情'
|
||
: NAVIGATION.find((item) => item.key === active).label;
|
||
const subtitles = {
|
||
overview: '本月数据为实时预估,以正式提成账单为准',
|
||
customers: '仅展示归属于您的客户及状态,不提供编辑功能',
|
||
estimate: '预估数据不含后续人工调整,实际以正式提成账单为准',
|
||
bills: '查看月度提成账单,并在线确认或驳回;确认后由平台办理后续结算',
|
||
rules: '查看分佣计算与结算规则;具体合作条款以签署协议为准',
|
||
};
|
||
const billColumns = [
|
||
{
|
||
title: t('账单号'),
|
||
dataIndex: 'id',
|
||
render: (value) => <span className='partner-portal-mono'>#{value}</span>,
|
||
},
|
||
{ title: t('账期'), dataIndex: 'statement_month' },
|
||
{
|
||
title: t('应计提成'),
|
||
dataIndex: 'estimated_uyuan',
|
||
render: money,
|
||
align: 'right',
|
||
},
|
||
{
|
||
title: t('手续费'),
|
||
dataIndex: 'fee_uyuan',
|
||
render: money,
|
||
align: 'right',
|
||
},
|
||
{
|
||
title: t('应付提成'),
|
||
dataIndex: 'payable_uyuan',
|
||
render: (value) => <b>{money(value)}</b>,
|
||
align: 'right',
|
||
},
|
||
{
|
||
title: t('状态'),
|
||
render: (_, row) =>
|
||
row.status === 'checking' && row.rejected_at ? (
|
||
<Tag color='error' variant='filled'>
|
||
{t('已驳回,平台核对中')}
|
||
</Tag>
|
||
) : (
|
||
tag(row.status)
|
||
),
|
||
},
|
||
{
|
||
title: t('确认截止'),
|
||
dataIndex: 'confirmation_deadline',
|
||
render: (value, row) =>
|
||
row.status === 'pending_confirmation' ? formatDateTime(value) : '—',
|
||
},
|
||
{
|
||
title: t('操作'),
|
||
width: 230,
|
||
render: (_, row) => (
|
||
<div className='partner-portal-row-actions'>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
disabled={mutationLoading}
|
||
onClick={() => open(row)}
|
||
>
|
||
{t('查看')}
|
||
</Button>
|
||
{row.status === 'pending_confirmation' && (
|
||
<>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
disabled={mutationLoading}
|
||
onClick={() => open(row, 'confirm')}
|
||
>
|
||
{t('确认')}
|
||
</Button>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
danger
|
||
disabled={mutationLoading}
|
||
onClick={() => open(row, 'reject')}
|
||
>
|
||
{t('驳回')}
|
||
</Button>
|
||
</>
|
||
)}
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
disabled={exportingId !== null || mutationLoading}
|
||
loading={exportingId === row.id}
|
||
onClick={() => exportStatement(row)}
|
||
>
|
||
{t('导出')}
|
||
</Button>
|
||
</div>
|
||
),
|
||
},
|
||
];
|
||
|
||
const refreshButton = (
|
||
<Button
|
||
icon={<ActionRefresh size={16} />}
|
||
disabled={mutationLoading || detailLoading}
|
||
loading={loading}
|
||
onClick={() => {
|
||
load();
|
||
if (selected) open(selected);
|
||
}}
|
||
>
|
||
{t('刷新')}
|
||
</Button>
|
||
);
|
||
|
||
const renderBills = () => (
|
||
<>
|
||
<ConsoleCollectionSearch>
|
||
<ConsoleFilterGrid
|
||
onReset={() => {
|
||
billSearch.cancelPendingSearch();
|
||
setAppliedBill({ month: 'all', status: 'all' });
|
||
setBillMonth('all');
|
||
setBillStatus('all');
|
||
setBillPage(1);
|
||
}}
|
||
onSearch={billSearch.submitSearch}
|
||
>
|
||
<ConsoleFilterField label={t('账期')} id='partner-bill-month'>
|
||
<Select
|
||
id='partner-bill-month'
|
||
value={billMonth}
|
||
onChange={billSearch.changeFilter(setBillMonth)}
|
||
optionList={[
|
||
{ value: 'all', label: t('全部账期') },
|
||
...Array.from(new Set(rows.map((row) => row.statement_month)))
|
||
.sort()
|
||
.reverse()
|
||
.map((value) => ({ value, label: value })),
|
||
]}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('状态')} id='partner-bill-status'>
|
||
<Select
|
||
id='partner-bill-status'
|
||
value={billStatus}
|
||
onChange={billSearch.changeFilter(setBillStatus)}
|
||
optionList={[
|
||
{ value: 'all', label: t('全部状态') },
|
||
...Array.from(new Set(rows.map((row) => row.status))).map(
|
||
(value) => ({
|
||
value,
|
||
label: commissionLabel(t, 'status', value),
|
||
}),
|
||
),
|
||
]}
|
||
/>
|
||
</ConsoleFilterField>
|
||
</ConsoleFilterGrid>
|
||
</ConsoleCollectionSearch>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='console-list-tools commission-filter-end'>
|
||
<Text type='secondary'>
|
||
{t('共 {{count}} 张账单', { count: visibleBills.length })}
|
||
</Text>
|
||
<div className='console-list-tool-actions'>{refreshButton}</div>
|
||
</div>
|
||
<Table
|
||
rowKey='id'
|
||
dataSource={visibleBills}
|
||
columns={billColumns}
|
||
pagination={
|
||
visibleBills.length > 0 || billPage > 1
|
||
? {
|
||
pageSize: 10,
|
||
current: billPage,
|
||
onPageChange: setBillPage,
|
||
preservePage: true,
|
||
}
|
||
: false
|
||
}
|
||
scroll={{ x: 1120 }}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无分佣账单')}
|
||
/>
|
||
}
|
||
/>
|
||
<p className='partner-portal-hint'>
|
||
{t(
|
||
'待确认账单请在确认截止日期前确认或驳回;截止日前无反馈,系统视同确认。驳回后由平台核对修正,重新出账后请再次确认。',
|
||
)}
|
||
</p>
|
||
</Card>
|
||
</>
|
||
);
|
||
|
||
const renderDetail = () => (
|
||
<>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-detail-meta'>
|
||
<span>
|
||
{t('账单号')}:#{selected.id} · {t('账期')}:
|
||
{selected.statement_month}
|
||
</span>
|
||
{tag(selected.status)}
|
||
{selected.confirmation_deadline > 0 && (
|
||
<span>
|
||
{t('确认截止')}:{formatDateTime(selected.confirmation_deadline)}
|
||
</span>
|
||
)}
|
||
{selected.confirmation_method && (
|
||
<span>
|
||
{t(
|
||
selected.confirmation_method === 'timeout'
|
||
? '逾期视同确认'
|
||
: '伙伴确认',
|
||
)}
|
||
</span>
|
||
)}
|
||
</div>
|
||
{selected.status === 'checking' && (
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={
|
||
<>
|
||
{t('已驳回,平台核对中,重新出账后可确认修正后的账单。')}
|
||
{selected.rejection_reason && (
|
||
<p>
|
||
{t('驳回原因')}:{selected.rejection_reason}
|
||
</p>
|
||
)}
|
||
</>
|
||
}
|
||
/>
|
||
)}
|
||
{selected.status === 'completed' && (
|
||
<Alert
|
||
showIcon
|
||
type='success'
|
||
description={t(
|
||
Number(selected.payable_uyuan) === 0
|
||
? '无需付款,账单已完成'
|
||
: '已登记付款,账单已完成',
|
||
)}
|
||
/>
|
||
)}
|
||
</Card>
|
||
<div className='partner-portal-metrics'>
|
||
<Metric
|
||
label={t('有效销售额')}
|
||
value={
|
||
detailLoading
|
||
? '—'
|
||
: money(
|
||
selected.sales_amount_uyuan ??
|
||
items.reduce(
|
||
(sum, row) => sum + Number(row.base_amount_uyuan || 0),
|
||
0,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<Metric
|
||
label={t('应计提成')}
|
||
value={detailLoading ? '—' : money(selected.estimated_uyuan)}
|
||
/>
|
||
<Metric
|
||
label={t('手续费')}
|
||
value={detailLoading ? '—' : money(selected.fee_uyuan)}
|
||
/>
|
||
<Metric
|
||
label={t('本期应付')}
|
||
value={detailLoading ? '—' : money(selected.payable_uyuan)}
|
||
primary
|
||
/>
|
||
</div>
|
||
{detailLoading ? (
|
||
<div className='partner-portal-loading'>
|
||
<Spin />
|
||
</div>
|
||
) : (
|
||
<>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>
|
||
{t('按档位与消费场景汇总')}
|
||
</div>
|
||
<TierSummary items={items} />
|
||
<p className='partner-portal-hint'>
|
||
{t('调整单净提成影响')}:{money(adjustmentImpact)} ·{' '}
|
||
{t('已计入应计提成')}
|
||
</p>
|
||
<p className='partner-portal-hint'>
|
||
{t('上期结转扣减')}:{money(selected.carry_in_uyuan)} ·{' '}
|
||
{t('下期结转扣减')}:{money(selected.carry_out_uyuan)} ·{' '}
|
||
{t('舍入尾差')}:{money(selected.rounding_uyuan)}
|
||
</p>
|
||
</Card>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<Tabs defaultActiveKey='usage' key={selected.id}>
|
||
<Tabs.TabPane tab={t('单笔消耗明细')} itemKey='usage'>
|
||
<ConsoleCollectionSearch>
|
||
<ConsoleFilterGrid
|
||
onReset={() => {
|
||
detailSearch.cancelPendingSearch();
|
||
setQuery('');
|
||
setAppliedDetail('');
|
||
setDetailPage(1);
|
||
}}
|
||
onSearch={detailSearch.submitSearch}
|
||
>
|
||
<ConsoleFilterField
|
||
label={t('搜索关键字')}
|
||
id='partner-bill-detail-query'
|
||
>
|
||
<Input
|
||
id='partner-bill-detail-query'
|
||
prefix={<Search size={16} />}
|
||
value={query}
|
||
onChange={detailSearch.changeFilter(setQuery)}
|
||
placeholder={t('搜索客户、模型、计费记录或档位')}
|
||
showClear
|
||
/>
|
||
</ConsoleFilterField>
|
||
</ConsoleFilterGrid>
|
||
</ConsoleCollectionSearch>
|
||
<Table
|
||
rowKey='id'
|
||
dataSource={detailItems}
|
||
columns={BillingColumns(t, money, formatDateTime)}
|
||
scroll={{ x: 1800 }}
|
||
pagination={
|
||
detailItems.length > 0 || detailPage > 1
|
||
? {
|
||
preservePage: true,
|
||
pageSize: 10,
|
||
current: detailPage,
|
||
onPageChange: setDetailPage,
|
||
}
|
||
: false
|
||
}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无明细')}
|
||
/>
|
||
}
|
||
/>
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane
|
||
tab={`${t('调整单明细')} (${adjustments.length})`}
|
||
itemKey='adjustments'
|
||
>
|
||
<p className='partner-portal-hint'>
|
||
{t(
|
||
'调整单独立于模型调用消耗记录展示;提成金额调整不改变有效销售额。',
|
||
)}
|
||
</p>
|
||
<Table
|
||
rowKey='id'
|
||
dataSource={adjustments}
|
||
columns={AdjustmentColumns(t, money)}
|
||
scroll={{ x: 1000 }}
|
||
pagination={adjustments.length > 0 ? { pageSize: 10 } : false}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('本期无调整单')}
|
||
/>
|
||
}
|
||
/>
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('付款记录')} itemKey='payments'>
|
||
<PaymentTable payments={payments} />
|
||
</Tabs.TabPane>
|
||
</Tabs>
|
||
</Card>
|
||
</>
|
||
)}
|
||
</>
|
||
);
|
||
|
||
const renderOverview = () => (
|
||
<>
|
||
<div className='partner-portal-welcome'>
|
||
<CircleDollarSign size={18} />
|
||
<span>
|
||
{t('欢迎使用合作分佣工作台')} · {t('伙伴状态')}:
|
||
{commissionLabel(t, 'status', summary.partner_status)}
|
||
{summary.agreement_expires_at > 0 && (
|
||
<>
|
||
{' '}
|
||
· {t('协议有效期至')} {date(summary.agreement_expires_at)}
|
||
</>
|
||
)}
|
||
{' · '}
|
||
{t('如有疑问请联系平台运营。')}
|
||
</span>
|
||
</div>
|
||
<div className='partner-portal-metrics'>
|
||
<Metric
|
||
label={t('名下客户')}
|
||
value={customers.length}
|
||
note={`${t('正式归属')} ${formalCount} · ${t('保护中')} ${protectedCount}`}
|
||
/>
|
||
<Metric
|
||
label={t('本月有效销售额(预估)')}
|
||
value={
|
||
summary.partner_status === 'terminated' ? '—' : money(totals.sales)
|
||
}
|
||
/>
|
||
<Metric
|
||
label={t('本月预估提成')}
|
||
value={
|
||
summary.partner_status === 'terminated'
|
||
? '—'
|
||
: money(totals.commission)
|
||
}
|
||
primary
|
||
/>
|
||
<Metric
|
||
label={t('待确认账单')}
|
||
value={pending.length}
|
||
note={
|
||
earliestDeadline
|
||
? `${t('最早确认截止')} ${date(earliestDeadline)}`
|
||
: t('暂无待确认账单')
|
||
}
|
||
/>
|
||
</div>
|
||
<div className='partner-portal-two-columns'>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>
|
||
{t('近 6 个账期提成')}
|
||
<span>{t('正式账单应计提成')}</span>
|
||
</div>
|
||
{recentMonths.length ? (
|
||
<div
|
||
className='partner-portal-chart'
|
||
role='img'
|
||
aria-label={t('近 6 个账期提成')}
|
||
>
|
||
{recentMonths.map((row) => (
|
||
<div className='partner-portal-chart-column' key={row.month}>
|
||
<span className='partner-portal-chart-value'>
|
||
{money(row.amount)}
|
||
</span>
|
||
<div
|
||
className={`partner-portal-chart-bar${row.amount < 0 ? ' is-negative' : ''}`}
|
||
style={{
|
||
height: `${Math.max(2, (Math.abs(row.amount) / chartMax) * 130)}px`,
|
||
}}
|
||
/>
|
||
<span className='partner-portal-chart-label'>
|
||
{row.month}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
) : (
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无正式账单数据')}
|
||
/>
|
||
)}
|
||
</Card>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>
|
||
{t('提醒')}
|
||
<Bell size={16} />
|
||
</div>
|
||
<div className='partner-portal-reminders'>
|
||
{rows
|
||
.filter((row) =>
|
||
['pending_confirmation', 'confirmed', 'checking'].includes(
|
||
row.status,
|
||
),
|
||
)
|
||
.slice(0, 5)
|
||
.map((row) => (
|
||
<button
|
||
key={row.id}
|
||
className='partner-portal-reminder'
|
||
onClick={() => open(row)}
|
||
>
|
||
<span className='partner-portal-reminder-icon'>
|
||
<FileText size={17} />
|
||
</span>
|
||
<span>
|
||
{row.statement_month} ·{' '}
|
||
{t(
|
||
row.status === 'pending_confirmation'
|
||
? '提成账单待确认'
|
||
: row.status === 'checking'
|
||
? '平台核对中'
|
||
: '已确认待打款',
|
||
)}
|
||
{row.status === 'pending_confirmation' && (
|
||
<small>
|
||
{t('确认截止')}:{date(row.confirmation_deadline)}
|
||
</small>
|
||
)}
|
||
</span>
|
||
<ChevronRight size={15} />
|
||
</button>
|
||
))}
|
||
{expiringCustomers.map((row) => (
|
||
<button
|
||
key={`customer-${row.id}`}
|
||
className='partner-portal-reminder'
|
||
onClick={() => navigate('customers')}
|
||
>
|
||
<span className='partner-portal-reminder-icon is-warning'>
|
||
<Users size={17} />
|
||
</span>
|
||
<span>
|
||
{row.customer_name || formatIdReference(row.subject_id)} ·{' '}
|
||
{t('客户保护期临近到期')}
|
||
<small>{date(protectionUntil(row))}</small>
|
||
</span>
|
||
<ChevronRight size={15} />
|
||
</button>
|
||
))}
|
||
{agreementExpiring && (
|
||
<div className='partner-portal-reminder'>
|
||
<span className='partner-portal-reminder-icon is-warning'>
|
||
<ScrollText size={17} />
|
||
</span>
|
||
<span>
|
||
{t('合作协议临近到期')}
|
||
<small>{date(summary.agreement_expires_at)}</small>
|
||
</span>
|
||
</div>
|
||
)}
|
||
{!rows.some((row) =>
|
||
['pending_confirmation', 'confirmed', 'checking'].includes(
|
||
row.status,
|
||
),
|
||
) &&
|
||
!expiringCustomers.length &&
|
||
!agreementExpiring && (
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无待办提醒')}
|
||
/>
|
||
)}
|
||
</div>
|
||
</Card>
|
||
</div>
|
||
</>
|
||
);
|
||
|
||
const renderCustomers = () => (
|
||
<>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'仅展示本伙伴保护期及正式归属期间的信息。转移或终止后的客户消费不在可见范围内。',
|
||
)}
|
||
/>
|
||
</Card>
|
||
<ConsoleCollectionSearch>
|
||
<ConsoleFilterGrid
|
||
onReset={() => {
|
||
customerSearch.cancelPendingSearch();
|
||
setAppliedCustomer({ keyword: '', status: 'all' });
|
||
setCustomerQuery('');
|
||
setCustomerStatus('all');
|
||
setCustomerPage(1);
|
||
}}
|
||
onSearch={customerSearch.submitSearch}
|
||
>
|
||
<ConsoleFilterField
|
||
label={t('搜索关键字')}
|
||
id='partner-customer-query'
|
||
>
|
||
<Input
|
||
id='partner-customer-query'
|
||
prefix={<Search size={16} />}
|
||
value={customerQuery}
|
||
onChange={customerSearch.changeFilter(setCustomerQuery)}
|
||
showClear
|
||
placeholder={t('搜索客户名称或编号')}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('状态')} id='partner-customer-status'>
|
||
<Select
|
||
id='partner-customer-status'
|
||
value={customerStatus}
|
||
onChange={customerSearch.changeFilter(setCustomerStatus)}
|
||
optionList={[
|
||
{ value: 'all', label: t('全部状态') },
|
||
...Array.from(new Set(customers.map((row) => row.status))).map(
|
||
(value) => ({
|
||
value,
|
||
label: commissionLabel(t, 'status', value),
|
||
}),
|
||
),
|
||
]}
|
||
/>
|
||
</ConsoleFilterField>
|
||
</ConsoleFilterGrid>
|
||
</ConsoleCollectionSearch>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='console-list-tools commission-filter-end'>
|
||
<Text type='secondary'>
|
||
{t('共 {{count}} 条归属记录', { count: visibleCustomers.length })}
|
||
</Text>
|
||
<div className='console-list-tool-actions'>{refreshButton}</div>
|
||
</div>
|
||
<Table
|
||
rowKey='id'
|
||
dataSource={visibleCustomers}
|
||
pagination={
|
||
visibleCustomers.length > 0 || customerPage > 1
|
||
? {
|
||
preservePage: true,
|
||
pageSize: 10,
|
||
current: customerPage,
|
||
onPageChange: setCustomerPage,
|
||
}
|
||
: false
|
||
}
|
||
scroll={{ x: 1100 }}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无客户')}
|
||
/>
|
||
}
|
||
columns={[
|
||
{
|
||
title: t('客户'),
|
||
render: (_, row) => (
|
||
<b>
|
||
{row.customer_name ||
|
||
row.subject_name ||
|
||
`${commissionLabel(t, 'subjectType', row.subject_type)} ${formatIdReference(row.subject_id)}`}
|
||
</b>
|
||
),
|
||
},
|
||
{
|
||
title: t('类型'),
|
||
dataIndex: 'subject_type',
|
||
render: (value) => commissionLabel(t, 'subjectType', value),
|
||
},
|
||
{ title: t('归属状态'), dataIndex: 'status', render: tag },
|
||
{
|
||
title: t('正式归属起点'),
|
||
dataIndex: 'formal_at',
|
||
render: formatDateTime,
|
||
},
|
||
{ title: t('保护期开始'), dataIndex: 'started_at', render: date },
|
||
{
|
||
title: t('保护期至'),
|
||
render: (_, row) => date(protectionUntil(row)),
|
||
},
|
||
{
|
||
title: t('保护期剩余天数'),
|
||
render: (_, row) =>
|
||
PROTECTED.includes(row.status)
|
||
? Math.max(
|
||
0,
|
||
Math.ceil(
|
||
(protectionUntil(row) - Date.now() / 1000) / 86400,
|
||
),
|
||
)
|
||
: '—',
|
||
},
|
||
{
|
||
title: t('归属结束'),
|
||
dataIndex: 'ended_at',
|
||
render: formatDateTime,
|
||
},
|
||
]}
|
||
/>
|
||
</Card>
|
||
</>
|
||
);
|
||
|
||
const renderEstimate = () => (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'预估数据不含后续人工调整,可能与最终账单存在差异。单笔明细仅显示分佣档位,不显示具体渠道。',
|
||
)}
|
||
/>
|
||
{summary.partner_status === 'terminated' ? (
|
||
<Card className='commission-card partner-portal-card'>
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('合作已终止,可在我的提成中查看历史账单。')}
|
||
/>
|
||
<Button onClick={() => navigate('bills')}>{t('查看历史账单')}</Button>
|
||
</Card>
|
||
) : (
|
||
<>
|
||
<div className='partner-portal-metrics partner-portal-metrics-three'>
|
||
<Metric
|
||
label={t('本月有效销售额(预估)')}
|
||
value={money(totals.sales)}
|
||
note={currentMonth}
|
||
/>
|
||
<Metric
|
||
label={t('本月预估提成')}
|
||
value={money(totals.commission)}
|
||
primary
|
||
/>
|
||
<Metric label={t('计费明细笔数')} value={totals.count} />
|
||
</div>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>
|
||
{t('本月预估汇总')}
|
||
<span>{t('按账期汇总')}</span>
|
||
</div>
|
||
<Table
|
||
className='partner-portal-estimate-table'
|
||
rowKey='statement_month'
|
||
dataSource={realtime}
|
||
pagination={realtime.length ? { pageSize: 10 } : false}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('本月暂无预估数据')}
|
||
/>
|
||
}
|
||
columns={[
|
||
{ title: t('账期'), dataIndex: 'statement_month' },
|
||
{ title: t('计费明细笔数'), dataIndex: 'detail_count' },
|
||
{
|
||
title: t('有效销售额'),
|
||
dataIndex: 'base_amount_uyuan',
|
||
render: money,
|
||
align: 'right',
|
||
},
|
||
{
|
||
title: t('预估提成'),
|
||
dataIndex: 'estimated_uyuan',
|
||
render: money,
|
||
align: 'right',
|
||
},
|
||
]}
|
||
/>
|
||
<p className='partner-portal-hint'>
|
||
{t(
|
||
'单笔消耗及档位比例可在正式账单详情中核对。预估汇总不代表已正式出账。',
|
||
)}
|
||
</p>
|
||
{currentStatements.map((row) => (
|
||
<Button key={row.id} type='link' onClick={() => open(row)}>
|
||
{t('查看本月账单明细')} #{row.id}
|
||
</Button>
|
||
))}
|
||
</Card>
|
||
</>
|
||
)}
|
||
</>
|
||
);
|
||
|
||
const renderRules = () => (
|
||
<div className='partner-portal-two-columns partner-portal-rules'>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>{t('分佣计算规则')}</div>
|
||
<div className='partner-portal-rule-block'>
|
||
<h3>{t('分佣档位与比例')}</h3>
|
||
<p>
|
||
{t(
|
||
'默认等级跟随渠道档位;优惠等级的正常钱包消费使用等级绑定档位,替代、不叠加。0% 不回退;缺少等级绑定档位时阻断计提与出账。',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<div className='partner-portal-rule-block'>
|
||
<h3>{t('历史快照')}</h3>
|
||
<p>
|
||
{t(
|
||
'历史明细按计费时的等级、档位和比例快照展示,不能用当前等级重算历史。具体比例请在正式账单的档位汇总与单笔明细中核对。',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<div className='partner-portal-rule-block'>
|
||
<h3>{t('调整与结转')}</h3>
|
||
<p>
|
||
{t(
|
||
'人工调整单独列示,并计入应计提成和本期应付。账单详情同时展示手续费、上期结转扣减、下期结转扣减与舍入尾差。',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t('为保护商业信息,伙伴端不展示具体渠道信息。')}
|
||
/>
|
||
</Card>
|
||
<Card className='commission-card partner-portal-card'>
|
||
<div className='partner-portal-card-title'>{t('客户归属与结算')}</div>
|
||
<ol className='partner-portal-rule-list'>
|
||
<li>
|
||
{t(
|
||
'客户保护期默认 90 天,可延期 1 次,最长 60 天。实际保护期限以我的客户页面为准。',
|
||
)}
|
||
</li>
|
||
<li>
|
||
{t(
|
||
'保护期内签约,或首次充值并产生付费消耗,经平台确认后转为正式归属。',
|
||
)}
|
||
</li>
|
||
<li>{t('实时预估仅供参考,最终金额以正式提成账单为准。')}</li>
|
||
<li>
|
||
{t(
|
||
'正式账单请在确认截止日期前确认或驳回;逾期无反馈视同确认。驳回需填写原因,平台修正并重新出账后再次确认。',
|
||
)}
|
||
</li>
|
||
<li>
|
||
{t(
|
||
'确认后由平台办理后续结算;企业伙伴按协议办理开票,个人伙伴以账单中列示的手续费为准。0 元应付账单确认后可直接完成。',
|
||
)}
|
||
</li>
|
||
<li>
|
||
{t(
|
||
'转移或终止后的客户消费不在伙伴可见范围内;历史正式账单仍可查看。',
|
||
)}
|
||
</li>
|
||
</ol>
|
||
<Button onClick={() => navigate('bills')}>{t('查看我的提成')}</Button>
|
||
</Card>
|
||
</div>
|
||
);
|
||
|
||
return (
|
||
<Layout
|
||
hasSider={!embedded}
|
||
className={`commission-v2 commission-admin-workspace partner-portal${embedded ? ' partner-portal--embedded' : ''}`}
|
||
>
|
||
{!embedded && (
|
||
<aside className='commission-v2-sider'>
|
||
<div className='commission-brand'>
|
||
<span className='commission-brand-mark' />
|
||
{t('合作分佣')}
|
||
</div>
|
||
<nav className='commission-navigation' aria-label={t('伙伴分佣导航')}>
|
||
<div className='commission-nav-group'>{t('伙伴工作台')}</div>
|
||
{NAVIGATION.map(({ key, label, icon: Icon }) => (
|
||
<button
|
||
type='button'
|
||
key={key}
|
||
className={`commission-nav-item${active === key ? ' is-active' : ''}`}
|
||
aria-current={active === key ? 'page' : undefined}
|
||
disabled={mutationLoading}
|
||
onClick={() => navigate(key)}
|
||
>
|
||
<Icon size={17} />
|
||
<span>{t(label)}</span>
|
||
{key === 'bills' && pending.length > 0 && (
|
||
<span className='commission-nav-badge'>{pending.length}</span>
|
||
)}
|
||
</button>
|
||
))}
|
||
</nav>
|
||
</aside>
|
||
)}
|
||
<Layout>
|
||
<header className='commission-workspace-bar' hidden={embedded}>
|
||
<div>
|
||
{t(embedded ? '企业分佣' : '合作分佣')}
|
||
<span className='commission-crumb-slash'>/</span>
|
||
{selected && (
|
||
<>
|
||
{t('我的提成')}
|
||
<span className='commission-crumb-slash'>/</span>
|
||
</>
|
||
)}
|
||
<b>{t(pageTitle)}</b>
|
||
</div>
|
||
{!embedded && (
|
||
<span className='commission-workspace-role'>{t('伙伴工作台')}</span>
|
||
)}
|
||
</header>
|
||
<Content
|
||
className={`commission-v2-content${embedded ? ' uc-page oc-page' : ''}`}
|
||
>
|
||
<div className='commission-page-header'>
|
||
<div className='commission-page-heading'>
|
||
{selected && (
|
||
<Button
|
||
className='partner-portal-back'
|
||
type='link'
|
||
icon={<ActionArrowLeft size={16} />}
|
||
disabled={mutationLoading}
|
||
onClick={() => navigate('bills')}
|
||
>
|
||
{t('返回我的提成')}
|
||
</Button>
|
||
)}
|
||
{embedded ? (
|
||
<OrgPageHeader
|
||
title={t(pageTitle)}
|
||
subtitle={
|
||
selected ? (
|
||
`${t('账单号')} ${formatIdReference(selected.id)} · ${selected.statement_month}`
|
||
) : (
|
||
<>
|
||
{t(subtitles[active])}
|
||
{['overview', 'estimate'].includes(active) &&
|
||
summary.updated_at
|
||
? ` · ${t('数据更新时间')}:${formatDateTime(summary.updated_at)}`
|
||
: ''}
|
||
</>
|
||
)
|
||
}
|
||
/>
|
||
) : (
|
||
<Title level={4}>{t(pageTitle)}</Title>
|
||
)}
|
||
{!embedded && (
|
||
<Text type='secondary'>
|
||
{selected
|
||
? `${t('账单号')} ${formatIdReference(selected.id)} · ${selected.statement_month}`
|
||
: t(subtitles[active])}
|
||
{!selected &&
|
||
['overview', 'estimate'].includes(active) &&
|
||
summary.updated_at
|
||
? ` · ${t('数据更新时间')}:${formatDateTime(summary.updated_at)}`
|
||
: ''}
|
||
</Text>
|
||
)}
|
||
</div>
|
||
<div className='commission-actions'>
|
||
{selected && (
|
||
<>
|
||
<Button
|
||
icon={<Download size={16} />}
|
||
disabled={detailLoading || mutationLoading}
|
||
onClick={() =>
|
||
exportDetails(items, adjustments, selected, t)
|
||
}
|
||
>
|
||
{t('导出明细')}
|
||
</Button>
|
||
{selected.status === 'pending_confirmation' && (
|
||
<>
|
||
<Button
|
||
danger
|
||
disabled={detailLoading || mutationLoading}
|
||
onClick={() => {
|
||
setReason('');
|
||
setActionError('');
|
||
setAction('reject');
|
||
}}
|
||
>
|
||
{t('驳回账单')}
|
||
</Button>
|
||
<Button
|
||
type='primary'
|
||
disabled={detailLoading || mutationLoading}
|
||
onClick={() => {
|
||
setReason('');
|
||
setActionError('');
|
||
setAction('confirm');
|
||
}}
|
||
>
|
||
{t('确认账单')}
|
||
</Button>
|
||
</>
|
||
)}
|
||
</>
|
||
)}
|
||
{(selected ||
|
||
!loaded ||
|
||
!['bills', 'customers'].includes(active)) &&
|
||
refreshButton}
|
||
</div>
|
||
</div>
|
||
{error && <Alert showIcon type='error' description={error} />}
|
||
{loading && !selected ? (
|
||
<div className='partner-portal-loading'>
|
||
<Spin size='large' />
|
||
</div>
|
||
) : !loaded && !selected ? (
|
||
<Card className='commission-card partner-portal-card'>
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('数据加载失败,请刷新重试')}
|
||
/>
|
||
</Card>
|
||
) : selected ? (
|
||
renderDetail()
|
||
) : active === 'overview' ? (
|
||
renderOverview()
|
||
) : active === 'customers' ? (
|
||
renderCustomers()
|
||
) : active === 'estimate' ? (
|
||
renderEstimate()
|
||
) : active === 'bills' ? (
|
||
renderBills()
|
||
) : (
|
||
renderRules()
|
||
)}
|
||
</Content>
|
||
</Layout>
|
||
<PartnerModal
|
||
style={themeStyle}
|
||
className='commission-modal partner-portal-modal'
|
||
visible={!!action}
|
||
title={`${t(action === 'reject' ? '驳回账单' : '确认账单')} · ${formatIdReference(selected?.id)}`}
|
||
confirmLoading={mutationLoading}
|
||
closeOnEsc={!mutationLoading}
|
||
maskClosable={!mutationLoading}
|
||
onCancel={() => {
|
||
if (!mutationLoading) setAction(null);
|
||
}}
|
||
onOk={transition}
|
||
okButtonProps={{ disabled: action === 'reject' && !reason.trim() }}
|
||
cancelButtonProps={{ disabled: mutationLoading }}
|
||
okText={t(action === 'reject' ? '提交驳回' : '确认无误')}
|
||
cancelText={t('取消')}
|
||
>
|
||
{actionError && (
|
||
<Alert showIcon type='error' description={actionError} />
|
||
)}
|
||
{action === 'reject' ? (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={t(
|
||
'驳回后账单将退回平台核对;平台修正并重新出账后,需您再次确认。',
|
||
)}
|
||
/>
|
||
<label className='partner-portal-reason-label'>
|
||
{t('驳回原因')}
|
||
<span>*</span>
|
||
</label>
|
||
<TextArea
|
||
value={reason}
|
||
onChange={setReason}
|
||
rows={4}
|
||
maxCount={2000}
|
||
disabled={mutationLoading}
|
||
placeholder={t('请填写差异客户、金额或其他驳回原因')}
|
||
/>
|
||
</>
|
||
) : (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={
|
||
<>
|
||
{t('本期应付提成')} <b>{money(selected?.payable_uyuan)}</b>。
|
||
{t('确认后账单不可再驳回,平台将办理后续结算。')}
|
||
</>
|
||
}
|
||
/>
|
||
<p>
|
||
{t(
|
||
Number(selected?.payable_uyuan) === 0
|
||
? '本期为 0 元账单,确认后直接完成。'
|
||
: '请确认销售额、应计提成、手续费及本期应付金额均已核对。确认后账单金额锁定。',
|
||
)}
|
||
</p>
|
||
</>
|
||
)}
|
||
</PartnerModal>
|
||
</Layout>
|
||
);
|
||
}
|