import { useState } from 'react' import { ChevronLeft, ChevronRight, ExternalLink, Sparkles, Star, Tag } from 'lucide-react' import * as Popover from '@radix-ui/react-popover' import type { RankedItem } from '../lib/day2' import { message, registrationReminder } from '../lib/day2' import { useStore } from '../lib/store' import { defaultMatchDimNames } from '../types' import type { AnalysisPanelState } from './AiPanel' import { ProjectTags } from './ProjectTags' import { PrototypeDialog } from './PrototypeDialog' import { GhostButton } from './ui-ext/AiButton' const PAGE_SIZE = 8 /** 原型七列表格,所有分数、节奏与门槛均读取已保存摘要,缺字段不在浏览器猜测。 */ export function OpportunityTable({ items, batchId, onOpenPanel }: { items: RankedItem[]; batchId: string; onOpenPanel: (state: AnalysisPanelState) => void }) { const { addWatch, removeWatch, isWatched } = useStore() const [scoreProject, setScoreProject] = useState(null) const [page, setPage] = useState(1), [error, setError] = useState('') const [tagProject, setTagProject] = useState(null), [saving, setSaving] = useState(false) const totalPages = Math.max(1, Math.ceil(items.length / PAGE_SIZE)), current = Math.min(page, totalPages) const rows = items.slice((current - 1) * PAGE_SIZE, current * PAGE_SIZE) const open = (item: RankedItem) => onOpenPanel({ kind: 'project', project: item.facts, item, batchId }) const follow = async (id: string) => { if (saving) return setSaving(true); setError('') try { // 关注已落库才打开标签窗口,窗口独立于星标和表格滚动容器。 if (isWatched(id)) { await removeWatch(id); setTagProject(null) } else { await addWatch(id); setTagProject(id) } } catch (e) { setError(message(e)) } finally { setSaving(false) } } return <> {error &&

{error}

}
{[27, 13, 9, 16, 16, 6, 13].map((width, i) => )}{['项目与建设内容', '招标方与地域', '预算', '时间节奏', '参与门槛', '匹配度', '操作'].map((name, i) => )}{rows.map(item => { const p = item.facts, summary = item.analysis?.summary, match = item.analysis?.match const reminder = registrationReminder(summary?.schedule) const construction = summary?.conclusion?.construction || summary?.construction || p.products.join('、') || (p.title ? `标题线索 · ${p.title}` : '项目建设内容待核验') const qualifications = summary?.qualifications ?? [] // 同一行尽量兼顾资质与业绩,不让多个同类条款把另一项挤出列表。 const requirements = [...new Set([qualifications.find(line => /资质|资格|许可证|认证|承包/.test(line)), qualifications.find(line => line.includes('业绩'))].filter(Boolean))] const timing = summary?.conclusion?.timing || summary?.schedule.find(line => /工期|交付|服务期|开标|投标截止/.test(line)) const watched = isWatched(p.id) return open(item)} className="cursor-pointer border-b border-line-soft/70 align-top transition-colors last:border-0 hover:bg-brand-50/40"> })}
{name}
{ e.stopPropagation(); if (!p.url) open(item) }} className="inline-flex items-start gap-1 font-medium leading-snug text-ink-900 hover:text-brand-500 hover:underline">{p.title || '标题待核验'}{p.url && }

建设内容 · {construction}

{p.purchaser || '待核验'}
地域 · {summary?.conclusion?.region || summary?.region || p.region || '项目地域待核验'}
{p.budgetWan == null ? 未披露 : {p.budgetWan.toLocaleString()} 万元}

= 0 && reminder.days <= 7 ? 'text-bad-500' : 'text-ink-600'}`}>{reminder?.label ?? '报名截止时间待核验'}

{reminder && }{timing &&

{timing}

}

发布 {p.publishDate || '未知'}

{summary?.conclusion?.participation || ((requirements.length ? requirements : qualifications).slice(0, 2).map((line, i) =>

{line}

))}{!summary?.conclusion?.participation && !qualifications.length && '请核对公告中的资格和业绩要求'}
setScoreProject(value ? p.id : null)}> e.stopPropagation()} sideOffset={8} className="z-50 w-72 rounded-card border border-line-soft bg-white p-3 shadow-card-hover">

贴合度打分构成

{match ? <>
    {Object.entries(match.dimensions).map(([key, dim]) =>
  • {defaultMatchDimNames[key as keyof typeof defaultMatchDimNames] ?? key} · 权重 {match.weights[key]}%{dim.known ? `${dim.score} 分` : '待核验'}

    {dim.basis}

  • )}

完整性 {match.completeness}% · 档案 v{match.profileVersion} · {match.limitation}

:

尚无已保存评分,请完善公司档案后重新检索。

}
{watched && }
{tagProject && setTagProject(null)} className="w-auto">
setTagProject(null)} />
} {!items.length &&
} {!!items.length &&
第 {(current - 1) * PAGE_SIZE + 1}–{Math.min(current * PAGE_SIZE, items.length)} 条,共 {items.length} 条 setPage(current - 1)} className="!px-2.5 !py-1 text-xs"> 上一页第 {current} / {totalPages} 页= totalPages} onClick={() => setPage(current + 1)} className="!px-2.5 !py-1 text-xs">下一页
} } function SearchEmpty() { return <>

没有符合条件的项目

可调整关键词、地区、预算或发布时间范围后重新检索

}