Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,524 @@
|
||||
/*
|
||||
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 from 'react';
|
||||
import {
|
||||
Button,
|
||||
Empty,
|
||||
Table,
|
||||
TabPane,
|
||||
Tabs,
|
||||
Tag,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { ClipboardList, Download } from 'lucide-react';
|
||||
import { ChangeText, OrgNameCell, ReasonTags, SectionCard } from './shared';
|
||||
import {
|
||||
daysSince,
|
||||
downloadCsv,
|
||||
formatCny,
|
||||
formatCst,
|
||||
orgDisplayName,
|
||||
quotaToCny,
|
||||
REASONS,
|
||||
} from './utils';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
export const ACTION_TABS = ['renewal', 'retention', 'growth', 'activation'];
|
||||
|
||||
const TAB_META = {
|
||||
renewal: {
|
||||
label: '续费跟进',
|
||||
desc: '余额耗尽 / 即将不足 / 低于预警线,以及合同即将到期的企业;按紧急程度排序',
|
||||
},
|
||||
retention: {
|
||||
label: '流失挽回',
|
||||
desc: '本期停用、消耗下滑、近 7 日腰斩,以及 60 天内还在使用的沉睡企业;按消耗减少金额排序',
|
||||
},
|
||||
growth: {
|
||||
label: '增长机会',
|
||||
desc: '高速增长、新客起量、回流,以及成员活跃率低于 30% 的企业;按本期消耗排序',
|
||||
},
|
||||
activation: {
|
||||
label: '激活跟进',
|
||||
desc: '待激活或开通后从未使用的企业;按创建时间倒序',
|
||||
},
|
||||
};
|
||||
|
||||
const money = (cny) => (v) => (
|
||||
<span className='tabular-nums'>{formatCny(v, cny)}</span>
|
||||
);
|
||||
|
||||
const salesRepCol = (t) => ({
|
||||
title: t('跟进人'),
|
||||
dataIndex: 'sales_rep',
|
||||
width: 100,
|
||||
render: (v) =>
|
||||
v ? (
|
||||
<span className='truncate'>{v}</span>
|
||||
) : (
|
||||
<Text type='tertiary'>{t('未分配')}</Text>
|
||||
),
|
||||
});
|
||||
|
||||
const contactCol = (t) => ({
|
||||
title: t('联系人'),
|
||||
dataIndex: 'contact_name',
|
||||
width: 150,
|
||||
render: (v, r) =>
|
||||
v || r.contact_phone ? (
|
||||
<div className='min-w-0'>
|
||||
<div className='truncate'>{v || '—'}</div>
|
||||
{r.contact_phone ? (
|
||||
<div className='text-xs text-gray-400 tabular-nums'>
|
||||
{r.contact_phone}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
});
|
||||
|
||||
const baseCols = (t) => [
|
||||
{
|
||||
title: t('企业'),
|
||||
dataIndex: 'name',
|
||||
width: 190,
|
||||
fixed: 'left',
|
||||
render: (_, r) => <OrgNameCell org={r} t={t} />,
|
||||
},
|
||||
salesRepCol(t),
|
||||
{
|
||||
title: t('原因'),
|
||||
dataIndex: 'reasons',
|
||||
width: 170,
|
||||
render: (v) => <ReasonTags reasons={v} t={t} />,
|
||||
},
|
||||
];
|
||||
|
||||
const actionCol = (t) => ({
|
||||
title: t('建议动作'),
|
||||
dataIndex: 'action',
|
||||
width: 190,
|
||||
render: (v) => <span className='text-sm'>{t(v)}</span>,
|
||||
});
|
||||
|
||||
const columnsFor = (tab, cny, t, atRisk) => {
|
||||
const m = money(cny);
|
||||
switch (tab) {
|
||||
case 'renewal':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('当前余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('日均消耗'),
|
||||
dataIndex: 'daily_avg',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (v) => (v > 0 ? m(v) : <Text type='tertiary'>—</Text>),
|
||||
},
|
||||
{
|
||||
title: t('预计可用'),
|
||||
dataIndex: 'days_left',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (v, r) => {
|
||||
if (v < 0) return <Text type='tertiary'>{t('近期无消耗')}</Text>;
|
||||
return (
|
||||
<span
|
||||
className='tabular-nums font-medium'
|
||||
style={{
|
||||
color:
|
||||
v <= 3
|
||||
? 'var(--semi-color-danger)'
|
||||
: 'var(--semi-color-warning)',
|
||||
}}
|
||||
>
|
||||
{v < 1 ? t('不足 1 天') : `${v.toFixed(1)} ${t('天')}`}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('建议充值'),
|
||||
dataIndex: 'topup_suggest',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v) =>
|
||||
v > 0 ? (
|
||||
<span className='font-semibold'>{m(v)}</span>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('到期时间'),
|
||||
dataIndex: 'expired_at',
|
||||
width: 110,
|
||||
render: (v) =>
|
||||
v > 0 ? formatCst(v, false) : <Text type='tertiary'>—</Text>,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
case 'retention':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('对比期消耗'),
|
||||
dataIndex: 'prev_quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<ChangeText
|
||||
cur={r.quota}
|
||||
prev={r.prev_quota}
|
||||
t={t}
|
||||
showNew={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('消耗减少'),
|
||||
dataIndex: 'at_risk',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<span className='tabular-nums font-semibold'>
|
||||
{formatCny(atRisk(r), cny)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('最近使用'),
|
||||
dataIndex: 'last_active',
|
||||
width: 110,
|
||||
render: (v) => {
|
||||
const d = daysSince(v);
|
||||
return d === null ? (
|
||||
<Text type='tertiary'>—</Text>
|
||||
) : d === 0 ? (
|
||||
t('今天')
|
||||
) : (
|
||||
t('{{days}} 天前', { days: d })
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
case 'growth':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<ChangeText cur={r.quota} prev={r.prev_quota} t={t} />
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('成员活跃'),
|
||||
dataIndex: 'active_members',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v, r) => (
|
||||
<span className='tabular-nums'>
|
||||
{v}/{r.member_count}
|
||||
{r.member_count > 0 ? (
|
||||
<span className='text-xs text-gray-400 ml-1'>
|
||||
{Math.min(100, (v / r.member_count) * 100).toFixed(0)}%
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('层级'),
|
||||
dataIndex: 'tier',
|
||||
width: 70,
|
||||
render: (v) =>
|
||||
v ? <Tag size='small'>{v}</Tag> : <Text type='tertiary'>—</Text>,
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
actionCol(t),
|
||||
];
|
||||
default:
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('创建时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 110,
|
||||
render: (v) => formatCst(v, false),
|
||||
},
|
||||
{
|
||||
title: t('已开通'),
|
||||
dataIndex: 'age',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => {
|
||||
const d = daysSince(r.created_at);
|
||||
return d === null ? '—' : t('{{days}} 天', { days: d });
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('成员数'),
|
||||
dataIndex: 'member_count',
|
||||
width: 80,
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
const exportList = (tab, rows, cny, t, atRisk) => {
|
||||
const yuan = (v) => quotaToCny(v, cny).toFixed(2);
|
||||
const common = (o) => [
|
||||
orgDisplayName(o, t),
|
||||
o.code,
|
||||
o.sales_rep || t('未分配'),
|
||||
o.reasons.map((r) => t(REASONS[r]?.label || r)).join(' / '),
|
||||
];
|
||||
const head = [t('企业'), t('企业代码'), t('跟进人'), t('原因')];
|
||||
let headers;
|
||||
let body;
|
||||
switch (tab) {
|
||||
case 'renewal':
|
||||
headers = [
|
||||
...head,
|
||||
t('当前余额'),
|
||||
t('日均消耗'),
|
||||
t('预计可用天数'),
|
||||
t('建议充值'),
|
||||
t('到期时间'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.balance),
|
||||
yuan(o.daily_avg),
|
||||
o.days_left < 0 ? '' : o.days_left.toFixed(1),
|
||||
yuan(o.topup_suggest),
|
||||
o.expired_at > 0 ? formatCst(o.expired_at, false) : '',
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
case 'retention':
|
||||
headers = [
|
||||
...head,
|
||||
t('对比期消耗'),
|
||||
t('本期消耗'),
|
||||
t('消耗减少'),
|
||||
t('最近使用'),
|
||||
t('余额'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.prev_quota),
|
||||
yuan(o.quota),
|
||||
yuan(atRisk(o)),
|
||||
formatCst(o.last_active),
|
||||
yuan(o.balance),
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
case 'growth':
|
||||
headers = [
|
||||
...head,
|
||||
t('本期消耗'),
|
||||
t('对比期消耗'),
|
||||
t('活跃成员'),
|
||||
t('成员数'),
|
||||
t('层级'),
|
||||
t('余额'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.quota),
|
||||
yuan(o.prev_quota),
|
||||
o.active_members,
|
||||
o.member_count,
|
||||
o.tier,
|
||||
yuan(o.balance),
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
headers = [
|
||||
...head,
|
||||
t('创建时间'),
|
||||
t('成员数'),
|
||||
t('余额'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
formatCst(o.created_at, false),
|
||||
o.member_count,
|
||||
yuan(o.balance),
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
}
|
||||
downloadCsv(
|
||||
`${t(TAB_META[tab].label)}-${formatCst(Date.now() / 1000, false)}.csv`,
|
||||
headers,
|
||||
body,
|
||||
);
|
||||
};
|
||||
|
||||
export const ActionCenter = ({ lists, activeTab, onTabChange, cny, t }) => (
|
||||
<SectionCard
|
||||
id='org-report-actions'
|
||||
title={t('行动清单')}
|
||||
icon={<ClipboardList className='w-5 h-5' />}
|
||||
extra={
|
||||
<span className='text-xs text-gray-400'>
|
||||
{t('按跟进场景拆分的待办企业,可直接导出分派')}
|
||||
</span>
|
||||
}
|
||||
bodyStyle={{ paddingTop: 4 }}
|
||||
>
|
||||
<Tabs
|
||||
type='line'
|
||||
activeKey={activeTab}
|
||||
onChange={onTabChange}
|
||||
tabBarExtraContent={
|
||||
<Button
|
||||
size='small'
|
||||
icon={<Download className='w-3.5 h-3.5' />}
|
||||
disabled={lists[activeTab].length === 0}
|
||||
onClick={() =>
|
||||
exportList(activeTab, lists[activeTab], cny, t, lists.atRisk)
|
||||
}
|
||||
>
|
||||
{t('导出')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{ACTION_TABS.map((tab) => (
|
||||
<TabPane
|
||||
key={tab}
|
||||
itemKey={tab}
|
||||
tab={
|
||||
<span className='flex items-center gap-1.5'>
|
||||
{t(TAB_META[tab].label)}
|
||||
<Tag
|
||||
size='small'
|
||||
color={
|
||||
lists[tab].length > 0
|
||||
? tab === 'growth'
|
||||
? 'green'
|
||||
: 'red'
|
||||
: 'grey'
|
||||
}
|
||||
>
|
||||
{lists[tab].length}
|
||||
</Tag>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 my-2'>
|
||||
{t(TAB_META[tab].desc)}
|
||||
</div>
|
||||
<Table
|
||||
columns={columnsFor(tab, cny, t, lists.atRisk)}
|
||||
dataSource={lists[tab]}
|
||||
rowKey='org_id'
|
||||
size='small'
|
||||
scroll={{ x: 1200 }}
|
||||
pagination={
|
||||
lists[tab].length > 10
|
||||
? { pageSize: 10, showSizeChanger: false }
|
||||
: false
|
||||
}
|
||||
empty={<Empty description={t('暂无需要跟进的企业')} />}
|
||||
/>
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
</SectionCard>
|
||||
);
|
||||
Reference in New Issue
Block a user