import { useState, useEffect } from 'react' import { useSearchParams } from 'react-router-dom' import { PenTool, Check, AlertCircle } from 'lucide-react' import api from '../../lib/api' import Card from '../../components/ui/Card' import Button from '../../components/ui/Button' // 金额格式化:保留两位小数 + 千分位 const fmt = (n: number) => (n || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) export default function ContractConfirm() { const [params] = useSearchParams() const token = params.get('token') || '' const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState('') const [agreed, setAgreed] = useState(false) const [submitting, setSubmitting] = useState(false) const [confirmed, setConfirmed] = useState(false) const [verifyCode, setVerifyCode] = useState('') const [sendingCode, setSendingCode] = useState(false) const [codeSent, setCodeSent] = useState(false) const [devCode, setDevCode] = useState('') useEffect(() => { if (token) { api.get(`/portal/contract-confirm/${token}`).then((res: any) => { setData(res.data) }).catch((err: any) => { setError(err.response?.data?.error?.message || '链接无效或已过期') }).finally(() => setLoading(false)) } else { setError('缺少 token 参数') setLoading(false) } }, [token]) const handleSendCode = async () => { setSendingCode(true) setError('') try { const res = await api.post('/portal/contract-confirm/send-code', { token }) as any setCodeSent(true) setDevCode(res.data?.data?.code || '') } catch (err: any) { setError(err.response?.data?.error?.message || '验证码发送失败') } finally { setSendingCode(false) } } const handleConfirm = async () => { setSubmitting(true) try { await api.post('/portal/contract-confirm', { token, agreed: true, verifyCode }) setConfirmed(true) } catch (err: any) { setError(err.response?.data?.error?.message || '确认失败') } finally { setSubmitting(false) } } if (confirmed) { return (

合同签署确认成功

已记录您的签署确认时间和 IP 地址。

) } return (

合同签署确认

{loading ? (
加载中...
) : error ? (
{error}
) : data ? (
{data.orgName} 与 {data.employeeName} 的劳动合同
{data.contract && (
{data.contract.contractYears > 0 && } {data.contract.endDate && } {data.contract.probationMonths > 0 && } {data.contract.probationSalary > 0 && }
)} {/* 验证码区域 */} {agreed && (
setVerifyCode(e.target.value)} placeholder="请输入6位验证码" maxLength={6} className="flex-1 px-3 py-2 rounded-md border border-gray-300 text-sm" />
{devCode && (
开发模式验证码:{devCode}
)}
)}
📌 确认后将记录签署时间、IP 地址和设备信息
) : null}
) } function Row({ label, value }: { label: string; value: string }) { return (
{label} {value}
) }