import type { WatchStatus, StatusChange } from '../types' /** 后端权威契约:万元与缺失值保持原样;浏览器不重新计算匹配分或收费。 */ export interface SearchQuery { keywords: string[] beginDate: string endDate: string stages: number[] preference: 'COMPREHENSIVE' | 'REGION' | 'BUSINESS' | 'AMOUNT' preferredRegions: string[] budgetMinWan: number | null budgetMaxWan: number | null mode: 'SEARCH' | 'LEADS' | 'MARKET' keywordMode: 'ANY' | 'ALL' hardRegions: string[] hardMinWan: number | null hardMaxWan: number | null } export interface Candidate { id: string; sourceId: string; title: string; purchaser: string; region: string budgetWan: number | null; publishDate: string; stage: number | null; url: string | null userFileId?: string | null; products: string[]; evidenceId: string | null; gaps: string[] } export interface RankedItem { facts: Candidate; relevance: number; preferenceBonus: number; reasoning: string[] analysis: null | { projectNumber: string summary: { construction: string; region: string; schedule: string[]; qualifications: string[]; gaps: string[]; evidenceId: string; locator: string; method: string } match: { score: number | null; completeness: number; profileVersion: number; version: string; limitation: string weights: Record; dimensions: Record } } } export interface SearchReport { conditions: SearchQuery; rankingVersion: string scope: { platformTotal: number | null; fetchedCount: number; uniqueCount: number; displayCount: number; pagesRead: number; stopReason: string; complete: boolean } stageChains: { projectNumber: string; purchaser: string; notices: Candidate[]; basis: string }[] items: RankedItem[]; limitations: string[]; referencesVerified: boolean summaryProgress: { completed: number; total: number; method: string } market?: { basis: string; buyers: Record; suppliers: Record; monthlyNotices: Record; platformAggregations: { tool: string; evidenceId: string; scope: string; rows: { name: string; count: number | null; amountWan: number | null; url: string | null }[] }[] } } export interface SearchHistory { id: string; status: string; createdAt: string; schemeId: string | null; schemeName: string | null; schemeVersion: number | null } export interface SearchScheme { id: string; name: string; conditions: SearchQuery; version: number } export interface WatchItem { fileId?: string | null; summary?: NonNullable['summary'] projectId: string; status: WatchStatus; note: string; version: number; tags: string[] createdAt: string; history: StatusChange[]; group: string; project: Candidate } export interface Tag { id: string; name: string } export const inputClass = 'w-full rounded-ctrl border border-line-soft bg-white px-3 py-2 text-sm outline-none focus:border-brand-500' export const stageNames: Record = { 1: '采购意向', 2: '预招标', 4: '招标', 5: '更正', 6: '终止', 7: '中标', 8: '合同', 9: '其他', 10: '其他' } export const preferenceNames = { COMPREHENSIVE: '综合推荐', REGION: '地域优先', BUSINESS: '业务优先', AMOUNT: '金额优先' } /** 时间快捷选项统一使用北京时间,避免午夜时浏览器时区改变查询日期。 */ export function beijingDate(offset = 0) { return new Date(Date.now() + (8 * 60 * 60 * 1000) - offset * 86400000).toISOString().slice(0, 10) } export function initialQuery(): SearchQuery { return { keywords: [], beginDate: beijingDate(89), endDate: beijingDate(), stages: [1, 2, 4, 7, 8], preference: 'COMPREHENSIVE', preferredRegions: [], budgetMinWan: null, budgetMaxWan: null, mode: 'LEADS', keywordMode: 'ANY', hardRegions: [], hardMinWan: null, hardMaxWan: null } } export function words(value: string) { return value.split(/[、,,;;\n]+/).map(s => s.trim()).filter(Boolean) } export function message(error: unknown) { return error instanceof Error ? error.message : '请求失败,请重试' } export function time(value: string) { return new Date(value).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false }) } /** 仅格式化原文明确写出的报名截止日期;不拿投标日期代替,也不把无效日期自动顺延。 */ export function registrationDate(schedule: string[] = []): string | null { const match = schedule.join(';').match(/报名(?:时间)?(?:截止|截至)(?:时间)?\s*[::]?\s*(\d{4})[-年/.](\d{1,2})[-月/.](\d{1,2})/) if (!match) return null const value = `${match[1]}-${match[2].padStart(2, '0')}-${match[3].padStart(2, '0')}` const date = new Date(`${value}T00:00:00Z`) return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value ? value : null }