/* 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 . For commercial licensing, please contact support@quantumnous.com */ 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 ( ); } function FormSection({ title, children }) { return (

{title}

{children}
); } function EvidenceInput({ value, onChange }) { const { t } = useTranslation(); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [selectedName, setSelectedName] = useState(''); return (
PDF / JPG / PNG / WEBP / Word / Excel · 10MB {selectedName && ( {selectedName} )} {value && }
{error && }
); } 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 {reference || '—'}; return ( <> {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) => ( {['evidence', 'agreement_evidence'].includes(key) ? ( set(key, value)} /> ) : ( set(key, value)} placeholder={required ? t('必填') : undefined} /> )} ); const dateField = (key, label, required = false) => ( set(key, pickerEpoch(firstValue, secondValue)) } style={{ width: '100%' }} /> ); const choices = ( key, label, rows, name = (item) => item.name || item.display_name || item.username || item.code, ) => (