2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
187 lines
6.0 KiB
React
187 lines
6.0 KiB
React
import { formatIdReference } from '../../helpers/safeDisplay';
|
|
import { formatUserReference } from '../../helpers/safeDisplay';
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
import { Button, Descriptions, Spin, Tag } from 'antd';
|
|
import { Table } from '@/components/ui';
|
|
import {
|
|
ConsoleAlert as Alert,
|
|
ConsoleDrawer as Drawer,
|
|
} from '../../components/console/ConsolePrimitives';
|
|
import { useCommissionThemeStyle } from './commissionTheme';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { commissionActorName, commissionLabel, statusTagColor } from './labels';
|
|
import { EvidenceLink } from './operations';
|
|
|
|
export default function PartnerDetail({
|
|
partner,
|
|
assignments,
|
|
audit,
|
|
fetchJSON,
|
|
onClose,
|
|
onEdit,
|
|
}) {
|
|
const themeStyle = useCommissionThemeStyle();
|
|
const { t, i18n } = useTranslation();
|
|
const [record, setRecord] = useState(null);
|
|
const [error, setError] = useState('');
|
|
useEffect(() => {
|
|
let current = true;
|
|
setRecord(null);
|
|
setError('');
|
|
if (partner)
|
|
fetchJSON(`/api/commission/v2/partners/${partner.id}`)
|
|
.then((value) => current && setRecord(value))
|
|
.catch((err) => current && setError(err.message));
|
|
return () => {
|
|
current = false;
|
|
};
|
|
}, [partner, fetchJSON]);
|
|
const row = record || partner || {};
|
|
const date = (value) =>
|
|
value ? new Date(value * 1000).toLocaleDateString(i18n.language) : '—';
|
|
const section = (title, fields) => (
|
|
<section className='commission-profile-section'>
|
|
<h3>{t(title)}</h3>
|
|
<Descriptions
|
|
size='small'
|
|
column={{ xs: 1, md: 2 }}
|
|
items={fields.map(([key, value]) => ({
|
|
key,
|
|
label: t(key),
|
|
children: value || '—',
|
|
}))}
|
|
/>
|
|
</section>
|
|
);
|
|
return (
|
|
<Drawer
|
|
rootStyle={themeStyle}
|
|
rootClassName='commission-profile-drawer commission-detail-drawer'
|
|
title={
|
|
<span>
|
|
{row.name}{' '}
|
|
<Tag color={statusTagColor(row.status)}>
|
|
{commissionLabel(t, 'status', row.status)}
|
|
</Tag>
|
|
</span>
|
|
}
|
|
open={!!partner}
|
|
placement='right'
|
|
size={820}
|
|
onClose={onClose}
|
|
footer={
|
|
<div className='commission-drawer-actions'>
|
|
<Button onClick={onClose}>{t('关闭')}</Button>
|
|
<Button type='primary' onClick={() => onEdit(partner)}>
|
|
{t('编辑伙伴档案')}
|
|
</Button>
|
|
</div>
|
|
}
|
|
>
|
|
{error && (
|
|
<Alert
|
|
type='error'
|
|
showIcon
|
|
className='commission-inline-alert'
|
|
title={error}
|
|
/>
|
|
)}
|
|
{!record && !error ? (
|
|
<Spin className='commission-drawer-spin' />
|
|
) : (
|
|
<>
|
|
{section('基本信息', [
|
|
['伙伴编号', row.partner_code],
|
|
['主体类型', commissionLabel(t, 'partnerType', row.type)],
|
|
['状态', commissionLabel(t, 'status', row.status)],
|
|
['伙伴名称', row.name],
|
|
['登录主体', formatUserReference('', row.user_id, t('未知用户'))],
|
|
['证件号码', row.identity_no],
|
|
['联系人', row.contact_name],
|
|
['联系电话', row.contact_phone],
|
|
['通知邮箱', row.contact_email],
|
|
])}
|
|
{section('协议信息', [
|
|
['协议编号', row.agreement_no],
|
|
[
|
|
'协议有效期',
|
|
`${date(row.agreement_effective_at)} ~ ${date(row.agreement_expires_at)}`,
|
|
],
|
|
[
|
|
'协议附件',
|
|
row.agreement_evidence ? (
|
|
<EvidenceLink value={row.agreement_evidence} />
|
|
) : null,
|
|
],
|
|
])}
|
|
{section('结算资料', [
|
|
['收款账户名', row.receiving_name],
|
|
['收款账号', row.receiving_account],
|
|
['开户行', row.receiving_bank],
|
|
])}
|
|
<section className='commission-profile-section'>
|
|
<h3>{t('名下客户')}</h3>
|
|
<Table
|
|
rowKey='id'
|
|
size='middle'
|
|
scroll={{ x: 'max-content' }}
|
|
dataSource={assignments.filter(
|
|
(item) => item.partner_id === row.id,
|
|
)}
|
|
pagination={{ pageSize: 10 }}
|
|
columns={[
|
|
{
|
|
title: t('客户'),
|
|
render: (_, item) =>
|
|
item.customer_name || formatIdReference(item.subject_id),
|
|
},
|
|
{
|
|
title: t('类型'),
|
|
render: (_, item) =>
|
|
commissionLabel(t, 'subjectType', item.subject_type),
|
|
},
|
|
{
|
|
title: t('状态'),
|
|
render: (_, item) =>
|
|
commissionLabel(t, 'status', item.status),
|
|
},
|
|
{
|
|
title: t('起止时间'),
|
|
render: (_, item) =>
|
|
`${date(item.started_at)} ~ ${date(item.ended_at)}`,
|
|
},
|
|
]}
|
|
/>
|
|
</section>
|
|
<section className='commission-profile-section'>
|
|
<h3>{t('变更记录')}</h3>
|
|
<div className='commission-timeline'>
|
|
{audit
|
|
.filter(
|
|
(item) =>
|
|
item.entity_type === 'partner' && item.entity_id === row.id,
|
|
)
|
|
.map((item) => (
|
|
<div key={item.id}>
|
|
<strong>
|
|
{commissionLabel(t, 'operation', item.action)}
|
|
</strong>
|
|
<p>
|
|
{date(item.created_at)} · {t('操作人')}{' '}
|
|
{commissionActorName(t, item)}
|
|
</p>
|
|
</div>
|
|
))}
|
|
{!audit.some(
|
|
(item) =>
|
|
item.entity_type === 'partner' && item.entity_id === row.id,
|
|
) && <p className='commission-muted'>{t('暂无操作记录')}</p>}
|
|
</div>
|
|
</section>
|
|
</>
|
|
)}
|
|
</Drawer>
|
|
);
|
|
}
|