// 弹窗系统(对应原 modal/guide/openHistoricalCase/openQuotationLibrary/知识图谱/表单弹窗) import { useEffect, useMemo, useRef, useState } from 'react' import { money, esc } from './logic' import { HISTORY_CASES, kbRecords } from './data' import type { Material, Resource, State } from './types' import { useApp } from './store' import { Btn, Notice, Table } from './components' // ============ 知识图谱 ============ function materialNetworkData(s: State, type: 'material' | 'resource') { const list: any[] = type === 'resource' ? (s.resources as any[]) : (s.materials as any[]) const sources: { key: string; known: boolean; x: number; y: number }[] = [] const nodes = list.map((m, i) => { const record: any = (kbRecords as any)[type].find((r: any) => r.id === m.id && r.name === m.name && r.ref === m.ref) const key = type === 'resource' ? (record ? (record.ref.includes('内部工艺') ? '内部工艺定额' : record.name.includes('焊接') ? '焊接工时依据' : '机加工工艺依据') : '上传 / 人工数据') : record ? (record.ref.includes('SIM-IS') ? 'SIM-IS-01' : record.ref.includes('SIM-OS') ? 'SIM-OS-01' : record.ref.includes('§4') ? '需求书 §4' : '需求书 §3') : '上传 / 人工数据' let source = sources.findIndex((x) => x.key === key) if (source < 0) { source = sources.length; sources.push({ key, known: !!record, x: 0, y: 0 }) } const angle = -Math.PI / 2 + (i * Math.PI * 2) / Math.max(1, list.length) return { m, record, source, x: 480 + 338 * Math.cos(angle), y: 248 + 174 * Math.sin(angle), i } }) sources.forEach((src, i) => { const a = -Math.PI / 2 + (i * Math.PI * 2) / sources.length src.x = 480 + 147 * Math.cos(a) src.y = 248 + 88 * Math.sin(a) }) return { sources, nodes } } function NetworkSvg() { const { s, flows, selectMaterialNetwork } = useApp() const a = flows.materialNetwork const type = a.type || 'material' const { sources, nodes } = useMemo(() => materialNetworkData(s, type), [s, type]) const shown = a.done ? nodes.length : Math.max(0, a.stage - 1) const visible = nodes.slice(0, shown) const resource = type === 'resource' return ( {a.stage >= 1 && ( <> {sources.map((src, i) => ( ))} {visible.map((n) => { const src = sources[n.source] return })} )} 当前项目 {resource ? '工艺资源关联' : '物料知识关联'} {a.stage >= 1 && sources.map((src, i) => ( {src.key} ))} {visible.map((n) => { const active = a.selected === n.i && a.done const color = n.record ? '#f18e84' : '#e3bc5b' return ( selectMaterialNetwork(n.i)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); selectMaterialNetwork(n.i) } }}> {n.m.name + ';来源:' + n.m.ref} {n.m.name.length > 16 ? n.m.name.slice(0, 15) + '…' : n.m.name} {n.m.id} ) })} 项目 来源 {resource ? '匹配工序' : '匹配物料'} 待核验数据 ) } function MaterialNetworkModal() { const { s, flows, replayKnowledgeNetwork } = useApp() const a = flows.materialNetwork const type = a.type || 'material' const { sources, nodes } = useMemo(() => materialNetworkData(s, type), [s, type]) const resource = type === 'resource' const n = nodes[a.selected] const status = a.done ? `关联构建完成:${sources.length} 个${resource ? '工艺依据' : '来源'}节点 · ${nodes.length} ${resource ? '道工序' : '项物料'} · ${sources.length + nodes.length} 条关联。点击${resource ? '工序' : '物料'}节点核对详情。` : a.stage === 0 ? (resource ? '索引检索 Agent:读取当前项目与工艺资源索引…' : '索引检索 Agent:读取当前项目与物料索引…') : a.stage === 1 ? (resource ? '关系映射 Agent:建立工艺定额与工时依据节点…' : '关系映射 Agent:建立图纸与需求条款来源节点…') : shown2() < nodes.length ? `关系映射 Agent:逐项关联${resource ? '工序' : '物料'} ${shown2()} / ${nodes.length}…` : (resource ? '来源校核 Agent:核对工时、综合费率与计价口径…' : '来源校核 Agent:比对记录与当前用量,整理追溯信息…') function shown2() { return a.done ? nodes.length : Math.max(0, a.stage - 1) } return (
✦ AI {resource ? '工艺资源' : '数据'}关联网络 {resource ? '项目 → 工艺依据 / 工时记录 → 工序资源 → 来源核对' : '项目 → 图纸 / 需求条款 → 物料 → 来源核对'}
01 索引检索 Agent02 关系映射 Agent03 来源校核 Agent
{status}

{resource ? '离线关联演示:依据当前工序、内置工艺记录与工时来源字段构建,未连接企业实际工艺库;未匹配记录显示为上传 / 人工数据。' : '离线关联演示:图谱依据当前物料及内置来源字段构建;未匹配记录显示为上传 / 人工数据。'}

{n ? ( resource ? : ) : ( )}
) } function MaterialNetworkDetail({ m, record }: { m: Material; record?: any }) { const { s, flows, selectMaterialNetwork } = useApp() const ref = m.ref || '待补充' const doc = record ? (ref.includes('SIM-IS') ? '/mod-assets/wuc-quotation/模拟内套图.svg' : ref.includes('SIM-OS') ? '/mod-assets/wuc-quotation/模拟外套图.svg' : '/mod-assets/wuc-quotation/客户需求书.md') : null return ( <>
{s.materials.map((r, i) => ( selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} /> ))}
{record ? '本地示例记录匹配' : '未匹配内置记录 / 人工数据'}

{m.id} · {m.name}

来源关联:{ref}

{doc ? 打开来源文件 ↗ : } ) } function ResourceNetworkDetail({ r, record }: { r: Resource; record?: any }) { const { s, flows, selectMaterialNetwork } = useApp() const hasRate = r.rate != null && Number.isFinite(r.rate) && r.rate > 0 return ( <>
{s.resources.map((item, i) => ( selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} /> ))}
{record ? '本地工艺示例记录匹配' : '未匹配内置记录 / 人工数据'}

{r.id} · {r.name}

工时来源:{r.ref || '待补充'}

) } // ============ 历史案例 ============ function HistoricalCaseModal({ id }: { id: string }) { const { s, openModal, closeModal } = useApp() const c = HISTORY_CASES[id] if (!c) return null const total = c.costs.reduce((sum, x) => sum + x[1], 0) const profit = c.price - total const manufacturing = c.process.reduce((sum, x) => sum + x[1] * x[2], 0) void manufacturing return (

项目概况

供货范围与技术要求

{c.scope}

{c.quality}

物料与依据

制造工艺与资源

[r[0], r[1], money(r[2]), money(r[1] * r[2])])} />

成本与成交报价

[r[0], money(r[1]) + ' 元']), ['项目全成本', money(total) + ' 元'], ['不含税成交总价', money(c.price) + ' 元'], ['不含税单位报价', money(c.price / c.sets) + ' 元/套'], ['项目利润', money(profit) + ' 元'], ['实际项目利润率', ((profit / c.price) * 100).toFixed(2) + '%'], ['模拟税额(13%)', money(c.price * 0.13) + ' 元'], ['模拟含税总额', money(c.price * 1.13) + ' 元'], ]} />

交付计划与商务条件

{c.terms}

报价参考与差异

{c.reason}

{c.risk}

a + m.qty * m.price, 0) + s.resources.reduce((a, r) => a + r.qty * (r.rate || 0), 0)) + ' 元(当前清单,未含专项与间接费)'], ['利润率参考', c.margin + '%(模拟成交)', s.floor + '%(硬性底线)'], ]} />
openModal('case', '历史案例 ' + (id === 'H01' ? 'H02' : 'H01') + ' / 完整项目参考', id === 'H01' ? 'H02' : 'H01')} />
) } // ============ 历史报价信息库 / 报价智能体 ============ function QuoteAgentProgress() { const { flows } = useApp() const a = flows.quoteAssistant if (!a.mode) return null const steps = a.mode === 'analysis' ? ['读取归档字段', '核算成本结构', '核对风险依据', '整理分析结论'] : ['理解查询条件', '检索本地记录', '核对项目字段', '逐项展示结果'] return (
{a.running ? '● Agent 协同处理中' : a.cancelled ? '处理已停止' : a.mode === 'analysis' ? '分析已完成' : '检索已完成'} {steps.map((t, i) => (
{i < a.stage ? '✓' : '0' + (i + 1)}{t}
))} 展示检索与计算步骤,不代表外部模型实时调用。
) } function QuoteAgentAnalysis() { const { flows, library } = useApp() const a = flows.quoteAssistant void library if (!a.analysis.length) { return (
◈
选择一个项目,开启证据驱动的归因分析

逐项呈现成本结构、风险线索和待核验依据。

) } const shown = a.analysis.slice(0, a.analysisCount) const kindLabel: Record = { fact: '可核算事实', attention: '需复核', hypothesis: '风险线索 / 非因果结论', action: '核验建议' } return (
PROJECT DIAGNOSTICS

{a.analysisTitle}

{a.running && a.mode === 'analysis' ? '正在构建分析' : '分析记录'}
{!shown.length ?
正在读取项目档案与成本字段…
: shown.map((x, i) => (
{kindLabel[x.kind]}

{x.title}

{x.text}

{x.bars && (
{x.bars.map((b, j) => (
{b.name} {money(b.value)}
))}
)}
依据 {x.evidence}
))}
) } function QuotationLibraryModal() { const { library, filters, setFilters, flows, useQuoteAgentPrompt, runQuoteAgentQuery, analyzeSelectedQuotation, selectAgentQuotation, showAllAgentQuotes, openModal, } = useApp() const a = flows.quoteAssistant const [input, setInput] = useState('') const messagesRef = useRef(null) const messages = a.messages.length ? a.messages : [{ role: 'assistant' as const, text: '你好,我可以帮你查找历史报价,并对选中项目核算成本结构、梳理风险依据。可按项目、客户、编号、年份、金额和交期查找。' }] useEffect(() => { const el = messagesRef.current if (el) el.scrollTop = el.scrollHeight }, [a.messages.length, a.stage, a.analysisCount]) let rows = filters.from && filters.to && filters.from > filters.to ? [] : libraryAll() function libraryAll() { const saved = library.map((r) => ({ ...r, kind: 'saved' })) const examples = Object.entries(HISTORY_CASES).map(([id, c]) => ({ id, number: c.code, project: c.name, customer: c.customer, date: c.date.startsWith('2025-09') ? '2025-09-01' : '2025-12-01', sets: c.sets, days: c.days, price: c.price, total: c.price * 1.13, kind: 'example', })) return [...saved, ...examples] } if (a.ids !== null) rows = rows.filter((r: any) => a.ids!.includes(r.id)) const shown = a.mode === 'search' && a.running ? rows.slice(0, a.revealed) : rows return (