version 0.1
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { CheckCircle, X, Edit3, Brain, Search, Filter } from 'lucide-react';
|
||||
import { getTransactions, updateTransaction, formatAmount, formatDate, SOURCE_TYPE_MAP, getCategories } from '../hooks/useApi';
|
||||
|
||||
export default function Review() {
|
||||
const [transactions, setTransactions] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [categories, setCategories] = useState([]);
|
||||
const [editingTx, setEditingTx] = useState(null);
|
||||
const [showReviewed, setShowReviewed] = useState(false);
|
||||
const [keyword, setKeyword] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
loadCategories();
|
||||
loadReviewTransactions();
|
||||
}, [showReviewed, keyword]);
|
||||
|
||||
async function loadCategories() {
|
||||
try {
|
||||
const cats = await getCategories();
|
||||
setCategories(cats);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function loadReviewTransactions() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = {
|
||||
min_amount: 100, // Only >= 100 RMB
|
||||
limit: 200,
|
||||
sort_by: 'amount',
|
||||
sort_order: 'DESC'
|
||||
};
|
||||
if (!showReviewed) params.reviewed = 0;
|
||||
if (keyword) params.keyword = keyword;
|
||||
|
||||
const result = await getTransactions(params);
|
||||
setTransactions(result.transactions);
|
||||
setTotal(result.total);
|
||||
|
||||
// Update badge count in sidebar
|
||||
try {
|
||||
const badge = document.getElementById('review-badge');
|
||||
if (badge) {
|
||||
// Get fresh unreviewed count
|
||||
const { getOverview } = require('../hooks/useApi');
|
||||
// Just use local count
|
||||
if (!showReviewed) badge.textContent = result.total;
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (err) {}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
async function handleConfirm(tx) {
|
||||
try {
|
||||
await updateTransaction(tx.id, { reviewed: 1 });
|
||||
loadReviewTransactions();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleUpdateTx(id, updates) {
|
||||
try {
|
||||
await updateTransaction(id, updates);
|
||||
setEditingTx(null);
|
||||
loadReviewTransactions();
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
async function handleConfirmAll() {
|
||||
if (!window.confirm(`确定要批量确认当前显示的 ${transactions.length} 笔交易吗?`)) return;
|
||||
for (const tx of transactions) {
|
||||
if (!tx.reviewed) {
|
||||
try { await updateTransaction(tx.id, { reviewed: 1 }); } catch (err) {}
|
||||
}
|
||||
}
|
||||
loadReviewTransactions();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="page-header">
|
||||
<h2>🔍 大额交易确认</h2>
|
||||
<p>逐笔确认 ≥100 元的交易,核对AI分类和描述是否正确</p>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<div style={{ display: 'flex', gap: 10, marginBottom: 20, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||
<div className="form-group" style={{ marginBottom: 0, minWidth: 200 }}>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="🔍 搜索对方/描述..."
|
||||
value={keyword}
|
||||
onChange={e => setKeyword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer', fontSize: 14 }}>
|
||||
<input type="checkbox" checked={showReviewed} onChange={e => setShowReviewed(e.target.checked)} />
|
||||
显示已确认
|
||||
</label>
|
||||
<div style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 14, color: 'var(--text-secondary)' }}>
|
||||
共 <strong>{total}</strong> 笔大额交易
|
||||
{!showReviewed && <span style={{ color: 'var(--warning)' }}>(待确认)</span>}
|
||||
</span>
|
||||
<button className="btn btn-success btn-sm" onClick={handleConfirmAll}>
|
||||
<CheckCircle size={14} /> 全部确认
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Review List */}
|
||||
<div className="card">
|
||||
{loading ? (
|
||||
<div className="loading"><div className="spinner"></div>加载中...</div>
|
||||
) : transactions.length > 0 ? (
|
||||
<div>
|
||||
{transactions.map(tx => (
|
||||
<div key={tx.id} className={`review-item ${tx.reviewed ? 'reviewed' : ''}`}>
|
||||
<div className={`amount-col ${tx.direction === 'income' ? 'stat-value income' : 'stat-value expense'}`}>
|
||||
{formatAmount(tx.amount)}
|
||||
</div>
|
||||
|
||||
<div className="info-col">
|
||||
<div className="title">
|
||||
{tx.ai_description || tx.description || '无描述'}
|
||||
</div>
|
||||
<div className="meta">
|
||||
{formatDate(tx.transaction_date)} ·
|
||||
<span className={`source-type-label source-${tx.source_type}`} style={{ marginLeft: 4 }}>
|
||||
{SOURCE_TYPE_MAP[tx.source_type] || tx.source_type}
|
||||
</span>
|
||||
{tx.counterparty && <span> · {tx.counterparty}</span>}
|
||||
{tx.category && (
|
||||
<span className="tag tag-matched" style={{ marginLeft: 6 }}>{tx.category}</span>
|
||||
)}
|
||||
{tx.reviewed && <span style={{ marginLeft: 6, color: 'var(--success)' }}>✓ 已确认</span>}
|
||||
{tx.matched_transaction_id && (
|
||||
<span className="tag tag-matched" style={{ marginLeft: 6 }}>已对账</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="action-col">
|
||||
<button className="btn btn-secondary btn-sm" onClick={() => setEditingTx({ ...tx })}>
|
||||
<Edit3 size={12} /> 编辑
|
||||
</button>
|
||||
{!tx.reviewed && (
|
||||
<button className="btn btn-success btn-sm" onClick={() => handleConfirm(tx)}>
|
||||
<CheckCircle size={12} /> 确认
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="empty-state">
|
||||
<div className="icon">✅</div>
|
||||
<p>{showReviewed ? '没有已确认的大额交易' : '所有大额交易已确认!'}</p>
|
||||
<p style={{ fontSize: 13, marginTop: 8 }}>
|
||||
{showReviewed ? '尝试切换显示模式' : '可以去交易明细页面查看所有记录'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Edit Modal */}
|
||||
{editingTx && (
|
||||
<div className="modal-overlay" onClick={() => setEditingTx(null)}>
|
||||
<div className="modal" onClick={e => e.stopPropagation()}>
|
||||
<h3>编辑交易分类与描述</h3>
|
||||
|
||||
<div style={{
|
||||
marginBottom: 16, padding: 12, background: 'var(--bg)',
|
||||
borderRadius: 8, fontSize: 13
|
||||
}}>
|
||||
<div style={{ fontWeight: 600, marginBottom: 4 }}>
|
||||
{formatAmount(editingTx.amount)} · {formatDate(editingTx.transaction_date)}
|
||||
</div>
|
||||
<div style={{ color: 'var(--text-secondary)' }}>
|
||||
{editingTx.counterparty} · {editingTx.description}
|
||||
</div>
|
||||
<div style={{ fontFamily: 'monospace', fontSize: 11, color: 'var(--text-secondary)', marginTop: 4 }}>
|
||||
编码: {editingTx.transaction_code}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>分类</label>
|
||||
<select className="form-select" value={editingTx.category || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, category: e.target.value })}>
|
||||
<option value="">选择分类</option>
|
||||
{categories.map(c => (
|
||||
<option key={c.id} value={c.name}>{c.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>交易描述</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
value={editingTx.ai_description || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, ai_description: e.target.value })}
|
||||
placeholder="简要描述这笔交易..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>备注</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
value={editingTx.review_notes || ''}
|
||||
onChange={e => setEditingTx({ ...editingTx, review_notes: e.target.value })}
|
||||
placeholder="人工备注(可选)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', gap: 10, justifyContent: 'flex-end', marginTop: 20 }}>
|
||||
<button className="btn btn-secondary" onClick={() => setEditingTx(null)}>取消</button>
|
||||
<button className="btn btn-primary" onClick={() => handleUpdateTx(editingTx.id, {
|
||||
category: editingTx.category,
|
||||
ai_description: editingTx.ai_description,
|
||||
review_notes: editingTx.review_notes,
|
||||
reviewed: 1
|
||||
})}>
|
||||
保存并确认
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user