c492e2b7c0
分析模块:补齐看板、排行、趋势及报表数值兜底 企业与用户中心:修复统计、成员、技能及资金字段展示 充值与交易:修复充值、发票、订单、订阅及支付字段拼接 平台页面:修复渠道、模型、服务监控与状态空值展示 通用能力:新增安全展示工具,补齐九语言文案与回归测试 文档记录:更新修复范围、影响及回滚说明
1427 lines
44 KiB
React
1427 lines
44 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 { Trans } from 'react-i18next';
|
||
import {
|
||
Copy as ActionCopy,
|
||
ReceiptText as ActionReceiptText,
|
||
ChevronRight as ActionChevronRight,
|
||
Pencil as ActionPencil,
|
||
} from '@/components/common/icons/ActionIcons';
|
||
import React, { useCallback, useEffect, useState } from 'react';
|
||
import {
|
||
Badge,
|
||
Banner,
|
||
Button,
|
||
Card,
|
||
Descriptions,
|
||
Empty,
|
||
Form,
|
||
Modal,
|
||
Table,
|
||
Tabs,
|
||
Tag,
|
||
Typography,
|
||
} from '@/components/ui';
|
||
import {
|
||
CreditCard,
|
||
Info,
|
||
Megaphone,
|
||
Network,
|
||
ReceiptText,
|
||
Users,
|
||
Wallet,
|
||
} from 'lucide-react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { API, copy, showError, showSuccess } from '../../helpers';
|
||
import {
|
||
formatNumber,
|
||
formatPercent,
|
||
toFiniteNumber,
|
||
} from '../../helpers/safeDisplay';
|
||
|
||
const { Text, Title } = Typography;
|
||
|
||
const fmtDate = (ts) => (ts ? new Date(ts * 1000).toLocaleDateString() : '-');
|
||
const fmtYuan = (v) => formatNumber(v, 2, '-');
|
||
|
||
const LEAD_STATUS = {
|
||
pending: ['orange', '待审核'],
|
||
approved: ['green', '已通过'],
|
||
rejected: ['red', '已驳回'],
|
||
expired: ['grey', '已失效'],
|
||
converted: ['blue', '已转化'],
|
||
};
|
||
|
||
const BILL_STATUS = {
|
||
pending_confirm: ['orange', '待确认'],
|
||
confirmed: ['green', '已确认'],
|
||
paid: ['blue', '已打款'],
|
||
suspended: ['red', '复核中'],
|
||
void: ['grey', '作废'],
|
||
generating: ['grey', '生成中'],
|
||
};
|
||
|
||
// 报备预检占用类型 → 中文(后端返回枚举 token,直显会出现 "platform_existing")
|
||
const PRECHECK_LABEL = {
|
||
pending_review: '已有报备待审核',
|
||
protected: '处于他人报备保护期',
|
||
converted: '已转化归属',
|
||
platform_existing: '属平台存量客户',
|
||
query_failed: '查重服务暂不可用,请稍后重试',
|
||
};
|
||
|
||
// 驳回原因枚举 → 中文
|
||
const REJECT_LABEL = {
|
||
duplicated: '重复报备',
|
||
existing: '平台存量客户',
|
||
invalid_info: '信息不完整/无效',
|
||
other: '其他原因',
|
||
};
|
||
|
||
// 账单调整项类型 → 中文
|
||
const ADJ_TYPE_LABEL = {
|
||
cost_diff: '成本差异',
|
||
refund_offset: '退款冲正',
|
||
violation_clawback: '违规追回',
|
||
special_bonus: '专项奖励',
|
||
dispute_resolve: '争议裁决',
|
||
first_order_bonus: '首单奖励',
|
||
cap_reduce: '封顶回调',
|
||
manual: '手工调整',
|
||
};
|
||
|
||
const STATUS_TAG = {
|
||
pending: ['orange', '待审核'],
|
||
active: ['green', '生效中'],
|
||
rejected: ['red', '已驳回'],
|
||
dormant: ['grey', '休眠'],
|
||
suspended: ['red', '已暂停'],
|
||
terminated: ['grey', '已终止'],
|
||
};
|
||
|
||
const LEVEL_LABEL = {
|
||
registered: '注册伙伴',
|
||
certified: '认证伙伴',
|
||
core: '核心伙伴', // 连续达标晋升可达(partner_growth),漏映射会裸显 "core"
|
||
};
|
||
|
||
// CSV 导出:必须走 axios(自动带 New-Api-User 头)。window.open 顶层导航
|
||
// 不带自定义头,全局鉴权中间件无豁免分支 → 必然 401
|
||
const downloadCsv = async (url, filename, t) => {
|
||
try {
|
||
const res = await API.get(url, {
|
||
responseType: 'blob',
|
||
skipErrorHandler: true,
|
||
});
|
||
const blob = res.data;
|
||
if (blob.type && blob.type.includes('application/json')) {
|
||
const text = await blob.text();
|
||
try {
|
||
const j = JSON.parse(text);
|
||
showError(j.message || t('导出失败'));
|
||
} catch {
|
||
showError(t('导出失败'));
|
||
}
|
||
return;
|
||
}
|
||
const a = document.createElement('a');
|
||
const objUrl = URL.createObjectURL(blob);
|
||
a.href = objUrl;
|
||
a.download = filename;
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
a.remove();
|
||
URL.revokeObjectURL(objUrl);
|
||
} catch (e) {
|
||
showError(e?.response?.data?.message || t('导出失败'));
|
||
}
|
||
};
|
||
|
||
/** 主题色提示条:替代蓝色 info Banner,颜色跟随平台品牌色 */
|
||
export const BrandTip = ({ children, className = '' }) => (
|
||
<div
|
||
className={`flex items-start gap-2 rounded-lg bg-brand/5 border border-brand/15 px-4 py-2.5 ${className}`}
|
||
>
|
||
<Info size={15} className='text-brand mt-0.5 flex-shrink-0' />
|
||
<span className='text-sm text-gray-600 dark:text-gray-300'>{children}</span>
|
||
</div>
|
||
);
|
||
|
||
/** 伙伴编号胶囊:点击复制 */
|
||
const PartnerCodeChip = ({ code, t }) => (
|
||
<button
|
||
type='button'
|
||
onClick={async () => {
|
||
if (await copy(code)) showSuccess(t('伙伴编号已复制'));
|
||
else showError(t('复制失败,请手动复制'));
|
||
}}
|
||
className='app-action-button flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-brand/10 text-brand-deep hover:bg-brand/20 transition-colors text-xs font-mono font-semibold cursor-pointer border-none'
|
||
title={t('点击复制')}
|
||
>
|
||
{code}
|
||
<ActionCopy size={12} />
|
||
</button>
|
||
);
|
||
|
||
/** 合作伙伴工作台:看板 / 报备 / 客户 / 账单 / 下级 / 公告 */
|
||
export default function Workbench({ self, dashboard }) {
|
||
const { t } = useTranslation();
|
||
const [unread, setUnread] = useState(0);
|
||
const [activeTab, setActiveTab] = useState('overview');
|
||
// 权限两档(与后端 PartnerAuth 写白名单对齐):
|
||
// suspended/terminated → 全只读;
|
||
// dormant → 仅停新报备,存量履约(留痕/延期)与账单闭环(确认/争议)、收款账户照常——
|
||
// 否则休眠伙伴在 30 天转出通知期内无法自救,账单只能被自动确认
|
||
const readOnly =
|
||
self?.status === 'suspended' || self?.status === 'terminated';
|
||
const canSubmitLead = self?.status === 'active';
|
||
|
||
const loadUnread = useCallback(async () => {
|
||
try {
|
||
const res = await API.get('/api/partner/notifications?unread=true');
|
||
if (res.data.success) setUnread(res.data.data.length);
|
||
} catch {
|
||
/* 忽略 */
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
loadUnread();
|
||
}, [loadUnread]);
|
||
|
||
const [statusColor, statusLabel] = STATUS_TAG[self?.status] || [
|
||
'grey',
|
||
self?.status,
|
||
];
|
||
|
||
return (
|
||
<Card
|
||
className='!rounded-2xl shadow-sm'
|
||
styles={{ body: { padding: '20px 24px' } }}
|
||
>
|
||
<div className='flex flex-wrap items-center justify-between gap-3 mb-3'>
|
||
<div className='flex items-center gap-2.5 min-w-0'>
|
||
<Title
|
||
heading={5}
|
||
style={{ margin: 0 }}
|
||
ellipsis={{ showTooltip: true }}
|
||
>
|
||
{dashboard?.name || self?.name}
|
||
</Title>
|
||
<Tag color={statusColor} shape='circle'>
|
||
{t(statusLabel)}
|
||
</Tag>
|
||
<Tag color='white' shape='circle'>
|
||
{t(LEVEL_LABEL[dashboard?.level] || dashboard?.level || '-')}
|
||
</Tag>
|
||
</div>
|
||
<div className='flex items-center gap-2'>
|
||
<Text type='tertiary' size='small'>
|
||
{t('伙伴编号')}
|
||
</Text>
|
||
<PartnerCodeChip code={dashboard?.partner_code || '-'} t={t} />
|
||
</div>
|
||
</div>
|
||
<Tabs type='line' activeKey={activeTab} onChange={setActiveTab}>
|
||
<Tabs.TabPane tab={t('看板')} itemKey='overview'>
|
||
<Overview dashboard={dashboard} t={t} onGoto={setActiveTab} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('客户报备')} itemKey='leads'>
|
||
<Leads t={t} readOnly={readOnly} canSubmit={canSubmitLead} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('我的客户')} itemKey='customers'>
|
||
<Customers t={t} readOnly={readOnly} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('我的账单')} itemKey='bills'>
|
||
<Bills t={t} readOnly={readOnly} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('收款账户')} itemKey='payout'>
|
||
<PayoutAccount t={t} readOnly={readOnly} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane tab={t('我的下级')} itemKey='referrals'>
|
||
<Referrals t={t} partnerCode={dashboard?.partner_code} />
|
||
</Tabs.TabPane>
|
||
<Tabs.TabPane
|
||
tab={
|
||
<span>
|
||
{t('公告通知')} {unread > 0 && <Badge count={unread} />}
|
||
</span>
|
||
}
|
||
itemKey='notices'
|
||
>
|
||
<Notices t={t} onRead={loadUnread} readOnly={readOnly} />
|
||
</Tabs.TabPane>
|
||
</Tabs>
|
||
</Card>
|
||
);
|
||
}
|
||
|
||
function StatCard({ icon, title, value, iconBg, bgColor, onClick }) {
|
||
// onClick 放外层 div:Semi Card 不保证透传原生事件
|
||
return (
|
||
<div onClick={onClick} className={onClick ? 'cursor-pointer' : ''}>
|
||
<Card
|
||
className={`${bgColor} border-none shadow-sm hover:shadow-md transition-shadow !rounded-xl`}
|
||
styles={{ body: { padding: 16 } }}
|
||
>
|
||
<div className='flex items-start justify-between gap-2'>
|
||
<div className='flex-1 min-w-0'>
|
||
<p className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
|
||
{title}
|
||
</p>
|
||
<p className='text-xl font-bold text-gray-800 dark:text-gray-100 truncate'>
|
||
{value}
|
||
</p>
|
||
</div>
|
||
<div
|
||
className={`${iconBg} p-2 rounded-lg text-white shadow-sm flex-shrink-0`}
|
||
>
|
||
{icon}
|
||
</div>
|
||
</div>
|
||
</Card>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Overview({ dashboard, t, onGoto }) {
|
||
const stats = [
|
||
{
|
||
title: t('本月净消耗(实时预估)'),
|
||
value: `¥ ${fmtYuan(dashboard?.month_net_preview_yuan)}`,
|
||
icon: <Wallet className='w-5 h-5' />,
|
||
iconBg: 'bg-brand',
|
||
bgColor: 'bg-brand/5 dark:bg-brand-deep/20',
|
||
},
|
||
{
|
||
title: t('生效客户数'),
|
||
value: dashboard?.active_customers ?? '-',
|
||
icon: <Users className='w-5 h-5' />,
|
||
iconBg: 'bg-blue-500',
|
||
bgColor: 'bg-blue-50 dark:bg-blue-900/20',
|
||
onClick: () => onGoto?.('customers'),
|
||
},
|
||
{
|
||
title: t('待确认账单'),
|
||
value: dashboard?.pending_bills ?? '-',
|
||
icon: <ReceiptText className='w-5 h-5' />,
|
||
iconBg: 'bg-orange-500',
|
||
bgColor: 'bg-orange-50 dark:bg-orange-900/20',
|
||
onClick: () => onGoto?.('bills'),
|
||
},
|
||
{
|
||
title: t('我的下级'),
|
||
value: dashboard?.referral_count ?? '-',
|
||
icon: <Network className='w-5 h-5' />,
|
||
iconBg: 'bg-purple-500',
|
||
bgColor: 'bg-purple-50 dark:bg-purple-900/20',
|
||
onClick: () => onGoto?.('referrals'),
|
||
},
|
||
];
|
||
|
||
const pendingBills = Number(dashboard?.pending_bills) || 0;
|
||
|
||
return (
|
||
<div>
|
||
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4'>
|
||
{stats.map((s, i) => (
|
||
<StatCard key={i} {...s} />
|
||
))}
|
||
</div>
|
||
{pendingBills > 0 && (
|
||
<button
|
||
type='button'
|
||
onClick={() => onGoto?.('bills')}
|
||
className='app-action-button w-full flex items-center justify-between gap-2 rounded-lg bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 px-4 py-3 mt-4 cursor-pointer hover:bg-orange-100 dark:hover:bg-orange-900/30 transition-colors'
|
||
>
|
||
<span className='flex items-center gap-2 text-sm text-orange-700 dark:text-orange-300'>
|
||
<ActionReceiptText size={15} className='flex-shrink-0' />
|
||
{t('您有 {{n}} 张账单待确认,请尽快核对——确认后才会进入打款流程', {
|
||
n: pendingBills,
|
||
})}
|
||
</span>
|
||
<span className='flex items-center gap-0.5 text-sm font-medium text-orange-700 dark:text-orange-300 flex-shrink-0'>
|
||
{t('去确认')}
|
||
<ActionChevronRight size={15} />
|
||
</span>
|
||
</button>
|
||
)}
|
||
<BrandTip className='mt-4'>
|
||
{t('看板数字为实时预估,最终以月结账单为准')}
|
||
</BrandTip>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Leads({ t, readOnly, canSubmit }) {
|
||
const [rows, setRows] = useState([]);
|
||
const [loading, setLoading] = useState(false);
|
||
const [total, setTotal] = useState(0);
|
||
const [page, setPage] = useState(1);
|
||
const [showSubmit, setShowSubmit] = useState(false);
|
||
const [precheck, setPrecheck] = useState(null);
|
||
const [extendTarget, setExtendTarget] = useState(null);
|
||
|
||
const load = useCallback(async (p = 1) => {
|
||
setLoading(true);
|
||
try {
|
||
const res = await API.get(`/api/partner/leads?p=${p - 1}`);
|
||
if (res.data.success) {
|
||
setRows(res.data.data.items || []);
|
||
setTotal(res.data.data.total || 0);
|
||
setPage(p);
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load(1);
|
||
}, [load]);
|
||
|
||
const doPrecheck = async (values) => {
|
||
const res = await API.get(
|
||
`/api/partner/leads/precheck?credit_code=${encodeURIComponent(values.credit_code || '')}&name=${encodeURIComponent(values.customer_name || '')}`,
|
||
);
|
||
if (res.data.success) setPrecheck(res.data.data);
|
||
};
|
||
|
||
const submit = async (values) => {
|
||
const res = await API.post('/api/partner/leads', {
|
||
...values,
|
||
is_company: !!values.credit_code,
|
||
});
|
||
if (res.data.success) {
|
||
showSuccess(t('报备已提交,1 个工作日内未处理视为通过'));
|
||
setShowSubmit(false);
|
||
setPrecheck(null);
|
||
load(1);
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
const extend = async (values) => {
|
||
const res = await API.post(`/api/partner/leads/${extendTarget.id}/extend`, {
|
||
reason: values.reason,
|
||
days: Number(values.days),
|
||
});
|
||
if (res.data.success) {
|
||
showSuccess(t('保护期延长成功'));
|
||
setExtendTarget(null);
|
||
load(page);
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
const columns = [
|
||
{ title: t('客户名称'), dataIndex: 'customer_name' },
|
||
{ title: t('信用代码'), dataIndex: 'credit_code', render: (v) => v || '-' },
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
render: (v, r) => {
|
||
const [color, label] = LEAD_STATUS[v] || ['grey', v];
|
||
return (
|
||
<span>
|
||
<Tag color={color} shape='circle'>
|
||
{t(label)}
|
||
</Tag>
|
||
{v === 'rejected' && r.reject_reason && (
|
||
<Text type='tertiary' size='small'>
|
||
{' '}
|
||
{t(REJECT_LABEL[r.reject_reason] || r.reject_reason)}
|
||
</Text>
|
||
)}
|
||
</span>
|
||
);
|
||
},
|
||
},
|
||
{ title: t('提交时间'), dataIndex: 'submitted_at', render: fmtDate },
|
||
{
|
||
title: t('保护期至'),
|
||
render: (r) => fmtDate(r.extended_until || r.protect_until),
|
||
},
|
||
{
|
||
title: '',
|
||
render: (r) =>
|
||
!readOnly &&
|
||
r.status === 'approved' &&
|
||
!r.extended_at && (
|
||
<Button size='small' onClick={() => setExtendTarget(r)}>
|
||
{t('申请延期')}
|
||
</Button>
|
||
),
|
||
},
|
||
];
|
||
|
||
return (
|
||
<div>
|
||
<div className='flex flex-wrap items-center justify-between gap-3 mb-3'>
|
||
<BrandTip className='flex-1 min-w-[260px]'>
|
||
{t('报备在先、平台确认是返佣资格的唯一依据;报备通过后进入保护期')}
|
||
</BrandTip>
|
||
{canSubmit && (
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
onClick={() => setShowSubmit(true)}
|
||
>
|
||
{t('新建报备')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
<Table
|
||
columns={columns}
|
||
dataSource={rows}
|
||
loading={loading}
|
||
rowKey='id'
|
||
scroll={{ x: 'max-content' }}
|
||
empty={
|
||
<Empty
|
||
description={
|
||
canSubmit
|
||
? t('暂无报备,点击右上角「新建报备」开始')
|
||
: t('暂无报备')
|
||
}
|
||
/>
|
||
}
|
||
pagination={{
|
||
total,
|
||
pageSize: 20,
|
||
currentPage: page,
|
||
onPageChange: load,
|
||
}}
|
||
/>
|
||
<Modal
|
||
title={t('新建客户报备')}
|
||
visible={showSubmit}
|
||
onCancel={() => {
|
||
setShowSubmit(false);
|
||
setPrecheck(null);
|
||
}}
|
||
footer={null}
|
||
>
|
||
<BrandTip>
|
||
{t(
|
||
'企业客户必须填写统一社会信用代码;报备在先、平台确认是返佣资格的唯一依据',
|
||
)}
|
||
</BrandTip>
|
||
{/* key 随弹窗开合重挂载:Semi Modal 关闭不卸载内容,避免上次输入残留 */}
|
||
<Form
|
||
key={showSubmit ? 'open' : 'closed'}
|
||
onSubmit={submit}
|
||
style={{ marginTop: 8 }}
|
||
>
|
||
{({ formState }) => (
|
||
<>
|
||
<Form.Input
|
||
field='customer_name'
|
||
label={t('客户名称')}
|
||
rules={[{ required: true, message: t('请输入客户名称') }]}
|
||
/>
|
||
<Form.Input
|
||
field='credit_code'
|
||
label={t('统一社会信用代码(企业必填)')}
|
||
/>
|
||
<Form.Input field='contact_name' label={t('联系人')} />
|
||
<Form.Input field='contact_phone' label={t('联系电话')} />
|
||
<Form.TextArea
|
||
field='demand_brief'
|
||
label={t('需求简述')}
|
||
maxLength={500}
|
||
/>
|
||
{precheck && (
|
||
<Banner
|
||
type={precheck.available ? 'success' : 'danger'}
|
||
closeIcon={null}
|
||
description={
|
||
precheck.available
|
||
? t('可报备')
|
||
: `${t('不可报备')}: ${t(PRECHECK_LABEL[precheck.label] || precheck.label)}`
|
||
}
|
||
/>
|
||
)}
|
||
<div
|
||
className='flex gap-2 justify-end'
|
||
style={{ margin: '16px 0 8px' }}
|
||
>
|
||
<Button onClick={() => doPrecheck(formState.values)}>
|
||
{t('占用预检')}
|
||
</Button>
|
||
<Button theme='solid' htmlType='submit' type='primary'>
|
||
{t('提交报备')}
|
||
</Button>
|
||
</div>
|
||
</>
|
||
)}
|
||
</Form>
|
||
</Modal>
|
||
<Modal
|
||
title={t('申请保护期延期(仅一次)')}
|
||
visible={!!extendTarget}
|
||
onCancel={() => setExtendTarget(null)}
|
||
footer={null}
|
||
>
|
||
<Form key={extendTarget?.id || 0} onSubmit={extend}>
|
||
<Form.Select
|
||
field='reason'
|
||
label={t('延期事由')}
|
||
style={{ width: '100%' }}
|
||
rules={[{ required: true }]}
|
||
>
|
||
<Form.Select.Option value='proposal'>
|
||
{t('方案编制中')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='negotiation'>
|
||
{t('商务谈判中')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='poc'>
|
||
{t('测试验证中')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='bidding'>
|
||
{t('招投标流程中')}
|
||
</Form.Select.Option>
|
||
</Form.Select>
|
||
<Form.InputNumber
|
||
field='days'
|
||
label={t('延长天数(最多 60 天)')}
|
||
initValue={30}
|
||
max={60}
|
||
min={1}
|
||
/>
|
||
<Button
|
||
theme='solid'
|
||
htmlType='submit'
|
||
type='primary'
|
||
block
|
||
style={{ margin: '16px 0 8px' }}
|
||
>
|
||
{t('提交')}
|
||
</Button>
|
||
</Form>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Customers({ t, readOnly }) {
|
||
const [rows, setRows] = useState([]);
|
||
const [loading, setLoading] = useState(false);
|
||
const [total, setTotal] = useState(0);
|
||
const [page, setPage] = useState(1);
|
||
const [serviceTarget, setServiceTarget] = useState(null);
|
||
|
||
const load = useCallback(async (p = 1) => {
|
||
setLoading(true);
|
||
try {
|
||
const res = await API.get(`/api/partner/customers?p=${p - 1}`);
|
||
if (res.data.success) {
|
||
setRows(res.data.data.items || []);
|
||
setTotal(res.data.data.total || 0);
|
||
setPage(p);
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load(1);
|
||
}, [load]);
|
||
|
||
const addService = async (values) => {
|
||
const quarter = `${new Date().getFullYear()}Q${Math.floor(new Date().getMonth() / 3) + 1}`;
|
||
const res = await API.post(
|
||
`/api/partner/customers/${serviceTarget.id}/service`,
|
||
{
|
||
type: values.type,
|
||
summary: values.summary,
|
||
quarter,
|
||
},
|
||
);
|
||
if (res.data.success) {
|
||
showSuccess(t('服务留痕已记录'));
|
||
setServiceTarget(null);
|
||
load(page);
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
const columns = [
|
||
{ title: t('客户名称'), dataIndex: 'customer_name' },
|
||
{ title: t('归属时间'), dataIndex: 'bound_at', render: fmtDate },
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
render: (v, r) => (
|
||
<span>
|
||
<Tag color={v === 'active' ? 'green' : 'grey'} shape='circle'>
|
||
{v === 'active' ? t('生效中') : t('已释放')}
|
||
</Tag>
|
||
{r.excluded_from_rebate && (
|
||
<Tag color='orange' shape='circle'>
|
||
{t('不计返佣')}
|
||
</Tag>
|
||
)}
|
||
</span>
|
||
),
|
||
},
|
||
{ title: t('最近服务'), dataIndex: 'last_service_at', render: fmtDate },
|
||
{
|
||
title: t('季度履约'),
|
||
dataIndex: 'service_miss_quarters',
|
||
render: (v) =>
|
||
v >= 1 ? (
|
||
<Tag color='red' shape='circle'>
|
||
{t('已缺 {{n}} 季度', { n: v })}
|
||
</Tag>
|
||
) : (
|
||
<Tag color='green' shape='circle'>
|
||
{t('正常')}
|
||
</Tag>
|
||
),
|
||
},
|
||
{
|
||
title: '',
|
||
render: (r) =>
|
||
!readOnly &&
|
||
r.status === 'active' && (
|
||
<Button size='small' onClick={() => setServiceTarget(r)}>
|
||
{t('服务留痕')}
|
||
</Button>
|
||
),
|
||
},
|
||
];
|
||
|
||
return (
|
||
<div>
|
||
<BrandTip className='mb-3'>
|
||
{t(
|
||
'每季度至少 1 次服务留痕;连续 2 个季度未履约将进入 30 天转出通知期',
|
||
)}
|
||
</BrandTip>
|
||
<Table
|
||
columns={columns}
|
||
dataSource={rows}
|
||
loading={loading}
|
||
rowKey='id'
|
||
scroll={{ x: 'max-content' }}
|
||
empty={<Empty description={t('暂无归属客户')} />}
|
||
pagination={{
|
||
total,
|
||
pageSize: 20,
|
||
currentPage: page,
|
||
onPageChange: load,
|
||
}}
|
||
/>
|
||
<Modal
|
||
title={`${t('服务留痕')} · ${serviceTarget?.customer_name || ''}`}
|
||
visible={!!serviceTarget}
|
||
onCancel={() => setServiceTarget(null)}
|
||
footer={null}
|
||
>
|
||
<Form key={serviceTarget?.id || 0} onSubmit={addService}>
|
||
<Form.Select
|
||
field='type'
|
||
label={t('服务类型')}
|
||
style={{ width: '100%' }}
|
||
rules={[{ required: true }]}
|
||
>
|
||
<Form.Select.Option value='demand'>
|
||
{t('需求对接')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='solution'>
|
||
{t('方案支持')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='revisit'>
|
||
{t('定期回访')}
|
||
</Form.Select.Option>
|
||
</Form.Select>
|
||
<Form.TextArea
|
||
field='summary'
|
||
label={t('服务纪要')}
|
||
maxLength={500}
|
||
rules={[{ required: true, message: t('请填写服务纪要') }]}
|
||
/>
|
||
<Button
|
||
theme='solid'
|
||
htmlType='submit'
|
||
type='primary'
|
||
block
|
||
style={{ margin: '16px 0 8px' }}
|
||
>
|
||
{t('提交')}
|
||
</Button>
|
||
</Form>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Bills({ t, readOnly }) {
|
||
const [rows, setRows] = useState([]);
|
||
const [detail, setDetail] = useState(null); // {bill, items, adjustments}
|
||
const [disputeTarget, setDisputeTarget] = useState(null); // 待发起争议的账单行
|
||
|
||
const load = useCallback(async () => {
|
||
const res = await API.get('/api/partner/bills');
|
||
if (res.data.success) setRows(res.data.data || []);
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
}, [load]);
|
||
|
||
const openDetail = async (bill) => {
|
||
const res = await API.get(`/api/partner/bills/${bill.id}/items`);
|
||
if (res.data.success) setDetail(res.data.data);
|
||
else showError(res.data.message);
|
||
};
|
||
|
||
const confirm = async (billId) => {
|
||
const res = await API.post(`/api/partner/bills/${billId}/confirm`);
|
||
if (res.data.success) {
|
||
showSuccess(t('账单已确认'));
|
||
setDetail(null);
|
||
load();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
const dispute = async (values) => {
|
||
const res = await API.post(
|
||
`/api/partner/bills/items/${disputeTarget.id}/dispute`,
|
||
{ note: values.note },
|
||
);
|
||
if (res.data.success) {
|
||
showSuccess(t('争议已登记:确认时该行返佣暂扣,无争议部分照常支付'));
|
||
setDisputeTarget(null);
|
||
openDetail({ id: detail.bill.id });
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
const columns = [
|
||
{ title: t('月份'), dataIndex: 'month' },
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
render: (v) => {
|
||
const [color, label] = BILL_STATUS[v] || ['grey', v];
|
||
return (
|
||
<Tag color={color} shape='circle'>
|
||
{t(label)}
|
||
</Tag>
|
||
);
|
||
},
|
||
},
|
||
{ title: t('净消耗(元)'), dataIndex: 'net_revenue_yuan', render: fmtYuan },
|
||
{ title: t('毛利(元)'), dataIndex: 'gross_profit_yuan', render: fmtYuan },
|
||
{
|
||
title: t('返佣(元)'),
|
||
render: (r) =>
|
||
fmtYuan(
|
||
(toFiniteNumber(r.l1_yuan) ?? 0) + (toFiniteNumber(r.l2_yuan) ?? 0),
|
||
),
|
||
},
|
||
{
|
||
title: t('应发(元)'),
|
||
dataIndex: 'payable_yuan',
|
||
render: (v) => formatNumber(v, 2, '0.00'),
|
||
},
|
||
{
|
||
title: '',
|
||
render: (r) => (
|
||
<span className='flex gap-2'>
|
||
<Button size='small' onClick={() => openDetail(r)}>
|
||
{t('明细')}
|
||
</Button>
|
||
<Button
|
||
size='small'
|
||
onClick={() =>
|
||
downloadCsv(
|
||
`/api/partner/bills/${r.id}/export`,
|
||
`partner-bill-${r.month}.csv`,
|
||
t,
|
||
)
|
||
}
|
||
>
|
||
{t('导出')}
|
||
</Button>
|
||
</span>
|
||
),
|
||
},
|
||
];
|
||
|
||
const itemColumns = [
|
||
{
|
||
title: t('层级'),
|
||
dataIndex: 'layer',
|
||
render: (v) => (v === 1 ? t('一层') : t('二层')),
|
||
},
|
||
{
|
||
title: t('客户/来源'),
|
||
render: (r) =>
|
||
r.layer === 1
|
||
? r.customer_name
|
||
: `${r.source_partner_name}(${t('客户数')} ${r.source_customer_count})`,
|
||
},
|
||
{
|
||
title: t('净消耗(元)'),
|
||
render: (r) => (r.layer === 1 ? fmtYuan(r.net_revenue_yuan) : '-'),
|
||
},
|
||
{
|
||
title: t('毛利(元)'),
|
||
render: (r) =>
|
||
r.layer === 1 ? fmtYuan(r.gross_profit_yuan) : r.tier_label || '-',
|
||
},
|
||
{ title: t('返佣(元)'), dataIndex: 'rebate_yuan', render: fmtYuan },
|
||
{
|
||
title: t('争议'),
|
||
render: (r) => {
|
||
if (r.disputed) {
|
||
return (
|
||
<Tag color={r.dispute_resolved ? 'green' : 'orange'} shape='circle'>
|
||
{r.dispute_resolved ? t('已裁决') : t('争议中')}
|
||
</Tag>
|
||
);
|
||
}
|
||
if (readOnly || detail?.bill?.status !== 'pending_confirm') return '-';
|
||
return (
|
||
<Button
|
||
size='small'
|
||
type='danger'
|
||
onClick={() => setDisputeTarget(r)}
|
||
>
|
||
{t('发起争议')}
|
||
</Button>
|
||
);
|
||
},
|
||
},
|
||
];
|
||
|
||
return (
|
||
<div>
|
||
<BrandTip className='mb-3'>
|
||
{t('月度账单于次月生成;确认后进入打款流程,如有异议可对单行发起争议')}
|
||
</BrandTip>
|
||
<Table
|
||
columns={columns}
|
||
dataSource={rows}
|
||
rowKey='id'
|
||
scroll={{ x: 'max-content' }}
|
||
empty={<Empty description={t('暂无账单')} />}
|
||
pagination={false}
|
||
/>
|
||
<Modal
|
||
title={
|
||
detail ? t('{{month}} 月账单明细', { month: detail.bill.month }) : ''
|
||
}
|
||
visible={!!detail}
|
||
onCancel={() => setDetail(null)}
|
||
width={860}
|
||
footer={
|
||
detail &&
|
||
!readOnly &&
|
||
detail.bill.status === 'pending_confirm' && (
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
onClick={() => confirm(detail.bill.id)}
|
||
>
|
||
{t('确认账单')}
|
||
</Button>
|
||
)
|
||
}
|
||
>
|
||
{detail && (
|
||
<>
|
||
<Descriptions
|
||
row
|
||
size='small'
|
||
data={[
|
||
{
|
||
key: t('定档'),
|
||
value: `${t('第 {{tier}} 档', { tier: detail.bill.tier })} · ${formatPercent(Number(detail.bill.tier_rate) * 100, 0)}`,
|
||
},
|
||
{ key: t('一层(元)'), value: fmtYuan(detail.bill.l1_yuan) },
|
||
{ key: t('二层(元)'), value: fmtYuan(detail.bill.l2_yuan) },
|
||
{ key: t('调整(元)'), value: fmtYuan(detail.bill.offset_yuan) },
|
||
{
|
||
key: t('期初结转(元)'),
|
||
value: fmtYuan(detail.bill.carry_in_yuan),
|
||
},
|
||
{
|
||
key: t('争议暂扣(元)'),
|
||
value: fmtYuan(detail.bill.disputed_hold_yuan),
|
||
},
|
||
{
|
||
key: t('应发(元)'),
|
||
value: formatNumber(detail.bill.payable_yuan, 2, '0.00'),
|
||
},
|
||
]}
|
||
/>
|
||
{detail.bill.status === 'suspended' && (
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
description={t('本账单正在平台复核中,复核通过后进入确认期')}
|
||
/>
|
||
)}
|
||
<Table
|
||
style={{ marginTop: 8 }}
|
||
columns={itemColumns}
|
||
dataSource={detail.items}
|
||
rowKey='id'
|
||
pagination={false}
|
||
size='small'
|
||
scroll={{ x: 'max-content' }}
|
||
/>
|
||
{detail.adjustments?.length > 0 && (
|
||
<>
|
||
<Title heading={6} style={{ marginTop: 12 }}>
|
||
{t('调整项明细')}
|
||
</Title>
|
||
<Table
|
||
columns={[
|
||
{
|
||
title: t('类型'),
|
||
dataIndex: 'type',
|
||
render: (v) => t(ADJ_TYPE_LABEL[v] || v),
|
||
},
|
||
{
|
||
title: t('金额(元)'),
|
||
dataIndex: 'amount_yuan',
|
||
render: fmtYuan,
|
||
},
|
||
{ title: t('说明'), dataIndex: 'reason' },
|
||
{ title: t('来源月份'), dataIndex: 'origin_month' },
|
||
]}
|
||
dataSource={detail.adjustments.map((a, i) => ({
|
||
...a,
|
||
_k: i,
|
||
}))}
|
||
rowKey='_k'
|
||
pagination={false}
|
||
size='small'
|
||
/>
|
||
</>
|
||
)}
|
||
<Text type='tertiary' size='small'>
|
||
{t('账单指纹')}: {detail.bill.content_hash?.slice(0, 16)}…
|
||
</Text>
|
||
</>
|
||
)}
|
||
</Modal>
|
||
<Modal
|
||
title={t('发起争议')}
|
||
visible={!!disputeTarget}
|
||
onCancel={() => setDisputeTarget(null)}
|
||
footer={null}
|
||
>
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
description={t(
|
||
'确认账单时该行返佣将暂扣,其余照常支付;裁决结果经调整项进入后续账单',
|
||
)}
|
||
/>
|
||
<div style={{ marginTop: 8 }}>
|
||
<Text type='tertiary' size='small'>
|
||
<Trans
|
||
t={t}
|
||
i18nKey='争议对象: {{value}} · 返佣(元) {{value2}}'
|
||
values={{
|
||
value:
|
||
disputeTarget?.layer === 1
|
||
? disputeTarget?.customer_name
|
||
: disputeTarget?.source_partner_name,
|
||
value2: fmtYuan(disputeTarget?.rebate_yuan),
|
||
}}
|
||
/>
|
||
</Text>
|
||
</div>
|
||
<Form key={disputeTarget?.id || 0} onSubmit={dispute}>
|
||
<Form.TextArea
|
||
field='note'
|
||
label={t('争议说明')}
|
||
maxLength={500}
|
||
placeholder={t(
|
||
'请说明争议原因,例如消耗数据与自查不符、客户归属有误等',
|
||
)}
|
||
rules={[{ required: true, message: t('请填写争议说明') }]}
|
||
/>
|
||
<div
|
||
className='flex gap-2 justify-end'
|
||
style={{ margin: '16px 0 8px' }}
|
||
>
|
||
<Button onClick={() => setDisputeTarget(null)}>{t('取消')}</Button>
|
||
<Button theme='solid' htmlType='submit' type='danger'>
|
||
{t('提交争议')}
|
||
</Button>
|
||
</div>
|
||
</Form>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const ACCOUNT_TYPE_LABEL = { bank: '银行账户', alipay: '支付宝' };
|
||
|
||
/** 收款账户:查看(掩码)+ 修改;变更触发 24h 打款冻结(§11.6) */
|
||
function PayoutAccount({ t, readOnly }) {
|
||
const [account, setAccount] = useState(null);
|
||
const [loaded, setLoaded] = useState(false);
|
||
const [editing, setEditing] = useState(false);
|
||
|
||
const load = useCallback(async () => {
|
||
try {
|
||
const res = await API.get('/api/partner/payout-account');
|
||
if (res.data.success) setAccount(res.data.data);
|
||
} catch {
|
||
/* 错误 toast 由全局拦截器兜底 */
|
||
} finally {
|
||
// 失败也要置 loaded,否则 tab 永远空白
|
||
setLoaded(true);
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
}, [load]);
|
||
|
||
const save = async (values) => {
|
||
const res = await API.put('/api/partner/payout-account', values);
|
||
if (res.data.success) {
|
||
showSuccess(res.data.message || t('已保存'));
|
||
setEditing(false);
|
||
load();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
};
|
||
|
||
if (!loaded) return null;
|
||
|
||
const frozen =
|
||
account?.frozen_until && account.frozen_until * 1000 > Date.now();
|
||
|
||
return (
|
||
<div className='max-w-2xl'>
|
||
<BrandTip className='mb-3'>
|
||
{t('返佣按收款账户打款;为保障资金安全,账户变更后 24 小时内暂停打款')}
|
||
</BrandTip>
|
||
{frozen && (
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
style={{ marginBottom: 12 }}
|
||
description={`${t('收款账户近期有变更,打款冻结至')} ${new Date(account.frozen_until * 1000).toLocaleString()}`}
|
||
/>
|
||
)}
|
||
{!editing && account && (
|
||
<Card className='!rounded-xl' styles={{ body: { padding: 20 } }}>
|
||
<div className='flex items-start justify-between gap-3'>
|
||
<div className='flex items-center gap-3 min-w-0'>
|
||
<div className='p-2.5 bg-brand/10 text-brand rounded-lg flex-shrink-0'>
|
||
<CreditCard size={20} />
|
||
</div>
|
||
<div className='min-w-0'>
|
||
<div className='flex items-center gap-2'>
|
||
<Text strong>{account.account_name}</Text>
|
||
<Tag color='white' shape='circle'>
|
||
{t(
|
||
ACCOUNT_TYPE_LABEL[account.account_type] ||
|
||
account.account_type,
|
||
)}
|
||
</Tag>
|
||
</div>
|
||
<Text type='tertiary' size='small' className='font-mono'>
|
||
{account.account_no}
|
||
{account.bank_name ? ` · ${account.bank_name}` : ''}
|
||
</Text>
|
||
</div>
|
||
</div>
|
||
{!readOnly && (
|
||
<Button
|
||
icon={<ActionPencil size={14} />}
|
||
size='small'
|
||
onClick={() => setEditing(true)}
|
||
>
|
||
{t('修改')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</Card>
|
||
)}
|
||
{!editing && !account && (
|
||
<Card className='!rounded-xl' styles={{ body: { padding: 24 } }}>
|
||
<div className='flex flex-col items-center text-center gap-2 py-4'>
|
||
<div className='p-2.5 bg-brand/10 text-brand rounded-lg'>
|
||
<CreditCard size={22} />
|
||
</div>
|
||
<Text strong>{t('尚未设置收款账户')}</Text>
|
||
<Text type='tertiary' size='small'>
|
||
{t('未设置收款账户将无法接收返佣打款,请尽快完善')}
|
||
</Text>
|
||
{!readOnly && (
|
||
<Button
|
||
theme='solid'
|
||
type='primary'
|
||
style={{ marginTop: 8 }}
|
||
onClick={() => setEditing(true)}
|
||
>
|
||
{t('立即设置')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</Card>
|
||
)}
|
||
{editing && (
|
||
<Card className='!rounded-xl' styles={{ body: { padding: 20 } }}>
|
||
{/* key 随开合重挂载,避免上次输入残留;账号后端返回掩码,修改需重新完整填写 */}
|
||
<Form key={editing ? 'open' : 'closed'} onSubmit={save}>
|
||
{({ formState }) => (
|
||
<>
|
||
<Form.Select
|
||
field='account_type'
|
||
label={t('账户类型')}
|
||
initValue={account?.account_type || 'bank'}
|
||
style={{ width: '100%' }}
|
||
rules={[{ required: true }]}
|
||
>
|
||
<Form.Select.Option value='bank'>
|
||
{t('银行账户')}
|
||
</Form.Select.Option>
|
||
<Form.Select.Option value='alipay'>
|
||
{t('支付宝')}
|
||
</Form.Select.Option>
|
||
</Form.Select>
|
||
{formState.values.account_type !== 'alipay' && (
|
||
<Form.Input
|
||
field='bank_name'
|
||
label={t('开户行')}
|
||
initValue={account?.bank_name || ''}
|
||
/>
|
||
)}
|
||
<Form.Input
|
||
field='account_name'
|
||
label={t('户名')}
|
||
initValue={account?.account_name || ''}
|
||
rules={[{ required: true, message: t('请输入户名') }]}
|
||
/>
|
||
<Form.Input
|
||
field='account_no'
|
||
label={t('账号(修改需完整重新填写)')}
|
||
placeholder={account?.account_no || ''}
|
||
rules={[{ required: true, message: t('请输入账号') }]}
|
||
/>
|
||
<div
|
||
className='flex gap-2 justify-end'
|
||
style={{ marginTop: 16 }}
|
||
>
|
||
<Button onClick={() => setEditing(false)}>{t('取消')}</Button>
|
||
<Button theme='solid' htmlType='submit' type='primary'>
|
||
{t('保存')}
|
||
</Button>
|
||
</div>
|
||
</>
|
||
)}
|
||
</Form>
|
||
</Card>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Referrals({ t, partnerCode }) {
|
||
const [rows, setRows] = useState([]);
|
||
|
||
useEffect(() => {
|
||
API.get('/api/partner/referrals').then((res) => {
|
||
if (res.data.success) setRows(res.data.data || []);
|
||
});
|
||
}, []);
|
||
|
||
return (
|
||
<div>
|
||
<div className='flex flex-wrap items-center justify-between gap-3 rounded-lg bg-brand/5 border border-brand/15 px-4 py-3 mb-3'>
|
||
<div className='flex items-start gap-2'>
|
||
<Info size={15} className='text-brand mt-0.5 flex-shrink-0' />
|
||
<span className='text-sm text-gray-600 dark:text-gray-300'>
|
||
{t(
|
||
'分享您的伙伴编号即可发展下级;下级生效后 12 个自然月内其客户毛利为您带来二层分佣',
|
||
)}
|
||
</span>
|
||
</div>
|
||
{partnerCode && <PartnerCodeChip code={partnerCode} t={t} />}
|
||
</div>
|
||
<Table
|
||
columns={[
|
||
{ title: t('伙伴编号'), dataIndex: 'partner_code' },
|
||
{ title: t('名称'), dataIndex: 'name' },
|
||
{
|
||
title: t('等级'),
|
||
dataIndex: 'level',
|
||
render: (v) => t(LEVEL_LABEL[v] || v),
|
||
},
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
render: (v) => (
|
||
<Tag color={v === 'active' ? 'green' : 'grey'} shape='circle'>
|
||
{v === 'active'
|
||
? t('生效中')
|
||
: v === 'dormant'
|
||
? t('休眠')
|
||
: t('已失效')}
|
||
</Tag>
|
||
),
|
||
},
|
||
{ title: t('生效日期'), dataIndex: 'effective_at', render: fmtDate },
|
||
{
|
||
title: t('二层计提剩余'),
|
||
dataIndex: 'l2_remaining_months',
|
||
render: (v) => (v > 0 ? t('{{n}} 个月', { n: v }) : t('已到期')),
|
||
},
|
||
{
|
||
title: t('累计二层返佣(元)'),
|
||
dataIndex: 'total_l2_rebate_yuan',
|
||
render: fmtYuan,
|
||
},
|
||
]}
|
||
dataSource={rows}
|
||
rowKey='partner_code'
|
||
scroll={{ x: 'max-content' }}
|
||
empty={
|
||
<Empty description={t('暂无下级伙伴,分享上方伙伴编号发展下级')} />
|
||
}
|
||
pagination={false}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Notices({ t, onRead, readOnly }) {
|
||
const [notifications, setNotifications] = useState([]);
|
||
const [announcements, setAnnouncements] = useState([]);
|
||
|
||
const load = useCallback(async () => {
|
||
const [n, a] = await Promise.all([
|
||
API.get('/api/partner/notifications'),
|
||
API.get('/api/partner/announcements'),
|
||
]);
|
||
if (n.data.success) setNotifications(n.data.data || []);
|
||
if (a.data.success) setAnnouncements(a.data.data || []);
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
}, [load]);
|
||
|
||
const markRead = async () => {
|
||
const res = await API.post('/api/partner/notifications/read');
|
||
if (res.data.success) {
|
||
load();
|
||
onRead?.();
|
||
}
|
||
};
|
||
|
||
return (
|
||
<div>
|
||
<div className='flex items-center justify-between mb-2'>
|
||
<div className='flex items-center gap-1.5'>
|
||
<Megaphone size={15} className='text-brand' />
|
||
<Title heading={6} style={{ margin: 0 }}>
|
||
{t('通知')}
|
||
</Title>
|
||
</div>
|
||
{!readOnly && (
|
||
<Button size='small' onClick={markRead}>
|
||
{t('全部已读')}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
{notifications.length === 0 && <Empty description={t('暂无通知')} />}
|
||
{notifications.map((n) => (
|
||
<Card
|
||
key={n.id}
|
||
className='!rounded-xl'
|
||
style={{ marginBottom: 8 }}
|
||
styles={{ body: { padding: 12 } }}
|
||
>
|
||
<div className='flex items-center justify-between'>
|
||
<span className='flex items-center gap-2'>
|
||
{!n.read && (
|
||
<span className='w-1.5 h-1.5 rounded-full bg-brand flex-shrink-0' />
|
||
)}
|
||
<Text strong={!n.read}>{n.title}</Text>
|
||
</span>
|
||
<Text type='tertiary' size='small'>
|
||
{fmtDate(n.created_at)}
|
||
</Text>
|
||
</div>
|
||
<Text type='tertiary' size='small'>
|
||
{n.content}
|
||
</Text>
|
||
</Card>
|
||
))}
|
||
<div className='flex items-center gap-1.5 mt-4 mb-2'>
|
||
<Megaphone size={15} className='text-brand' />
|
||
<Title heading={6} style={{ margin: 0 }}>
|
||
{t('平台公示')}
|
||
</Title>
|
||
</div>
|
||
{announcements.length === 0 && <Empty description={t('暂无公示')} />}
|
||
{announcements.map((a) => (
|
||
<Card
|
||
key={a.id}
|
||
className='!rounded-xl'
|
||
style={{ marginBottom: 8 }}
|
||
styles={{ body: { padding: 12 } }}
|
||
>
|
||
<div className='flex items-center justify-between'>
|
||
<Text strong>{a.title}</Text>
|
||
<Text type='tertiary' size='small'>
|
||
{fmtDate(a.published_at)}
|
||
</Text>
|
||
</div>
|
||
<Text size='small' style={{ whiteSpace: 'pre-wrap' }}>
|
||
{a.content}
|
||
</Text>
|
||
</Card>
|
||
))}
|
||
</div>
|
||
);
|
||
}
|