203 lines
6.6 KiB
React
203 lines
6.6 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, { 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],
|
|
['登录主体', `#${row.user_id}`],
|
|
['证件号码', 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: 5, size: 'small' }}
|
|
columns={[
|
|
{
|
|
title: t('客户'),
|
|
render: (_, item) =>
|
|
item.customer_name || `#${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>
|
|
);
|
|
}
|