2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
1544 lines
56 KiB
React
1544 lines
56 KiB
React
import React, { useEffect, useRef, useState } from 'react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { Button, Checkbox, Empty, Spin } from 'antd';
|
||
// 存量 Semi 契约(受控值 onChange(value)、visible、data/empty 等)与控制台作用域
|
||
// (ConsoleModal / ConsoleDrawer / ConsoleTable / ConsoleAlert)由适配层统一映射。
|
||
import {
|
||
Alert,
|
||
DatePicker,
|
||
Descriptions,
|
||
Input,
|
||
InputNumber,
|
||
Modal,
|
||
Radio,
|
||
RadioGroup,
|
||
Select,
|
||
SideSheet,
|
||
Table,
|
||
TextArea,
|
||
} from '@/components/ui';
|
||
import { Upload as ActionUpload } from '@/components/common/icons/ActionIcons';
|
||
import { commissionLabel, commissionLevelName } from './labels';
|
||
import {
|
||
COMMISSION_EVIDENCE_ACCEPT,
|
||
commissionEvidenceErrorMessage,
|
||
validateCommissionEvidenceFile,
|
||
} from './evidenceUpload';
|
||
import {
|
||
getInitialOperationForm,
|
||
partnerIdentityPayload,
|
||
levelBindingPayload,
|
||
validateContractSignedConversion,
|
||
} from './operationForm';
|
||
import { pickerEpoch } from './datePicker';
|
||
import { API } from '../../helpers';
|
||
import {
|
||
formatCurrency,
|
||
formatIdReference,
|
||
formatPercent,
|
||
toFiniteNumber,
|
||
} from '../../helpers/safeDisplay';
|
||
import RemoteIdentitySelect from './RemoteIdentitySelect';
|
||
import { fetchAllLatestTiers } from './latestTiers';
|
||
import './formSections.css';
|
||
import { useCommissionThemeStyle } from './commissionTheme';
|
||
|
||
const time = (value) => (value ? new Date(value * 1000).toLocaleString() : '—');
|
||
export function Field({ label, children, required = false }) {
|
||
return (
|
||
<label className='commission-form-field'>
|
||
<span>
|
||
{required && <span className='commission-required'>*</span>}
|
||
{label}
|
||
</span>
|
||
{children}
|
||
</label>
|
||
);
|
||
}
|
||
function FormSection({ title, children }) {
|
||
return (
|
||
<section className='commission-form-section'>
|
||
<h3>{title}</h3>
|
||
<div className='commission-form-section-grid'>{children}</div>
|
||
</section>
|
||
);
|
||
}
|
||
function EvidenceInput({ value, onChange }) {
|
||
const { t } = useTranslation();
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState('');
|
||
const [selectedName, setSelectedName] = useState('');
|
||
return (
|
||
<div className='commission-evidence-input'>
|
||
<div className='commission-evidence-input-row'>
|
||
<Input
|
||
value={value || ''}
|
||
onChange={onChange}
|
||
placeholder={t('凭证编号或受控附件地址')}
|
||
/>
|
||
<label className='commission-evidence-upload-button'>
|
||
<ActionUpload size={16} />
|
||
<span>{busy ? t('上传中') : t('上传凭证')}</span>
|
||
<input
|
||
type='file'
|
||
accept={COMMISSION_EVIDENCE_ACCEPT}
|
||
disabled={busy}
|
||
onChange={async (event) => {
|
||
const file = event.target.files?.[0];
|
||
event.target.value = '';
|
||
const validationError = validateCommissionEvidenceFile(file);
|
||
if (validationError) {
|
||
setError(validationError);
|
||
return;
|
||
}
|
||
const payload = new FormData();
|
||
payload.append('file', file);
|
||
setBusy(true);
|
||
setError('');
|
||
setSelectedName(file.name);
|
||
try {
|
||
const response = await API.post(
|
||
'/api/commission/v2/attachments',
|
||
payload,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success) {
|
||
const uploadError = new Error(
|
||
response.data?.message || t('上传失败'),
|
||
);
|
||
uploadError.response = response;
|
||
throw uploadError;
|
||
}
|
||
onChange(response.data.data.reference);
|
||
} catch (err) {
|
||
setSelectedName('');
|
||
setError(commissionEvidenceErrorMessage(err));
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
/>
|
||
</label>
|
||
</div>
|
||
<div className='commission-evidence-meta'>
|
||
<span>PDF / JPG / PNG / WEBP / Word / Excel · 10MB</span>
|
||
{selectedName && (
|
||
<span className='commission-evidence-file' title={selectedName}>
|
||
{selectedName}
|
||
</span>
|
||
)}
|
||
{value && <EvidenceLink value={value} />}
|
||
</div>
|
||
{error && <Alert showIcon type='error' description={error} />}
|
||
</div>
|
||
);
|
||
}
|
||
export function EvidenceLink({ value }) {
|
||
const { t } = useTranslation();
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState('');
|
||
const reference = String(value || '');
|
||
const attachment = reference.match(/attachment:(\d+)/);
|
||
if (!attachment) return <span>{reference || '—'}</span>;
|
||
return (
|
||
<>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
loading={busy}
|
||
onClick={async () => {
|
||
const preview = window.open('about:blank', '_blank');
|
||
if (preview) preview.opener = null;
|
||
setBusy(true);
|
||
setError('');
|
||
try {
|
||
const response = await API.get(
|
||
`/api/commission/v2/attachments/${attachment[1]}`,
|
||
{ skipErrorHandler: true },
|
||
);
|
||
if (!response.data?.success || !response.data.data?.url)
|
||
throw new Error(response.data?.message || t('下载失败'));
|
||
if (preview) preview.location.href = response.data.data.url;
|
||
else
|
||
window.open(
|
||
response.data.data.url,
|
||
'_blank',
|
||
'noopener,noreferrer',
|
||
);
|
||
} catch (err) {
|
||
preview?.close();
|
||
setError(err.message);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
>
|
||
{t('查看凭证')} #{attachment[1]}
|
||
</Button>
|
||
{error && <Alert showIcon type='error' description={error} />}
|
||
</>
|
||
);
|
||
}
|
||
|
||
// All mutation forms collect the business fact and evidence before submission.
|
||
export function OperationsDialog({
|
||
operation,
|
||
options,
|
||
partners,
|
||
tiers,
|
||
fetchJSON,
|
||
mutateJSON,
|
||
onClose,
|
||
onSaved,
|
||
}) {
|
||
const themeStyle = useCommissionThemeStyle();
|
||
const { t } = useTranslation();
|
||
const [form, setForm] = useState({});
|
||
const [error, setError] = useState('');
|
||
const [busy, setBusy] = useState(false);
|
||
const [history, setHistory] = useState([]);
|
||
const [bindingConfigs, setBindingConfigs] = useState([]);
|
||
const identitySelect = useRef(null);
|
||
const close = () => {
|
||
identitySelect.current?.invalidate();
|
||
onClose();
|
||
};
|
||
const kind = operation?.kind || '';
|
||
const row = operation?.row || {};
|
||
const set = (key, value) =>
|
||
setForm((current) => ({ ...current, [key]: value }));
|
||
useEffect(() => {
|
||
if (!operation) return;
|
||
let current = true;
|
||
setError('');
|
||
setBusy(false);
|
||
setHistory([]);
|
||
setForm(getInitialOperationForm(operation));
|
||
const resource = ['partner-edit', 'partner-agreement'].includes(kind)
|
||
? `partners/${row.id}`
|
||
: kind === 'assignment-history'
|
||
? `assignments/${row.id}/events`
|
||
: kind === 'tier-history'
|
||
? 'tier-bindings'
|
||
: null;
|
||
if (kind === 'tier-binding') {
|
||
setBindingConfigs([]);
|
||
setBusy(true);
|
||
fetchAllLatestTiers(fetchJSON, { type: 'level' })
|
||
.then((items) => {
|
||
if (current) setBindingConfigs(items);
|
||
})
|
||
.catch((err) => current && setError(err.message))
|
||
.finally(() => current && setBusy(false));
|
||
}
|
||
if (resource) {
|
||
setBusy(true);
|
||
fetchJSON(`/api/commission/v2/${resource}`)
|
||
.then((value) => {
|
||
if (!current) return;
|
||
if (['partner-edit', 'partner-agreement'].includes(kind))
|
||
setForm({ ...value, evidence: value.agreement_evidence || '' });
|
||
else setHistory(value);
|
||
})
|
||
.catch((err) => current && setError(err.message))
|
||
.finally(() => current && setBusy(false));
|
||
}
|
||
return () => {
|
||
current = false;
|
||
};
|
||
}, [operation, fetchJSON, kind, row.id]);
|
||
const title = {
|
||
'partner-create': '新建伙伴档案',
|
||
'partner-edit': '编辑伙伴档案',
|
||
'partner-agreement': '登记或续签协议',
|
||
'partner-status': '变更合作状态',
|
||
'assignment-create': '新增客户归属',
|
||
'assignment-convert': '确认正式归属',
|
||
'assignment-extend': '延长保护期',
|
||
'assignment-transfer': '转移客户归属',
|
||
'assignment-terminate': '终止客户归属',
|
||
'assignment-reject': '驳回转化',
|
||
'assignment-history': '归属历史',
|
||
'tier-create': row.id ? '修改分佣档位' : '新增分佣档位',
|
||
'tier-binding': '绑定等级档位',
|
||
'tier-history': '等级绑定历史',
|
||
'tier-status': '变更档位状态',
|
||
exception: '异常详情与重试',
|
||
}[kind];
|
||
const readonly = ['assignment-history', 'tier-history', 'exception'].includes(
|
||
kind,
|
||
);
|
||
const historyView = ['assignment-history', 'tier-history'].includes(kind);
|
||
const partnerProfile = ['partner-create', 'partner-edit'].includes(kind);
|
||
const Dialog = partnerProfile ? SideSheet : Modal;
|
||
const modalClassName = [
|
||
'commission-modal',
|
||
readonly ? 'commission-modal--readonly' : 'commission-modal--form',
|
||
historyView ? 'commission-modal--history' : '',
|
||
kind === 'exception' ? 'commission-modal--exception' : '',
|
||
]
|
||
.filter(Boolean)
|
||
.join(' ');
|
||
const modalWidth =
|
||
kind === 'assignment-history' ? 920 : kind === 'tier-history' ? 840 : 720;
|
||
const input = (key, label, required = false) => (
|
||
<Field label={t(label)} required={required}>
|
||
{['evidence', 'agreement_evidence'].includes(key) ? (
|
||
<EvidenceInput
|
||
value={form[key]}
|
||
onChange={(value) => set(key, value)}
|
||
/>
|
||
) : (
|
||
<Input
|
||
value={form[key] || ''}
|
||
onChange={(value) => set(key, value)}
|
||
placeholder={required ? t('必填') : undefined}
|
||
/>
|
||
)}
|
||
</Field>
|
||
);
|
||
const dateField = (key, label, required = false) => (
|
||
<Field label={t(label)} required={required}>
|
||
<DatePicker
|
||
type='dateTime'
|
||
value={form[key] ? new Date(form[key] * 1000) : undefined}
|
||
// Persist the Date object so locale formatting cannot silently lose or
|
||
// shift the agreement effective date.
|
||
onChange={(firstValue, secondValue) =>
|
||
set(key, pickerEpoch(firstValue, secondValue))
|
||
}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Field>
|
||
);
|
||
const choices = (
|
||
key,
|
||
label,
|
||
rows,
|
||
name = (item) =>
|
||
item.name || item.display_name || item.username || item.code,
|
||
) => (
|
||
<Field label={t(label)}>
|
||
<Select
|
||
filter
|
||
showClear
|
||
value={form[key]}
|
||
onChange={(value) => set(key, value)}
|
||
style={{ width: '100%' }}
|
||
optionList={rows.map((item) => ({
|
||
value: item.id,
|
||
label: `${name(item)} (${formatIdReference(item.id)})`,
|
||
}))}
|
||
/>
|
||
</Field>
|
||
);
|
||
const reason = () => (
|
||
<FormSection title={t('业务依据')}>
|
||
<Field label={t('业务原因')}>
|
||
<TextArea
|
||
value={form.reason || ''}
|
||
onChange={(value) => set('reason', value)}
|
||
rows={3}
|
||
/>
|
||
</Field>
|
||
{input('evidence', '凭证编号或受控附件地址')}
|
||
</FormSection>
|
||
);
|
||
const submit = async () => {
|
||
setBusy(true);
|
||
setError('');
|
||
try {
|
||
let url = '',
|
||
method = 'post',
|
||
body = { ...form };
|
||
if (kind.startsWith('partner-')) {
|
||
if (['partner-create', 'partner-edit'].includes(kind)) {
|
||
body = partnerIdentityPayload(form, t);
|
||
url = `partners${kind === 'partner-edit' ? `/${row.id}` : ''}`;
|
||
method = kind === 'partner-edit' ? 'put' : 'post';
|
||
} else if (kind === 'partner-agreement') {
|
||
if (
|
||
!form.agreement_no?.trim() ||
|
||
!form.agreement_effective_at ||
|
||
!form.agreement_expires_at ||
|
||
form.agreement_expires_at <= form.agreement_effective_at
|
||
)
|
||
throw new Error(t('请填写协议编号及正确的有效期'));
|
||
url = `partners/${row.id}`;
|
||
method = 'put';
|
||
body = { ...form, agreement_evidence: form.evidence };
|
||
} else {
|
||
if (!form.reason?.trim()) throw new Error(t('请填写业务原因'));
|
||
url = `partners/${row.id}/status`;
|
||
body = {
|
||
status: operation.status,
|
||
reason: form.reason,
|
||
evidence: form.evidence,
|
||
};
|
||
}
|
||
} else if (kind.startsWith('assignment-')) {
|
||
if (kind === 'assignment-create') {
|
||
if (!form.subject_id || !form.partner_id)
|
||
throw new Error(t('请选择客户主体和归属伙伴'));
|
||
url = 'assignments';
|
||
body = { ...form, subject_type: form.subject_type || 'user' };
|
||
} else {
|
||
url = `assignments/${row.id}/${kind.slice('assignment-'.length)}`;
|
||
body = {
|
||
...form,
|
||
fact_at: ['assignment-transfer', 'assignment-terminate'].includes(
|
||
kind,
|
||
)
|
||
? form.effective_at
|
||
: form.fact_at,
|
||
};
|
||
if (!['assignment-transfer', 'assignment-terminate'].includes(kind)) {
|
||
delete body.effective_at;
|
||
}
|
||
}
|
||
if (
|
||
kind === 'assignment-convert' ||
|
||
(kind === 'assignment-create' && form.status === 'formal')
|
||
) {
|
||
if (!form.fact_at || !form.evidence?.trim())
|
||
throw new Error(t('正式归属必须提供实际转化时间和凭证'));
|
||
if (form.method === 'contract_signed') {
|
||
const contractError = validateContractSignedConversion(form, t);
|
||
if (contractError) throw new Error(contractError);
|
||
}
|
||
}
|
||
if (!form.reason?.trim() || !form.evidence?.trim())
|
||
throw new Error(t('请填写业务原因及凭证'));
|
||
if (kind === 'assignment-extend' && !form.progress?.trim())
|
||
throw new Error(t('请填写当前进展阶段'));
|
||
if (
|
||
[
|
||
'assignment-transfer',
|
||
'assignment-terminate',
|
||
'assignment-reject',
|
||
'assignment-extend',
|
||
].includes(kind) &&
|
||
!form.reason?.trim()
|
||
)
|
||
throw new Error(t('请填写业务原因'));
|
||
if (kind === 'assignment-transfer' && form.partner_id == null)
|
||
throw new Error(t('请选择接收伙伴'));
|
||
if (kind === 'assignment-extend' && (!form.days || form.days > 60))
|
||
throw new Error(t('延期天数必须为1至60天'));
|
||
} else if (kind === 'tier-create') {
|
||
if (
|
||
(form.source_type === 'channel' && !form.channel_ids?.length) ||
|
||
(form.source_type === 'model' && !form.model_names?.length) ||
|
||
(form.source_type === 'level' && (!form.level_type || !form.tier_key))
|
||
)
|
||
throw new Error(t('请选择档位关联对象'));
|
||
url = 'tiers';
|
||
body = {
|
||
...form,
|
||
source_id: 0,
|
||
channel_ids: form.source_type === 'channel' ? form.channel_ids : [],
|
||
model_names: form.source_type === 'model' ? form.model_names : [],
|
||
effective_from: form.effective_from || Math.floor(Date.now() / 1000),
|
||
};
|
||
} else if (kind === 'tier-binding') {
|
||
const level = (options.levels || []).find(
|
||
(item) =>
|
||
`${item.type}:${item.id || item.key}` === form.level_selection,
|
||
);
|
||
url = 'tier-bindings';
|
||
body = levelBindingPayload(form, level, t);
|
||
} else if (kind === 'tier-status') {
|
||
if (!form.reason?.trim()) throw new Error(t('请填写业务原因'));
|
||
url = `tiers/${row.id}/status`;
|
||
body = { enabled: operation.enabled, reason: form.reason };
|
||
}
|
||
await mutateJSON(method, `/api/commission/v2/${url}`, body);
|
||
onClose();
|
||
await onSaved();
|
||
} catch (err) {
|
||
setError(err.message);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
};
|
||
return (
|
||
<Dialog
|
||
style={themeStyle}
|
||
className={partnerProfile ? 'commission-partner-sheet' : modalClassName}
|
||
width={modalWidth}
|
||
title={t(title || '详情')}
|
||
visible={!!operation}
|
||
onCancel={close}
|
||
{...(partnerProfile
|
||
? {
|
||
placement: 'right',
|
||
footer: (
|
||
<div className='commission-partner-sheet-actions'>
|
||
<Button onClick={close}>{t('取消')}</Button>
|
||
<Button type='primary' loading={busy} onClick={submit}>
|
||
{t(kind === 'partner-create' ? '保存草稿' : '保存')}
|
||
</Button>
|
||
</div>
|
||
),
|
||
}
|
||
: {
|
||
onOk: readonly ? close : submit,
|
||
okText: t(readonly ? '关闭' : '确认提交'),
|
||
cancelText: t('取消'),
|
||
confirmLoading: busy,
|
||
})}
|
||
>
|
||
{error && (
|
||
<Alert
|
||
showIcon
|
||
className='commission-modal-alert'
|
||
type='error'
|
||
description={error}
|
||
/>
|
||
)}
|
||
{busy && readonly ? (
|
||
<Spin />
|
||
) : (
|
||
<div className='commission-operation-form'>
|
||
{['partner-create', 'partner-edit'].includes(kind) && (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'合作伙伴的审核准入与合同签署在线下完成,本系统登记伙伴档案与签约结果。',
|
||
)}
|
||
/>
|
||
<FormSection title={t('基本信息')}>
|
||
<Field label={t('主体类型(创建后不可修改)')} required>
|
||
<RadioGroup
|
||
value={form.type}
|
||
disabled={kind === 'partner-edit'}
|
||
onChange={(event) => {
|
||
identitySelect.current?.invalidate();
|
||
setForm((current) => ({
|
||
...current,
|
||
type: event.target.value,
|
||
user_id: undefined,
|
||
organization_id: undefined,
|
||
}));
|
||
}}
|
||
>
|
||
<Radio value='company'>{t('企业伙伴')}</Radio>
|
||
<Radio value='individual'>{t('个人伙伴')}</Radio>
|
||
</RadioGroup>
|
||
</Field>
|
||
{input('name', '伙伴名称', true)}
|
||
{input(
|
||
'identity_no',
|
||
form.type === 'company' ? '统一社会信用代码' : '证件号码',
|
||
)}
|
||
{input('contact_name', '联系人')}
|
||
{input('contact_phone', '联系电话')}
|
||
{input('contact_email', '联系邮箱')}
|
||
<Field
|
||
label={t(
|
||
form.type === 'company' ? '关联企业' : '关联个人用户',
|
||
)}
|
||
required
|
||
>
|
||
{kind === 'partner-edit' ? (
|
||
<Input
|
||
readOnly
|
||
value={
|
||
form.type === 'company'
|
||
? `${form.organization_name || ''} (#${form.organization_id || '—'})`
|
||
: `${form.user_display_name || form.username || ''} (#${form.user_id || '—'})`
|
||
}
|
||
/>
|
||
) : (
|
||
<RemoteIdentitySelect
|
||
ref={identitySelect}
|
||
key={form.type}
|
||
type={form.type}
|
||
value={
|
||
form.type === 'company'
|
||
? form.organization_id
|
||
: form.user_id
|
||
}
|
||
fetchJSON={fetchJSON}
|
||
onChange={(value) =>
|
||
set(
|
||
form.type === 'company'
|
||
? 'organization_id'
|
||
: 'user_id',
|
||
value,
|
||
)
|
||
}
|
||
/>
|
||
)}
|
||
</Field>
|
||
{form.type === 'company' && (
|
||
<span className='commission-field-hint'>
|
||
{t('关联企业的所有者和管理员可进入企业分佣工作台。')}
|
||
</span>
|
||
)}
|
||
</FormSection>
|
||
<FormSection title={t('协议信息')}>
|
||
{input('agreement_no', '协议编号')}
|
||
{dateField('agreement_effective_at', '协议生效时间')}
|
||
{dateField('agreement_expires_at', '协议到期时间')}
|
||
{input('agreement_evidence', '协议附件')}
|
||
<span className='commission-field-hint commission-form-span'>
|
||
{t('续签请登记新的协议编号,原协议与历史记录将保留。')}
|
||
</span>
|
||
</FormSection>
|
||
<FormSection title={t('结算资料')}>
|
||
{input('receiving_name', '收款户名')}
|
||
{input('receiving_account', '收款账号')}
|
||
{input('receiving_bank', '开户银行')}
|
||
</FormSection>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t('先保存档案并登记有效协议,再启用合作。')}
|
||
/>
|
||
{kind === 'partner-edit' && (
|
||
<Descriptions
|
||
data={[
|
||
{
|
||
key: t('状态'),
|
||
value: commissionLabel(t, 'status', form.status),
|
||
},
|
||
{ key: t('协议编号'), value: form.agreement_no || '—' },
|
||
{
|
||
key: t('协议到期'),
|
||
value: time(form.agreement_expires_at),
|
||
},
|
||
]}
|
||
/>
|
||
)}
|
||
</>
|
||
)}
|
||
{kind === 'partner-agreement' && (
|
||
<FormSection title={t('协议信息')}>
|
||
{input('agreement_no', '协议编号', true)}
|
||
{dateField('agreement_effective_at', '协议生效时间')}
|
||
{dateField('agreement_expires_at', '协议到期时间')}
|
||
{input('evidence', '凭证编号或受控附件地址')}
|
||
</FormSection>
|
||
)}
|
||
{kind === 'partner-status' && (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={`${t('目标状态')}:${commissionLabel(t, 'status', operation.status)}`}
|
||
/>
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{kind === 'assignment-create' && (
|
||
<FormSection title={t('归属信息')}>
|
||
<Field label={t('客户类型')}>
|
||
<Select
|
||
value={form.subject_type || 'user'}
|
||
onChange={(value) => {
|
||
set('subject_type', value);
|
||
set('subject_id', undefined);
|
||
}}
|
||
optionList={[
|
||
{ value: 'user', label: t('个人用户') },
|
||
{ value: 'organization', label: t('企业组织') },
|
||
]}
|
||
/>
|
||
</Field>
|
||
{choices(
|
||
'subject_id',
|
||
'客户主体',
|
||
form.subject_type === 'organization'
|
||
? options.organizations || []
|
||
: options.users || [],
|
||
)}
|
||
{choices(
|
||
'partner_id',
|
||
'归属伙伴',
|
||
partners.filter((item) => item.status === 'active'),
|
||
)}
|
||
<Field label={t('归属方式')}>
|
||
<Select
|
||
value={form.status}
|
||
onChange={(value) => set('status', value)}
|
||
optionList={[
|
||
{ value: 'protected', label: t('保护归属') },
|
||
{ value: 'formal', label: t('直接正式归属') },
|
||
]}
|
||
/>
|
||
</Field>
|
||
</FormSection>
|
||
)}
|
||
{kind === 'assignment-create' && form.status !== 'formal' && reason()}
|
||
{(kind === 'assignment-convert' ||
|
||
(kind === 'assignment-create' && form.status === 'formal')) && (
|
||
<>
|
||
<FormSection title={t('转化事实')}>
|
||
<Field label={t('转化依据')}>
|
||
<Select
|
||
value={form.method}
|
||
onChange={(value) => set('method', value)}
|
||
optionList={[
|
||
{ value: 'contract_signed', label: t('合同签约') },
|
||
{ value: 'wallet_paid', label: t('真实充值与付费消耗') },
|
||
]}
|
||
/>
|
||
</Field>
|
||
{dateField('fact_at', '实际转化事实时间', true)}
|
||
{form.method === 'contract_signed' && (
|
||
<>
|
||
{input('reference', '合同编号', true)}
|
||
{input('contract_subject', '签约主体', true)}
|
||
{dateField('signed_at', '合同签署日期', true)}
|
||
<span className='commission-field-hint commission-form-span'>
|
||
{t('合同签署日期不能晚于实际转化事实时间')}
|
||
</span>
|
||
<span className='commission-field-hint commission-form-span'>
|
||
{t(
|
||
'此处填写客户签约合同;伙伴合作协议需在「合作伙伴」中另行登记,且有效期须覆盖实际转化事实时间。',
|
||
)}
|
||
</span>
|
||
</>
|
||
)}
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'正式归属从事实时间起算;充值消耗转化须同时核验保护期内的真实充值及正常钱包付费调用。',
|
||
)}
|
||
/>
|
||
</FormSection>
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{kind === 'assignment-extend' && (
|
||
<>
|
||
<FormSection title={t('保护期延期')}>
|
||
{input('progress', '当前进展阶段', true)}
|
||
<Field label={t('延期天数(最多一次,不超过60天)')}>
|
||
<InputNumber
|
||
min={1}
|
||
max={60}
|
||
value={form.days}
|
||
onChange={(value) => set('days', value)}
|
||
/>
|
||
</Field>
|
||
</FormSection>
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{kind === 'assignment-transfer' && (
|
||
<>
|
||
<FormSection title={t('转移信息')}>
|
||
{choices(
|
||
'partner_id',
|
||
'接收伙伴',
|
||
partners
|
||
.filter(
|
||
(item) =>
|
||
item.status === 'active' && item.id !== row.partner_id,
|
||
)
|
||
.concat([{ id: 0, name: t('平台自营') }]),
|
||
)}
|
||
{dateField('effective_at', '转移生效时间')}
|
||
</FormSection>
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{kind === 'assignment-terminate' && (
|
||
<>
|
||
{dateField('effective_at', '终止生效时间')}
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{kind === 'assignment-reject' && reason()}
|
||
{kind === 'tier-create' && (
|
||
<>
|
||
<FormSection title={t('档位信息')}>
|
||
<Field label={t('档位分类')}>
|
||
<Select
|
||
value={form.source_type}
|
||
disabled={!!row.id}
|
||
onChange={(value) =>
|
||
setForm((current) => ({
|
||
...current,
|
||
source_type: value,
|
||
source_id: 0,
|
||
channel_ids: [],
|
||
model_names: [],
|
||
tier_key: '',
|
||
level_type: undefined,
|
||
level_selection: undefined,
|
||
}))
|
||
}
|
||
optionList={[
|
||
{ value: 'channel', label: t('渠道档位') },
|
||
{ value: 'model', label: t('模型档位') },
|
||
{ value: 'level', label: t('等级档位') },
|
||
]}
|
||
/>
|
||
</Field>
|
||
{input('name', '档位名称')}
|
||
{['channel', 'model'].includes(form.source_type) && (
|
||
<div className='commission-tier-targets'>
|
||
<Field
|
||
label={t(
|
||
form.source_type === 'model'
|
||
? '关联模型(可多选)'
|
||
: '关联渠道(可多选)',
|
||
)}
|
||
>
|
||
<Select
|
||
multiple
|
||
filter
|
||
showClear
|
||
maxTagCount={3}
|
||
value={
|
||
form.source_type === 'model'
|
||
? form.model_names || []
|
||
: form.channel_ids || []
|
||
}
|
||
placeholder={t(
|
||
form.source_type === 'model'
|
||
? '搜索并选择模型超市中的模型'
|
||
: '搜索并选择关联渠道',
|
||
)}
|
||
onChange={(value) =>
|
||
set(
|
||
form.source_type === 'model'
|
||
? 'model_names'
|
||
: 'channel_ids',
|
||
value,
|
||
)
|
||
}
|
||
optionList={
|
||
form.source_type === 'model'
|
||
? [
|
||
...new Set([
|
||
...(options.models || []),
|
||
...(row.model_names || []),
|
||
]),
|
||
].map((name) => ({ value: name, label: name }))
|
||
: [
|
||
...new Map([
|
||
...(
|
||
row.channel_ids ||
|
||
(row.source_id ? [row.source_id] : [])
|
||
).map((id) => [
|
||
id,
|
||
{ value: id, label: `#${id}` },
|
||
]),
|
||
...(options.channels || []).map((channel) => [
|
||
channel.id,
|
||
{
|
||
value: channel.id,
|
||
label: `${channel.name || t('未知渠道')} (${formatIdReference(channel.id)})`,
|
||
},
|
||
]),
|
||
]).values(),
|
||
]
|
||
}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Field>
|
||
<span className='commission-field-hint'>
|
||
{t('已选择 {{count}} 个对象,共用下方提成比例', {
|
||
count:
|
||
(form.source_type === 'model'
|
||
? form.model_names
|
||
: form.channel_ids
|
||
)?.length || 0,
|
||
})}
|
||
</span>
|
||
</div>
|
||
)}
|
||
{form.source_type === 'level' ? (
|
||
<Field label={t('现有客户等级')}>
|
||
<Select
|
||
filter
|
||
disabled={!!row.id}
|
||
value={form.level_selection}
|
||
onChange={(value) => {
|
||
const level = (options.levels || []).find(
|
||
(item) => `${item.type}:${item.key}` === value,
|
||
);
|
||
set('level_selection', value);
|
||
set('level_type', level?.type);
|
||
set('tier_key', level?.key);
|
||
}}
|
||
optionList={(options.levels || []).map((level) => ({
|
||
value: `${level.type}:${level.key}`,
|
||
label: `${level.type === 'enterprise' ? t('企业等级') : t('个人等级')} · ${commissionLevelName(t, level)} (${level.key})`,
|
||
disabled: level.is_default || level.key === 'default',
|
||
}))}
|
||
/>
|
||
</Field>
|
||
) : (
|
||
<Field label={t('档位编码')}>
|
||
<Input
|
||
value={form.tier_key || ''}
|
||
disabled={!!row.id}
|
||
onChange={(value) => set('tier_key', value)}
|
||
placeholder={t('留空自动生成')}
|
||
maxLength={64}
|
||
/>
|
||
</Field>
|
||
)}
|
||
</FormSection>
|
||
<FormSection title={t('提成规则')}>
|
||
<Field label={t('提成比例')}>
|
||
<InputNumber
|
||
min={0}
|
||
max={100}
|
||
precision={2}
|
||
suffix='%'
|
||
value={Number(form.rate_bps || 0) / 100}
|
||
onChange={(value) =>
|
||
set('rate_bps', Math.round(Number(value) * 100))
|
||
}
|
||
/>
|
||
</Field>
|
||
{dateField('effective_from', '档位生效时间')}
|
||
</FormSection>
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'默认等级按模型优先、渠道兜底匹配;非默认等级使用等级档位。0%有效,比例不叠加。修改将创建新版本,历史计费快照保持原比例。',
|
||
)}
|
||
/>
|
||
</>
|
||
)}
|
||
{kind === 'tier-binding' && (
|
||
<FormSection title={t('等级档位绑定')}>
|
||
<Field label={t('客户等级')}>
|
||
<Select
|
||
filter
|
||
value={form.level_selection}
|
||
onChange={(value) => set('level_selection', value)}
|
||
optionList={(options.levels || []).map((level) => ({
|
||
value: `${level.type}:${level.id || level.key}`,
|
||
label: `${level.type === 'enterprise' ? t('企业等级') : t('个人等级')} · ${commissionLevelName(t, level)} (${level.key})`,
|
||
disabled: level.is_default || level.key === 'default',
|
||
}))}
|
||
/>
|
||
</Field>
|
||
{choices(
|
||
'config_id',
|
||
'等级档位',
|
||
bindingConfigs.map((item) => ({ ...item, id: item.config_id })),
|
||
(item) =>
|
||
`${item.name || item.tier_key || t('未知档位')} · 配置 ${formatIdReference(item.config_id)}`,
|
||
)}
|
||
{dateField('effective_from', '绑定生效时间', true)}
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
'按绑定生效时间解析有效版本;绑定不自动跟随后续版本,到期后请明确重新绑定。0%不会回退渠道比例。',
|
||
)}
|
||
/>
|
||
</FormSection>
|
||
)}
|
||
{kind === 'tier-status' && (
|
||
<>
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={t(
|
||
operation.enabled
|
||
? '启用会创建新的有效版本,历史比例保持不变。'
|
||
: '停用立即结束当前有效期,后续计费缺少档位时会进入异常。',
|
||
)}
|
||
/>
|
||
{reason()}
|
||
</>
|
||
)}
|
||
{['assignment-history', 'tier-history'].includes(kind) && (
|
||
<div className='commission-history-table'>
|
||
<Table
|
||
rowKey='id'
|
||
dataSource={history}
|
||
pagination={{ pageSize: 10 }}
|
||
empty={
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={t('暂无历史')}
|
||
/>
|
||
}
|
||
columns={
|
||
kind === 'assignment-history'
|
||
? [
|
||
{
|
||
title: t('动作'),
|
||
dataIndex: 'event_type',
|
||
width: 120,
|
||
render: (value) =>
|
||
commissionLabel(t, 'operation', value),
|
||
},
|
||
{
|
||
title: t('时间'),
|
||
dataIndex: 'created_at',
|
||
width: 190,
|
||
render: (value) => (
|
||
<span className='commission-history-nowrap'>
|
||
{time(value)}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: t('原因'),
|
||
dataIndex: 'reason',
|
||
width: 280,
|
||
render: (value) => value || '—',
|
||
},
|
||
{
|
||
title: t('凭证'),
|
||
dataIndex: 'evidence',
|
||
width: 190,
|
||
render: (value) => <EvidenceLink value={value} />,
|
||
},
|
||
]
|
||
: [
|
||
{
|
||
title: t('等级类型'),
|
||
dataIndex: 'level_type',
|
||
width: 130,
|
||
},
|
||
{
|
||
title: t('等级'),
|
||
dataIndex: 'level_key',
|
||
width: 160,
|
||
},
|
||
{
|
||
title: t('档位'),
|
||
dataIndex: 'tier_id',
|
||
width: 120,
|
||
},
|
||
{
|
||
title: t('生效时间'),
|
||
dataIndex: 'effective_from',
|
||
width: 190,
|
||
render: (value) => (
|
||
<span className='commission-history-nowrap'>
|
||
{time(value)}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: t('结束时间'),
|
||
dataIndex: 'effective_to',
|
||
width: 190,
|
||
render: (value) => (
|
||
<span className='commission-history-nowrap'>
|
||
{time(value)}
|
||
</span>
|
||
),
|
||
},
|
||
]
|
||
}
|
||
/>
|
||
</div>
|
||
)}
|
||
{kind === 'exception' && (
|
||
<div className='commission-exception-content'>
|
||
<Descriptions
|
||
data={Object.entries(row)
|
||
.filter(([key]) => !['metadata_json'].includes(key))
|
||
.map(([key, value]) => ({
|
||
key: t(key),
|
||
value: String(value ?? '—'),
|
||
}))}
|
||
/>
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={t(
|
||
'修复归属或档位配置后重试计提;只有重试成功才会解除异常。',
|
||
)}
|
||
/>
|
||
<Button
|
||
loading={busy}
|
||
onClick={async () => {
|
||
setBusy(true);
|
||
try {
|
||
await mutateJSON(
|
||
'post',
|
||
`/api/commission/v2/exceptions/${row.id}/retry`,
|
||
{},
|
||
);
|
||
onClose();
|
||
await onSaved();
|
||
} catch (err) {
|
||
setError(err.message);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
>
|
||
{t('重试计提')}
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
</Dialog>
|
||
);
|
||
}
|
||
|
||
export function BillingColumns(t, money, date) {
|
||
return [
|
||
{ title: t('计费事实'), dataIndex: 'billing_record_id' },
|
||
{ title: t('计费时间'), dataIndex: 'billed_at', render: date },
|
||
{
|
||
title: t('客户'),
|
||
dataIndex: 'customer_name',
|
||
render: (value, row) =>
|
||
value ||
|
||
`${commissionLabel(t, 'subjectType', row.subject_type)} #${row.subject_id || '—'}`,
|
||
},
|
||
{ title: t('模型'), dataIndex: 'model_name' },
|
||
{
|
||
title: t('消费场景'),
|
||
dataIndex: 'group_name',
|
||
render: (value, row) => value || row.group || '—',
|
||
},
|
||
{
|
||
title: t('计费时等级'),
|
||
render: (_, row) =>
|
||
`${row.level_type || row.level_scope || ''} · ${row.level_name || row.level_key || '—'} ${(row.is_default_level ?? row.level_is_default) ? `(${t('默认')})` : ''}`,
|
||
},
|
||
{
|
||
title: t('分佣档位'),
|
||
render: (_, row) =>
|
||
`${commissionLabel(t, 'sourceType', row.tier_source || row.source_type)} · ${row.tier_name || row.tier_key || '—'}`,
|
||
},
|
||
{
|
||
title: t('原始销售额'),
|
||
dataIndex: 'original_amount_uyuan',
|
||
render: (value, row) => money(value ?? row.base_amount_uyuan),
|
||
},
|
||
{
|
||
title: t('扣减类型'),
|
||
dataIndex: 'deduction_type',
|
||
render: (value) => value || '—',
|
||
},
|
||
{
|
||
title: t('扣减金额'),
|
||
dataIndex: 'deduction_amount_uyuan',
|
||
render: money,
|
||
},
|
||
{ title: t('有效销售额'), dataIndex: 'base_amount_uyuan', render: money },
|
||
{
|
||
title: t('比例'),
|
||
dataIndex: 'rate_bps',
|
||
render: (value) => formatPercent(Number(value || 0) / 100, 2),
|
||
},
|
||
{ title: t('提成金额'), dataIndex: 'commission_uyuan', render: money },
|
||
];
|
||
}
|
||
|
||
export function AdjustmentColumns(t, money) {
|
||
return [
|
||
{ title: t('调整单号'), dataIndex: 'id' },
|
||
{
|
||
title: t('类型'),
|
||
dataIndex: 'type',
|
||
render: (value) => commissionLabel(t, 'adjustmentType', value),
|
||
},
|
||
{
|
||
title: t('客户'),
|
||
dataIndex: 'customer_name',
|
||
render: (value) => value || '—',
|
||
},
|
||
{
|
||
title: t('归属账期'),
|
||
dataIndex: 'original_month',
|
||
render: (value, row) => value || row.statement_month || '—',
|
||
},
|
||
{
|
||
title: t('分佣档位'),
|
||
render: (_, row) =>
|
||
row.type === 'sales_amount'
|
||
? row.tier_key || `#${row.detail_id || '—'}`
|
||
: '—',
|
||
},
|
||
{
|
||
title: t('销售额调整'),
|
||
render: (_, row) =>
|
||
row.type === 'sales_amount' ? money(row.amount_uyuan) : '—',
|
||
},
|
||
{
|
||
title: t('提成影响'),
|
||
render: (_, row) =>
|
||
money(
|
||
row.commission_impact_uyuan ??
|
||
(row.type === 'commission_amount' ? row.amount_uyuan : 0),
|
||
),
|
||
},
|
||
{ title: t('业务调整原因'), dataIndex: 'reason' },
|
||
];
|
||
}
|
||
|
||
export function SettlementDialog({
|
||
operation,
|
||
statement,
|
||
items,
|
||
mutateJSON,
|
||
onClose,
|
||
onSaved,
|
||
}) {
|
||
const themeStyle = useCommissionThemeStyle();
|
||
const { t } = useTranslation();
|
||
const [form, setForm] = useState({});
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState('');
|
||
const kind = operation?.kind;
|
||
const set = (key, value) =>
|
||
setForm((current) => ({ ...current, [key]: value }));
|
||
useEffect(() => {
|
||
setError('');
|
||
setForm({
|
||
type: 'commission_amount',
|
||
amount:
|
||
kind === 'payment'
|
||
? Number(statement?.payable_uyuan || 0) / 1e6
|
||
: kind === 'fee'
|
||
? Number(statement?.fee_uyuan || 0) / 1e6
|
||
: Number(operation?.row?.amount_uyuan || 0) / 1e6,
|
||
paid_at: Math.floor(Date.now() / 1000),
|
||
...operation?.row,
|
||
});
|
||
}, [
|
||
operation,
|
||
statement?.id,
|
||
statement?.payable_uyuan,
|
||
statement?.fee_uyuan,
|
||
kind,
|
||
]);
|
||
const submit = async () => {
|
||
setBusy(true);
|
||
setError('');
|
||
try {
|
||
let method = 'post',
|
||
path = `statements/${statement.id}`,
|
||
body = { ...form };
|
||
if (['issue', 'deadline'].includes(kind)) {
|
||
if (
|
||
!form.confirmation_deadline ||
|
||
form.confirmation_deadline <= Date.now() / 1000
|
||
)
|
||
throw new Error(t('请填写未来的确认截止时间'));
|
||
if (kind === 'issue' && (!form.special_reviewed || !form.data_reviewed))
|
||
throw new Error(t('请完成全部出账前确认清单'));
|
||
path += `/${kind}`;
|
||
if (kind === 'deadline') method = 'put';
|
||
} else if (kind === 'payment') {
|
||
if (
|
||
Number(statement.payable_uyuan) > 0 &&
|
||
(!form.paid_at || !form.reference?.trim() || !form.evidence?.trim())
|
||
)
|
||
throw new Error(t('请填写打款日期、流水号及凭证'));
|
||
if (
|
||
Math.round(Number(form.amount) * 1e6) !==
|
||
Number(statement.payable_uyuan) &&
|
||
!form.difference_reason?.trim()
|
||
)
|
||
throw new Error(t('实付与应付不一致时必须填写差异原因'));
|
||
path += '/complete';
|
||
body = { ...form, amount_uyuan: Math.round(Number(form.amount) * 1e6) };
|
||
} else if (kind === 'fee') {
|
||
if (Number(form.amount) < 0) throw new Error(t('手续费不能为负数'));
|
||
path += '/fee';
|
||
method = 'put';
|
||
body = {
|
||
fee_uyuan: Math.round(Number(form.amount) * 1e6),
|
||
reason: form.reason,
|
||
evidence: form.evidence,
|
||
};
|
||
} else {
|
||
if (!form.reason?.trim()) throw new Error(t('请填写业务原因'));
|
||
if (
|
||
kind !== 'adjustment-void' &&
|
||
(!Number.isFinite(Number(form.amount)) || Number(form.amount) === 0)
|
||
)
|
||
throw new Error(t('调整金额必须为非零金额'));
|
||
if (form.type === 'sales_amount' && !form.detail_id)
|
||
throw new Error(t('销售额调整必须关联原始计费明细'));
|
||
body = { ...form, amount_uyuan: Math.round(Number(form.amount) * 1e6) };
|
||
if (kind === 'adjustment') path += '/adjustments';
|
||
else if (kind === 'adjustment-edit') {
|
||
path = `adjustments/${operation.row.id}`;
|
||
method = 'put';
|
||
} else {
|
||
path = `adjustments/${operation.row.id}/void`;
|
||
body = { reason: form.reason };
|
||
}
|
||
}
|
||
await mutateJSON(method, `/api/commission/v2/${path}`, body);
|
||
onClose();
|
||
await onSaved();
|
||
} catch (err) {
|
||
setError(err.message);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
};
|
||
return (
|
||
<Modal
|
||
style={themeStyle}
|
||
className='commission-modal commission-modal--form commission-modal--settlement'
|
||
width={720}
|
||
title={t(
|
||
{
|
||
issue: '确认出账',
|
||
deadline: '修改确认截止日期',
|
||
payment: '登记已打款',
|
||
fee: '录入手续费',
|
||
adjustment: '添加账单调整',
|
||
'adjustment-edit': '修改调整单',
|
||
'adjustment-void': '作废调整单',
|
||
}[kind] || '账单操作',
|
||
)}
|
||
visible={!!operation}
|
||
onCancel={onClose}
|
||
onOk={submit}
|
||
confirmLoading={busy}
|
||
okText={t(
|
||
kind === 'issue'
|
||
? '确认出账'
|
||
: kind === 'payment'
|
||
? '确认已打款'
|
||
: ['adjustment', 'adjustment-edit', 'fee'].includes(kind)
|
||
? '保存'
|
||
: '确认提交',
|
||
)}
|
||
cancelText={t('取消')}
|
||
>
|
||
{error && (
|
||
<Alert
|
||
showIcon
|
||
className='commission-modal-alert'
|
||
type='error'
|
||
description={error}
|
||
/>
|
||
)}
|
||
<div className='commission-operation-form'>
|
||
{['issue', 'payment', 'fee'].includes(kind) && (
|
||
<Alert
|
||
showIcon
|
||
type='info'
|
||
description={t(
|
||
kind === 'issue'
|
||
? '请核对账单数据并填写确认截止日期,出账后账单进入待确认状态。'
|
||
: kind === 'payment'
|
||
? '请核对线下打款结果并登记付款信息,登记后账单将完成结算。'
|
||
: '请登记本账期手续费及依据,出账后手续费锁定。',
|
||
)}
|
||
/>
|
||
)}
|
||
{statement && (
|
||
<div className='commission-settlement-context'>
|
||
<Descriptions
|
||
row
|
||
data={[
|
||
{ key: t('账单编号'), value: formatIdReference(statement.id) },
|
||
{ key: t('账期'), value: statement.statement_month || '—' },
|
||
{
|
||
key: t('应付金额'),
|
||
value: formatCurrency(
|
||
(toFiniteNumber(statement.payable_uyuan) ?? 0) / 1e6,
|
||
'¥',
|
||
2,
|
||
'¥0.00',
|
||
),
|
||
},
|
||
]}
|
||
/>
|
||
</div>
|
||
)}
|
||
{kind !== 'adjustment-void' && (
|
||
<FormSection
|
||
title={t(
|
||
['issue', 'deadline'].includes(kind)
|
||
? '确认信息'
|
||
: kind === 'payment'
|
||
? '付款信息'
|
||
: kind === 'fee'
|
||
? '手续费信息'
|
||
: '调整信息',
|
||
)}
|
||
>
|
||
{['issue', 'deadline'].includes(kind) && (
|
||
<>
|
||
<Field label={t('确认截止日期')}>
|
||
<DatePicker
|
||
type='dateTime'
|
||
value={
|
||
form.confirmation_deadline
|
||
? new Date(form.confirmation_deadline * 1000)
|
||
: undefined
|
||
}
|
||
onChange={(first, second) =>
|
||
set('confirmation_deadline', pickerEpoch(first, second))
|
||
}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Field>
|
||
{kind === 'issue' && (
|
||
<>
|
||
<div className='commission-checklist'>
|
||
<Checkbox
|
||
checked={!!form.special_reviewed}
|
||
onChange={(event) =>
|
||
set('special_reviewed', event.target.checked)
|
||
}
|
||
>
|
||
{t('本账期无需特殊项目线下调整,或已通过调整单录入')}
|
||
</Checkbox>
|
||
<Checkbox
|
||
checked={!!form.data_reviewed}
|
||
onChange={(event) =>
|
||
set('data_reviewed', event.target.checked)
|
||
}
|
||
>
|
||
{t('已核对调整单及异常数据')}
|
||
</Checkbox>
|
||
</div>
|
||
<Alert
|
||
showIcon
|
||
type='warning'
|
||
description={t(
|
||
'出账后金额锁定;伙伴驳回后才能重新核对并出账。',
|
||
)}
|
||
/>
|
||
</>
|
||
)}
|
||
</>
|
||
)}
|
||
{['adjustment', 'adjustment-edit'].includes(kind) && (
|
||
<>
|
||
<Field label={t('调整类型')}>
|
||
<Select
|
||
value={form.type}
|
||
disabled={kind === 'adjustment-edit'}
|
||
onChange={(value) => set('type', value)}
|
||
optionList={[
|
||
{ value: 'commission_amount', label: t('提成金额调整') },
|
||
{ value: 'sales_amount', label: t('销售额调整') },
|
||
]}
|
||
/>
|
||
</Field>
|
||
{form.type === 'sales_amount' && (
|
||
<>
|
||
<Field label={t('原始计费明细')}>
|
||
<Select
|
||
value={form.detail_id}
|
||
filter
|
||
onChange={(value) => set('detail_id', value)}
|
||
optionList={items.map((item) => ({
|
||
value: item.detail_id,
|
||
label: `${formatIdReference(item.billing_record_id)} · ${item.model_name || t('未知模型')} · ${formatPercent(Number(item.rate_bps) / 100, 2)}`,
|
||
}))}
|
||
/>
|
||
</Field>
|
||
<Field label={t('或填写历史计费明细 ID')}>
|
||
<InputNumber
|
||
min={1}
|
||
value={form.detail_id}
|
||
onChange={(value) => set('detail_id', value)}
|
||
/>
|
||
</Field>
|
||
</>
|
||
)}
|
||
<Field label={t('原始账单 ID(跨期调整时填写)')}>
|
||
<InputNumber
|
||
min={1}
|
||
value={form.original_statement_id}
|
||
onChange={(value) => set('original_statement_id', value)}
|
||
/>
|
||
</Field>
|
||
</>
|
||
)}
|
||
{['payment', 'fee', 'adjustment', 'adjustment-edit'].includes(
|
||
kind,
|
||
) && (
|
||
<Field
|
||
label={t(
|
||
kind === 'payment'
|
||
? '实付金额'
|
||
: kind === 'fee'
|
||
? '手续费金额'
|
||
: '调整金额,可填负数',
|
||
)}
|
||
>
|
||
<InputNumber
|
||
prefix='¥'
|
||
precision={2}
|
||
min={['payment', 'fee'].includes(kind) ? 0 : undefined}
|
||
value={form.amount}
|
||
onChange={(value) => set('amount', value)}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</Field>
|
||
)}
|
||
{kind === 'payment' && (
|
||
<>
|
||
<Field label={t('打款日期')}>
|
||
<DatePicker
|
||
type='dateTime'
|
||
value={
|
||
form.paid_at ? new Date(form.paid_at * 1000) : undefined
|
||
}
|
||
onChange={(first, second) =>
|
||
set('paid_at', pickerEpoch(first, second))
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label={t('付款流水号')}>
|
||
<Input
|
||
value={form.reference || ''}
|
||
onChange={(value) => set('reference', value)}
|
||
/>
|
||
</Field>
|
||
<Field label={t('差异原因')}>
|
||
<TextArea
|
||
value={form.difference_reason || ''}
|
||
onChange={(value) => set('difference_reason', value)}
|
||
/>
|
||
</Field>
|
||
</>
|
||
)}
|
||
</FormSection>
|
||
)}
|
||
{kind !== 'issue' && (
|
||
<FormSection title={t('业务依据')}>
|
||
{!['issue', 'payment'].includes(kind) && (
|
||
<Field label={t('业务原因')}>
|
||
<TextArea
|
||
value={form.reason || ''}
|
||
onChange={(value) => set('reason', value)}
|
||
rows={3}
|
||
/>
|
||
</Field>
|
||
)}
|
||
{['payment', 'fee', 'adjustment', 'adjustment-edit'].includes(
|
||
kind,
|
||
) && (
|
||
<Field label={t('凭证编号或受控附件地址')}>
|
||
<EvidenceInput
|
||
value={form.evidence || ''}
|
||
onChange={(value) => set('evidence', value)}
|
||
/>
|
||
</Field>
|
||
)}
|
||
</FormSection>
|
||
)}
|
||
</div>
|
||
</Modal>
|
||
);
|
||
}
|