新增武传demo

This commit is contained in:
2026-10-18 21:20:33 +08:00
parent 32c16e86b0
commit 8f6904b2d1
25 changed files with 3693 additions and 2 deletions
+605
View File
@@ -0,0 +1,605 @@
// 弹窗系统(对应原 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 (
<svg viewBox="0 0 960 500" role="img"
aria-label={resource ? '项目与工艺依据、工时记录、工序的来源关系网络' : '项目与图纸、需求条款、物料的来源关系网络'}>
<defs>
<radialGradient id="networkBg"><stop stopColor="#233252" /><stop offset="1" stopColor="#0c1428" /></radialGradient>
<filter id="networkGlow"><feGaussianBlur stdDeviation="4" /></filter>
</defs>
<rect width="960" height="500" rx="12" fill="url(#networkBg)" />
<g fill="none" stroke="#5e79ad" strokeOpacity=".25" strokeDasharray="2 8">
<ellipse cx="480" cy="248" rx="338" ry="174" />
<ellipse cx="480" cy="248" rx="230" ry="129" />
<ellipse cx="480" cy="248" rx="147" ry="88" />
</g>
<g className="network-links">
{a.stage >= 1 && (
<>
{sources.map((src, i) => (
<path key={'s' + i} d={`M480 248 L${src.x} ${src.y}`} stroke="#50bfbd" strokeWidth="1.5" fill="none" opacity=".55" />
))}
{visible.map((n) => {
const src = sources[n.source]
return <path key={'n' + n.i} d={`M${src.x} ${src.y} Q480 248 ${n.x} ${n.y}`}
stroke={n.record ? '#55b9b0' : '#d9ac4e'} opacity=".45" fill="none" />
})}
</>
)}
</g>
<g fontFamily="Microsoft YaHei,Segoe UI" textAnchor="middle">
<circle cx="480" cy="248" r="41" fill="#8a79ff" opacity=".25" filter="url(#networkGlow)" />
<circle cx="480" cy="248" r="30" fill="#7160ce" stroke="#c6b8ff" />
<text x="480" y="245" fontSize="13" fill="white" fontWeight="700">当前项目</text>
<text x="480" y="262" fontSize="10" fill="#ece9ff">{resource ? '工艺资源关联' : '物料知识关联'}</text>
{a.stage >= 1 && sources.map((src, i) => (
<g key={'g' + i} className="network-node">
<circle cx={src.x} cy={src.y} r="16" fill="#163e50" stroke={src.known ? '#66d4c5' : '#e1b451'} strokeWidth="2" />
<circle cx={src.x} cy={src.y} r="5" fill={src.known ? '#66d4c5' : '#e1b451'} />
<text x={src.x} y={src.y + 31} fill="#a9e4dc" fontSize="12">{src.key}</text>
</g>
))}
{visible.map((n) => {
const active = a.selected === n.i && a.done
const color = n.record ? '#f18e84' : '#e3bc5b'
return (
<g key={'m' + n.i} className="network-node network-material" role="button" tabIndex={0}
aria-label={'查看 ' + n.m.name + ' 来源'}
style={{ cursor: 'pointer' }}
onClick={() => selectMaterialNetwork(n.i)}
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); selectMaterialNetwork(n.i) } }}>
<title>{n.m.name + ';来源:' + n.m.ref}</title>
<circle cx={n.x} cy={n.y} r="23" fill={color} opacity=".15" />
<circle cx={n.x} cy={n.y} r={active ? 16 : 12} fill={color} stroke={active ? '#fff' : color} strokeWidth="2" />
<text x={n.x} y={n.y + 34} fontSize="12" fill="#edf3ff">{n.m.name.length > 16 ? n.m.name.slice(0, 15) + '…' : n.m.name}</text>
<text x={n.x} y={n.y + 49} fontSize="10" fill="#92a9c9">{n.m.id}</text>
</g>
)
})}
<g textAnchor="start">
<circle cx="24" cy="477" r="4" fill="#8a79ff" /><text x="34" y="481" fill="#a8b8d5" fontSize="11">项目</text>
<circle cx="92" cy="477" r="4" fill="#66d4c5" /><text x="102" y="481" fill="#a8b8d5" fontSize="11">来源</text>
<circle cx="160" cy="477" r="4" fill="#f18e84" /><text x="170" y="481" fill="#a8b8d5" fontSize="11">{resource ? '匹配工序' : '匹配物料'}</text>
<circle cx="255" cy="477" r="4" fill="#e3bc5b" /><text x="265" y="481" fill="#a8b8d5" fontSize="11">待核验数据</text>
</g>
</g>
</svg>
)
}
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 (
<div className="material-network">
<div className="network-toolbar">
<div>
<b>✦ AI {resource ? '工艺资源' : '数据'}关联网络</b>
<small>{resource ? '项目 → 工艺依据 / 工时记录 → 工序资源 → 来源核对' : '项目 → 图纸 / 需求条款 → 物料 → 来源核对'}</small>
</div>
<Btn t="↻ 重播构建" onClick={replayKnowledgeNetwork} />
</div>
<div className="network-agents">
<span>01 索引检索 Agent</span><span>02 关系映射 Agent</span><span>03 来源校核 Agent</span>
</div>
<div className="network-canvas-wrap"><NetworkSvg /></div>
<div className="network-status" role="status">{status}</div>
<p className="network-boundary">
{resource
? '离线关联演示:依据当前工序、内置工艺记录与工时来源字段构建,未连接企业实际工艺库;未匹配记录显示为上传 / 人工数据。'
: '离线关联演示:图谱依据当前物料及内置来源字段构建;未匹配记录显示为上传 / 人工数据。'}
</p>
{n ? (
resource ? <ResourceNetworkDetail r={n.m as Resource} record={n.record} /> : <MaterialNetworkDetail m={n.m as Material} record={n.record} />
) : (
<Notice t={resource ? '暂无工艺资源记录。' : '暂无物料记录。'} />
)}
</div>
)
}
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 (
<>
<div className="kg-items">
{s.materials.map((r, i) => (
<Btn key={r.id + i} t={r.id} onClick={() => selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} />
))}
</div>
<div className="kg-detail network-detail">
<span className={'chip ' + (record ? 'purple' : 'amber')}>{record ? '本地示例记录匹配' : '未匹配内置记录 / 人工数据'}</span>
<h3>{m.id} · {m.name}</h3>
<p>来源关联:{ref}</p>
<Table head={['字段', '来源记录值', '当前清单值']} rows={[
['用量', record ? `${record.qty} ${record.unit}` : '未匹配', `${m.qty} ${m.unit}`],
['参考单价', record ? money(record.price) + ' 元' : '未匹配', money(m.price) + ' 元'],
['成本口径', '用量 × 单价', money(m.qty * m.price) + ' 元'],
]} />
{doc
? <a className="kg-link" href={doc} target="_blank" rel="noopener">打开来源文件 ↗</a>
: <Notice cls="warn" t="请技术人员补充原始依据,此条目不声称历史匹配。" />}
</div>
</>
)
}
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 (
<>
<div className="kg-items">
{s.resources.map((item, i) => (
<Btn key={item.id + i} t={item.id} onClick={() => selectMaterialNetwork(i)} cls={flows.materialNetwork.selected === i ? 'primary' : ''} />
))}
</div>
<div className="kg-detail network-detail">
<span className={'chip ' + (record ? 'purple' : 'amber')}>{record ? '本地工艺示例记录匹配' : '未匹配内置记录 / 人工数据'}</span>
<h3>{r.id} · {r.name}</h3>
<p>工时来源:{r.ref || '待补充'}</p>
<Table head={['字段', '来源记录值', '当前清单值']} rows={[
['计划工时', record ? record.qty + ' h' : '未匹配', r.qty + ' h'],
['综合费率', record ? money(record.rate) + ' 元/h' : '未匹配', hasRate ? money(r.rate!) + ' 元/h' : '待核价'],
['工序成本', record ? money(record.qty * record.rate) + ' 元' : '未匹配', hasRate ? money(r.qty * (r.rate || 0)) + ' 元' : '待核价'],
['工艺说明', record ? record.note || '待补充' : '未匹配', r.note || '待补充'],
]} />
<Notice cls="warn" t={record
? '来源为DEMO内置工艺与工时估算记录,未连接真实历史工单;工时与费率仍需生产部门复核。'
: '此工序为上传或人工补充记录,请补充工艺文件、工时定额及费率依据,不自动声称历史匹配。'} />
</div>
</>
)
}
// ============ 历史案例 ============
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 (
<div className="history-case-detail">
<Notice cls="warn" t="DEMO模拟案例:以下项目、客户、金额、工序与履约信息均为演示补充数据,并非真实合同或历史档案。仅供报价参考,不自动带入当前项目。" />
<h3>项目概况</h3>
<Table head={['字段', '案例信息']} rows={[
['案例编号 / 版本', c.code + ' / DEMO V1'],
['项目名称', c.name],
['客户', c.customer],
['案例时间', c.date],
['数量 / 交期', `${c.sets}套 / ${c.days}天`],
['记录来源', `本地内置案例记录 ${id};未连接企业历史项目库`],
]} />
<h3>供货范围与技术要求</h3>
<p>{c.scope}</p>
<p>{c.quality}</p>
<h3>物料与依据</h3>
<Table head={['物料', '规格', '数量口径', '依据(模拟)']} rows={c.materials} />
<h3>制造工艺与资源</h3>
<Table head={['工序', '计划工时 h', '综合费率 元/h', '成本 元']}
rows={c.process.map((r) => [r[0], r[1], money(r[2]), money(r[1] * r[2])])} />
<h3>成本与成交报价</h3>
<Table head={['项目', '金额 / 口径']} rows={[
...c.costs.map((r) => [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) + ' 元'],
]} />
<h3>交付计划与商务条件</h3>
<Table head={['里程碑', '计划周期']} rows={c.milestones} />
<p>{c.terms}</p>
<h3>报价参考与差异</h3>
<p>{c.reason}</p>
<p>{c.risk}</p>
<Table head={['比较项', '历史案例', '当前项目']} rows={[
['数量', c.sets + '套', s.project.sets + '套'],
['交期', c.days + '天', s.project.delivery + '天'],
['成本基准', money(total) + ' 元(模拟)', money(s.materials.reduce((a, m) => a + m.qty * m.price, 0) + s.resources.reduce((a, r) => a + r.qty * (r.rate || 0), 0)) + ' 元(当前清单,未含专项与间接费)'],
['利润率参考', c.margin + '%(模拟成交)', s.floor + '%(硬性底线)'],
]} />
<div className="actions section">
<Btn t={'查看 ' + (id === 'H01' ? 'H02' : 'H01') + ' 案例'}
onClick={() => openModal('case', '历史案例 ' + (id === 'H01' ? 'H02' : 'H01') + ' / 完整项目参考', id === 'H01' ? 'H02' : 'H01')} />
<Btn t="关闭" onClick={closeModal} cls="primary" />
</div>
</div>
)
}
// ============ 历史报价信息库 / 报价智能体 ============
function QuoteAgentProgress() {
const { flows } = useApp()
const a = flows.quoteAssistant
if (!a.mode) return null
const steps = a.mode === 'analysis'
? ['读取归档字段', '核算成本结构', '核对风险依据', '整理分析结论']
: ['理解查询条件', '检索本地记录', '核对项目字段', '逐项展示结果']
return (
<div className="quote-agent-progress">
<b>{a.running ? '● Agent 协同处理中' : a.cancelled ? '处理已停止' : a.mode === 'analysis' ? '分析已完成' : '检索已完成'}</b>
{steps.map((t, i) => (
<div key={i} className={i < a.stage ? 'done' : i === a.stage && a.running ? 'active' : ''}>
<span>{i < a.stage ? '✓' : '0' + (i + 1)}</span>{t}
</div>
))}
<small>展示检索与计算步骤,不代表外部模型实时调用。</small>
</div>
)
}
function QuoteAgentAnalysis() {
const { flows, library } = useApp()
const a = flows.quoteAssistant
void library
if (!a.analysis.length) {
return (
<div className="quote-analysis-idle">
<span>◈</span>
<div><b>选择一个项目,开启证据驱动的归因分析</b><p>逐项呈现成本结构、风险线索和待核验依据。</p></div>
</div>
)
}
const shown = a.analysis.slice(0, a.analysisCount)
const kindLabel: Record<string, string> = { fact: '可核算事实', attention: '需复核', hypothesis: '风险线索 / 非因果结论', action: '核验建议' }
return (
<section className="quote-analysis-panel">
<div className="quote-analysis-heading">
<div><small>PROJECT DIAGNOSTICS</small><h3>{a.analysisTitle}</h3></div>
<span className="chip purple">{a.running && a.mode === 'analysis' ? '正在构建分析' : '分析记录'}</span>
</div>
{!shown.length
? <div className="kb-empty">正在读取项目档案与成本字段…</div>
: shown.map((x, i) => (
<article key={i} className={'quote-analysis-card ' + x.kind}>
<span className="chip">{kindLabel[x.kind]}</span>
<h3>{x.title}</h3>
<p>{x.text}</p>
{x.bars && (
<div className="quote-cost-bars">
{x.bars.map((b, j) => (
<div key={j}>
<span>{b.name}</span>
<i><em style={{ width: b.share.toFixed(2) + '%' }} /></i>
<strong>{money(b.value)}</strong>
</div>
))}
</div>
)}
<div className="quote-evidence"><b>依据</b> {x.evidence}</div>
</article>
))}
</section>
)
}
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<HTMLDivElement>(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 (
<div className="quote-agent-workspace">
<aside className="quote-agent-sidebar">
<div className="quote-agent-brand">
<span>✦</span>
<div><b>历史报价智能助手</b><small>检索项目 · 核对依据 · 归因线索</small></div>
</div>
<div className="quote-agent-note">基于本机报价快照与内置示例分析。自然语言由本地规则解析,未连接外部大模型。</div>
<div className="quote-agent-messages" ref={messagesRef}>
{messages.map((m, i) => (
<div className={'quote-agent-bubble ' + m.role} key={i}>
<small>{m.role === 'user' ? '你的需求' : '✦ 报价智能助手'}</small>
<p>{m.text}</p>
</div>
))}
</div>
<QuoteAgentProgress />
<div className="quote-agent-prompts">
{['查找2025年的导向套项目', '查找交期90天以内的项目', '查找不含税报价20万元以下的项目'].map((t, i) => (
<Btn key={i} t={t} onClick={() => { setInput(t); useQuoteAgentPrompt(i) }} />
))}
</div>
<label className="quote-agent-input-label" htmlFor="qAgentInput">用自然语言查找或分析项目</label>
<textarea id="qAgentInput" rows={3} maxLength={600} value={input}
placeholder="例如:查找内外套项目;分析 H01 的成本与历史风险"
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => { if (e.key === 'Enter' && !e.shiftKey && !(e as any).isComposing) { e.preventDefault(); runQuoteAgentQuery(input); setInput('') } }} />
<div className="actions quote-agent-send">
<Btn t="✦ 发送并检索" onClick={() => { runQuoteAgentQuery(input); setInput('') }} cls="primary" />
<Btn t="分析选中项目" onClick={() => analyzeSelectedQuotation()} />
</div>
</aside>
<section className="quote-agent-main">
<div className="quote-agent-heading">
<div>
<div className="eyebrow">QUOTATION INTELLIGENCE</div>
<h2>历史项目与报价证据</h2>
<p>先定位项目,再核对成本与风险依据。</p>
</div>
<Btn t="查看全部" onClick={showAllAgentQuotes} />
</div>
<details className="quote-agent-filters">
<summary>精确筛选 · 项目 / 客户 / 编号 / 日期</summary>
<div className="quotation-search">
{([['project', '项目名称', 'text'], ['customer', '客户名称', 'text'], ['number', '报价编号', 'text'], ['from', '开始日期', 'date'], ['to', '结束日期', 'date']] as const).map(([key, label, type]) => (
<label key={key}>{label}
<input type={type} value={filters[key]} onChange={(e) => setFilters((f) => ({ ...f, [key]: e.target.value.trim() }))} />
</label>
))}
</div>
</details>
<div className="quote-result-heading">
<b>项目匹配结果 <span>{shown.length}</span></b>
<small>本机快照 {library.length} 条 · 示例 2 条</small>
</div>
{filters.from && filters.to && filters.from > filters.to
? <Notice cls="warn" t="开始日期不得晚于结束日期。" />
: shown.length ? (
<div className="quote-project-grid">
{shown.map((r: any) => (
<article className={'quote-project-card ' + (a.selected === r.id ? 'is-selected' : '')} key={r.id}>
<div className="quote-project-top">
<span className={'chip ' + (r.kind === 'saved' ? 'purple' : '')}>{r.kind === 'saved' ? '本机归档快照' : 'DEMO参考案例'}</span>
<small>{r.date}</small>
</div>
<h3>{r.project}</h3>
<p>{r.customer}</p>
<small className="muted">{r.number} · {r.sets}套 · {r.days}天</small>
<div className="quote-project-price"><strong>¥ {money(r.price)}</strong><span>不含税总价</span></div>
<div className="actions">
<Btn t={a.selected === r.id ? '✓ 已选中' : '选择项目'} onClick={() => selectAgentQuotation(r.id)} cls={a.selected === r.id ? 'primary' : ''} />
<Btn t="归因分析" onClick={() => analyzeSelectedQuotation(r.id)} />
<Btn t="完整档案" onClick={() => openHistoryDetail(r.id)} />
</div>
</article>
))}
</div>
) : a.running && a.mode === 'search' ? (
<div className="quote-search-empty">
<span className="quote-agent-orbit">✦</span>
<b>AI 正在检索报价记录</b>
<p>匹配结果将逐项展示…</p>
</div>
) : (
<div className="kb-empty">未找到符合条件的报价,请调整自然语言或筛选条件。</div>
)}
<QuoteAgentAnalysis />
</section>
</div>
)
function openHistoryDetail(id: string) {
const r = library.find((x) => x.id === id)
if (!r) {
if (HISTORY_CASES[id]) openModal('case', '历史案例 ' + id + ' / 完整项目参考', id)
return
}
openModal('historyDetail', '历史报价详情 / ' + r.number, id)
}
}
function QuotationHistoryDetail({ id }: { id: string }) {
const { library, openModal } = useApp()
const r = library.find((x) => x.id === id)
if (!r) return null
const snap = r.snapshot
const material = snap.materials.reduce((sum, m) => sum + m.qty * m.price, 0)
const process = snap.resources.reduce((sum, x) => sum + x.qty * (x.rate || 0), 0)
return (
<div className="quotation-history-detail">
<div className="actions"><Btn t="← 返回历史报价信息库" onClick={() => openModal('library', '历史报价信息库 / AI智能体工作台')} /></div>
<Notice t={'归档快照:' + esc(r.date) + '入库 · V' + esc(r.revision) + ' · 此处数据固定为入库时内容,不随当前项目修改。'} />
<Table head={['归档字段', '信息']} rows={[
['项目', snap.project.project],
['客户', snap.project.customer],
['报价编号', r.number],
['数量 / 交期', `${r.sets}套 / ${r.days}天`],
['批准策略', r.strategy],
['批准时间', r.approvedAt || ''],
['不含税 / 含税总额', `${money(r.price)} 元 / ${money(r.total)} 元`],
['税率', r.tax + '%'],
['供货范围', snap.project.scope],
['商务条件', snap.project.terms],
['项目补充说明', snap.context],
...(snap.competitorQuote ? [
['友商报价参考', `${snap.competitorQuote.name || '友商'} / ${money(snap.competitorQuote.price)} 元(${snap.competitorQuote.taxMode === 'inclusive' ? '含税' : '不含税'})`],
['友商数量 / 交期', `${snap.competitorQuote.sets}套 / ${snap.competitorQuote.days}天`],
['友商信息来源', snap.competitorQuote.source || '未填写'],
] : []),
]} />
<h3 className="section">入库报价单原件</h3>
<div dangerouslySetInnerHTML={{ __html: r.html }} />
<h3 className="section">内部物料依据</h3>
<Table head={['物料号', '物料', '用量', '单价', '金额', '来源']}
rows={snap.materials.map((m) => [m.id, m.name, `${m.qty} ${m.unit}`, money(m.price), money(m.qty * m.price), m.ref])} />
<h3 className="section">内部工艺资源</h3>
<Table head={['工序', '工时', '费率', '金额', '来源']}
rows={snap.resources.map((x) => [x.name, x.qty, money(x.rate || 0), money(x.qty * (x.rate || 0)), x.ref])} />
<p>物料合计:{money(material)} 元;工艺资源合计:{money(process)} 元。</p>
<Table head={['补充成本 / 参数', '归档值']} rows={[
...Object.entries(snap.other).map(([k, v]) => [k, money(v) + ' 元']),
['间接费率', snap.overhead + '%'],
['风险准备', snap.risk + '%'],
['利润底线', snap.floor + '%'],
]} />
<div className="actions section">
<Btn t="返回历史报价信息库" onClick={() => openModal('library', '历史报价信息库 / AI智能体工作台')} />
</div>
</div>
)
}
// ============ 简单表单弹窗 ============
function NewMaterialModal() {
const { submitMaterial, closeModal } = useApp()
const [name, setName] = useState('人工补充物料')
const [qty, setQty] = useState('1')
const [unit, setUnit] = useState('件')
const [price, setPrice] = useState('100')
return (
<>
<label>名称 <input value={name} onChange={(e) => setName(e.target.value)} /></label>
<div className="formrow">
数量 <input type="number" value={qty} onChange={(e) => setQty(e.target.value)} />
单位 <input value={unit} onChange={(e) => setUnit(e.target.value)} />
单价 <input type="number" value={price} onChange={(e) => setPrice(e.target.value)} />
</div>
<div className="actions">
<button className="primary" onClick={() => submitMaterial({ name, unit, qty, price })}>保存并纳入成本</button>
<Btn t="取消" onClick={closeModal} />
</div>
</>
)
}
function NewResourceModal() {
const { submitResource, closeModal } = useApp()
const [name, setName] = useState('')
const [ref, setRef] = useState('')
const [qty, setQty] = useState('1')
const [note, setNote] = useState('')
return (
<div className="resource-form">
<label>工序名称 <input maxLength={100} placeholder="例如:表面处理" value={name} onChange={(e) => setName(e.target.value)} /></label>
<label>工时来源 <input maxLength={240} placeholder="例如:技术人工估算 / 工艺文件编号" value={ref} onChange={(e) => setRef(e.target.value)} /></label>
<label>计划工时(h) <input type="number" min="0.01" step="0.01" value={qty} onChange={(e) => setQty(e.target.value)} /></label>
<label>工序说明(选填) <input maxLength={240} placeholder="填写工序范围或补充说明" value={note} onChange={(e) => setNote(e.target.value)} /></label>
<div className="actions">
<Btn t="保存工序" onClick={() => submitResource({ name, ref, qty, note })} cls="primary" />
<Btn t="取消" onClick={closeModal} />
</div>
</div>
)
}
function PreviewModal({ payload }: { payload: { url: string; name: string; pdf: boolean } }) {
return payload.pdf
? <iframe title="PDF预览" src={payload.url} width="100%" height="520" />
: <img alt="上传图纸" src={payload.url} style={{ maxWidth: '100%' }} />
}
// ============ 弹窗宿主 ============
export function ModalHost() {
const { modal, closeModal } = useApp()
const dlg = useRef<HTMLDialogElement>(null)
useEffect(() => {
const el = dlg.current
if (!el) return
if (modal.open && !el.open) el.showModal()
if (!modal.open && el.open) el.close()
}, [modal.open])
const cls = modal.kind === 'library' ? 'quote-agent-dialog quotation-library-dialog'
: modal.kind === 'network' ? 'material-network-dialog' : ''
return (
<dialog ref={dlg} id="modal" className={cls} onClose={closeModal}>
<div className="modal-head">
<b>{modal.title}</b>
<button onClick={closeModal}>关闭</button>
</div>
<div id="modalBody">
{modal.kind === 'guide' && (
<ol>
<li>需求解析:载入样例 → 解析 → 确认澄清(1分钟)。</li>
<li>清单:追溯来源 → 补入焊材 → 确认技术(1.5分钟)。</li>
<li>询价:尝试低价超期供应商 → 合规选择 → 物供提交 → 生产提交 → 经营确认(2分钟)。</li>
<li>成本:核对材料、工时、间接费与风险准备 → 生成报告(1分钟)。</li>
<li>策略:比较A/B/C → 演示低于底线的阻断 → 选择B → 审批(1.5分钟)。</li>
<li>报价:打印/导出 → 返回修改工时,演示审批失效(1分钟)。</li>
</ol>
)}
{modal.kind === 'network' && <MaterialNetworkModal />}
{modal.kind === 'library' && <QuotationLibraryModal />}
{modal.kind === 'case' && <HistoricalCaseModal id={modal.payload} />}
{modal.kind === 'historyDetail' && <QuotationHistoryDetail id={modal.payload} />}
{modal.kind === 'newMaterial' && <NewMaterialModal />}
{modal.kind === 'newResource' && <NewResourceModal />}
{modal.kind === 'preview' && <PreviewModal payload={modal.payload} />}
</div>
</dialog>
)
}