import React, { useState, useEffect, useMemo } from 'react' import axios from 'axios' /** * PI 合同管理(Proforma Invoice) * 数据来源:happy 后端 /api/pi-contracts(P1 后端合并阶段开放) */ function PiContractManagement() { const [contracts, setContracts] = useState([]) const [loading, setLoading] = useState(true) const [keyword, setKeyword] = useState('') useEffect(() => { let alive = true axios.get('/api/pi-contracts') .then(res => { if (alive) setContracts(Array.isArray(res.data) ? res.data : res.data?.items || []) }) .catch(() => { if (alive) setContracts([]) }) .finally(() => { if (alive) setLoading(false) }) return () => { alive = false } }, []) const rows = useMemo(() => { const kw = keyword.trim().toLowerCase() if (!kw) return contracts return contracts.filter(c => [c.pi_no, c.customer_name, c.customer_company].filter(Boolean).join(' ').toLowerCase().includes(kw)) }, [contracts, keyword]) const statusText = (s) => ({ draft: '草稿', signed: '已签署', deposited: '已收定金', producing: '生产中', shipped: '已出运', closed: '已结案' }[s] || s || '—') return (

PI 合同管理

setKeyword(e.target.value)} />
{rows.length} 条
{loading ? ( ) : rows.length === 0 ? ( ) : ( rows.map(c => ( )) )}
PI 编号 客户 签订日期 金额 收款条件 状态 操作
加载中...
暂无 PI 合同
PI 合同接口待接入(P1 后端合并阶段开放)
{c.pi_no} {c.customer_name || c.customer_company || '—'} {c.signed_date ? new Date(c.signed_date).toLocaleDateString('zh-CN') : '—'} {c.total_amount ? `${c.currency || 'USD'} ${Number(c.total_amount).toFixed(2)}` : '—'} {c.payment_terms || '—'} {statusText(c.status)}
) } export default PiContractManagement