import { useMemo, useState } from 'react' import { Star, ExternalLink, Trash2, ChevronDown, ChevronRight, Sparkles, Plus, X, Link2, Tag, FileUp } from 'lucide-react' import { motion, AnimatePresence } from 'framer-motion' import type { AiPanelState, Project, WatchStatus } from '../types' import { RESULT_STATUSES } from '../types' import { useStore, isHistoryStatus, uid, nowStr } from '../lib/store' import Pill from '../components/ui-ext/Pill' import { GhostButton, PrimaryButton } from '../components/ui-ext/AiButton' import { cn } from '@/lib/utils' export function WatchPage({ onOpenPanel }: { onOpenPanel: (s: AiPanelState) => void }) { const { watch, setWatchStatus, setWatchNote, removeWatch, customTags, addCustomTag, removeCustomTag, toggleWatchTag, addCustomProject, findProject, } = useStore() const [tab, setTab] = useState<'active' | 'result' | 'skipped'>('active') const [confirmRemove, setConfirmRemove] = useState(null) const [openHistory, setOpenHistory] = useState(null) const [tagFilter, setTagFilter] = useState(null) const [tagEditorFor, setTagEditorFor] = useState(null) const [newTag, setNewTag] = useState('') const [showAddLink, setShowAddLink] = useState(false) const [linkForm, setLinkForm] = useState({ url: '', name: '', purchaser: '', region: '', budget: '' }) const [linkFile, setLinkFile] = useState('') const [linkError, setLinkError] = useState('') // 状态变更弹窗:避免一排按钮诱导频繁点击,历史记录保持干净;备注随状态一起设置 const [statusModalFor, setStatusModalFor] = useState(null) const [pendingStatus, setPendingStatus] = useState('已关注') const [pendingNote, setPendingNote] = useState('') const active = useMemo(() => watch.filter(w => !isHistoryStatus(w.status)), [watch]) const result = useMemo(() => watch.filter(w => (RESULT_STATUSES as string[]).includes(w.status)), [watch]) const skipped = useMemo(() => watch.filter(w => w.status === '暂不考虑'), [watch]) const list = (tab === 'active' ? active : tab === 'result' ? result : skipped).filter(w => !tagFilter || w.tags.includes(tagFilter)) const submitLink = () => { const url = linkForm.url.trim() const name = linkForm.name.trim() if (!url && !linkFile) { setLinkError('请填写公告网址或上传公告文件'); return } if (url && !/^https?:\/\//i.test(url)) { setLinkError('网址需以 http:// 或 https:// 开头'); return } if (!name) { setLinkError('请填写项目名称'); return } const budgetNum = linkForm.budget.trim() === '' ? null : Number(linkForm.budget) if (linkForm.budget.trim() !== '' && (Number.isNaN(budgetNum) || (budgetNum as number) < 0)) { setLinkError('预算需为数字(万元)'); return } const p: Project = { id: uid('custom'), name, region: linkForm.region.trim() || '未填写', keywords: [], budget: budgetNum, publishDate: nowStr().slice(0, 10), regDeadline: null, bidDeadline: null, purchaser: linkForm.purchaser.trim() || '待确认(详见公告原文)', noticeType: '手动添加', sourceName: linkFile ? '上传公告文件' : '手动添加链接', sourceUrl: url || null, summary: '手动添加的项目,可通过「向AI提问」进一步了解。', detail: `该项目由用户手动添加。\n${url ? `公告链接:${url}\n` : ''}${linkFile ? `公告文件:${linkFile}\n` : ''}地区、预算与截止时间等信息以公告原文为准。`, requirements: [], } addCustomProject(p) setShowAddLink(false) setLinkForm({ url: '', name: '', purchaser: '', region: '', budget: '' }) setLinkFile('') setLinkError('') } return (

重点关注

{ setLinkForm({ url: '', name: '', purchaser: '', region: '', budget: '' }) setLinkFile('') setLinkError('') setShowAddLink(true) }} className="!px-3 !py-1.5 text-xs"> 添加项目
{/* 页签:胶囊切换(跟进中 / 已有结果 / 暂不考虑) */}
{/* 自定义标签筛选:在卡片上给项目打标签后可按标签分类查看 */} {customTags.length > 0 && (
{customTags.map(t => ( ))} {tagFilter && 筛选中:{tagFilter}(再点一次取消)}
)} {list.length === 0 ? (

{tab === 'active' ? '暂无跟进中的项目。在「发现商机」检索结果中点击 ☆ 加入重点关注。' : tab === 'result' ? '暂无已有结果的项目。中标 / 未中标 / 流标的项目会保留在这里。' : '暂无暂不考虑的项目。我方主动放弃跟进的项目会保留在这里,可随时转回跟进。'}

) : (
    {list.map(w => { const p = findProject(w.projectId) if (!p) return null return (
  • {p.name} {p.region} {p.budget === null ? '预算未披露' : {p.budget.toLocaleString()} 万元}
    发布 {p.publishDate} · 报名截止 {p.regDeadline ?? '未披露'} {/* 自定义标签:跟在报名截止右侧,不单独占行 */} {w.tags.map(t => ( {t} ))} {tagEditorFor === w.projectId && (
    选择或新建标签
    {customTags.length === 0 && 还没有标签,先在下方新建一个} {customTags.map(t => { const on = w.tags.includes(t) return ( ) })}
    setNewTag(e.target.value)} onKeyDown={e => { if (e.key === 'Enter' && newTag.trim()) { addCustomTag(newTag.trim()) if (!w.tags.includes(newTag.trim())) toggleWatchTag(w.projectId, newTag.trim()) setNewTag('') } }} placeholder="新标签名,回车创建" className="w-full rounded-ctrl border border-line-soft px-2 py-1 text-[12px] outline-none placeholder:text-ink-400 focus:border-brand-500/60" />
    )}
    {p.summary}
    {p.sourceUrl && ( 公告原文 )}
    {/* 状态:通过弹窗单独设置,避免误点与频繁变更历史 */}
    当前状态:
    {/* 备注:填写过才展示;填写与修改统一在「变更状态」弹窗里进行 */} {w.note && (
    {w.note}
    )}
    {openHistory === w.projectId && (
      {[...w.history].reverse().map((h, i) => (
    • {h.status} · {h.time} {h.note &&
      当时备注:{h.note}
      }
    • ))}
    )}
  • ) })}
)} {confirmRemove && ( { if (e.target === e.currentTarget) setConfirmRemove(null) }}>
!

取消关注这个项目?

将移除该项目的状态、备注与全部历史。
暂时不跟进,可改设为「暂不考虑」。

setConfirmRemove(null)}>再想想 { removeWatch(confirmRemove); setConfirmRemove(null) }} className="!bg-bad-500 hover:!bg-bad-500/90 !shadow-[0_2px_8px_rgba(244,63,94,.25)]">确认取消关注
)}
{showAddLink && ( { if (e.target === e.currentTarget) setShowAddLink(false) }}>

添加项目

粘贴公告网址,或直接上传公告文件(PDF / Word / 图片)。
AI 会提取项目信息,加入后即可提问、跟进与打标签。

{ setLinkForm(f => ({ ...f, url: e.target.value })); setLinkError('') }} placeholder="https://…" className="mt-1 w-full rounded-ctrl border border-line-soft px-3 py-2 text-[13px] outline-none placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10" />
{linkFile ? (
{linkFile}
) : ( )}
{ setLinkForm(f => ({ ...f, name: e.target.value })); setLinkError('') }} placeholder="按公告标题填写" className="mt-1 w-full rounded-ctrl border border-line-soft px-3 py-2 text-[13px] outline-none placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10" />
setLinkForm(f => ({ ...f, purchaser: e.target.value }))} placeholder="选填" className="mt-1 w-full rounded-ctrl border border-line-soft px-3 py-2 text-[13px] outline-none placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10" />
setLinkForm(f => ({ ...f, region: e.target.value }))} placeholder="选填" className="mt-1 w-full rounded-ctrl border border-line-soft px-3 py-2 text-[13px] outline-none placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10" />
{ setLinkForm(f => ({ ...f, budget: e.target.value })); setLinkError('') }} placeholder="选填" className="mt-1 w-full rounded-ctrl border border-line-soft px-3 py-2 text-[13px] font-num outline-none placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10" />
{linkError &&
{linkError}
}
setShowAddLink(false)}>取消 添加并关注
)}
{/* 状态变更弹窗 */} {statusModalFor && ( { if (e.target === e.currentTarget) setStatusModalFor(null) }}>

变更跟进状态

选择新状态后可顺手更新备注,变更与备注会一起记入状态历史。

{([ ['跟进中', ['已关注', '准备投标', '已报名', '已提交投标文件']], ['已有结果', ['已中标', '未中标', '已流标']], ['我方决定', ['暂不考虑']], ] as const).map(([group, statuses]) => (
{group}
{statuses.map(s => ( ))}
))}