diff --git a/client/src/hooks/useApi.js b/client/src/hooks/useApi.js index 6cfe3ec..cf2cbd7 100644 --- a/client/src/hooks/useApi.js +++ b/client/src/hooks/useApi.js @@ -60,6 +60,22 @@ export async function deleteSource(id) { return res.data; } +// Deals +export async function getDeals(params = {}) { + const res = await api.get("/deals", { params }); + return res.data; +} + +export async function updateDeal(id, data) { + const res = await api.put(`/deals/${id}`, data); + return res.data; +} + +export async function batchConfirmDeals(ids) { + const res = await api.post("/deals/batch-confirm", { ids }); + return res.data; +} + // Transactions export async function getTransactions(params = {}) { const res = await api.get("/transactions", { params }); diff --git a/client/src/pages/Review.js b/client/src/pages/Review.js index e870e52..0e840ad 100644 --- a/client/src/pages/Review.js +++ b/client/src/pages/Review.js @@ -1,19 +1,31 @@ -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'; +import React, { useState, useEffect, useCallback } from "react"; +import { CheckCircle, X, Edit3, ChevronDown, ChevronRight } from "lucide-react"; +import { + getDeals, + updateDeal, + batchConfirmDeals, + formatAmount, + formatDate, + SOURCE_TYPE_MAP, + getCategories, +} from "../hooks/useApi"; export default function Review() { - const [transactions, setTransactions] = useState([]); + const [deals, setDeals] = useState([]); const [loading, setLoading] = useState(true); const [total, setTotal] = useState(0); const [categories, setCategories] = useState([]); - const [editingTx, setEditingTx] = useState(null); + const [editingDeal, setEditingDeal] = useState(null); const [showReviewed, setShowReviewed] = useState(false); - const [keyword, setKeyword] = useState(''); + const [keyword, setKeyword] = useState(""); + const [expandedDeals, setExpandedDeals] = useState(new Set()); useEffect(() => { loadCategories(); - loadReviewTransactions(); + }, []); + + useEffect(() => { + loadReviewDeals(); }, [showReviewed, keyword]); async function loadCategories() { @@ -23,177 +35,399 @@ export default function Review() { } catch (err) {} } - async function loadReviewTransactions() { + async function loadReviewDeals() { setLoading(true); try { const params = { - min_amount: 100, // Only >= 100 RMB + min_amount: 100, limit: 200, - sort_by: 'amount', - sort_order: 'DESC' + sort_by: "amount", + sort_order: "DESC", }; if (!showReviewed) params.reviewed = 0; if (keyword) params.keyword = keyword; - const result = await getTransactions(params); - setTransactions(result.transactions); + const result = await getDeals(params); + setDeals(result.deals); setTotal(result.total); // Update badge count in sidebar try { - const badge = document.getElementById('review-badge'); + 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; + if (!showReviewed) { + badge.textContent = result.total; + } else { + // When showing reviewed, fetch unreviewed count for badge + const unreviewed = await getDeals({ + min_amount: 100, + reviewed: 0, + limit: 1, + }); + badge.textContent = unreviewed.total; + } } } catch (e) {} } catch (err) {} setLoading(false); } - async function handleConfirm(tx) { + async function handleConfirm(deal) { try { - await updateTransaction(tx.id, { reviewed: 1 }); - loadReviewTransactions(); + await updateDeal(deal.id, { reviewed: 1 }); + loadReviewDeals(); } catch (err) {} } - async function handleUpdateTx(id, updates) { + async function handleUpdateDeal(id, updates) { try { - await updateTransaction(id, updates); - setEditingTx(null); - loadReviewTransactions(); + await updateDeal(id, updates); + setEditingDeal(null); + loadReviewDeals(); } 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(); + const unreviewed = deals.filter((d) => !d.reviewed); + if (unreviewed.length === 0) return; + if ( + !window.confirm( + `确定要批量确认当前显示的 ${unreviewed.length} 笔交易吗?`, + ) + ) + return; + try { + await batchConfirmDeals(unreviewed.map((d) => d.id)); + loadReviewDeals(); + } catch (err) {} + } + + function toggleExpand(dealId) { + setExpandedDeals((prev) => { + const next = new Set(prev); + if (next.has(dealId)) next.delete(dealId); + else next.add(dealId); + return next; + }); } return (

🔍 大额交易确认

-

逐笔确认 ≥100 元的交易,核对AI分类和描述是否正确

+

逐笔确认 ≥100 元的 Deal(关联交易组),核对AI分类和描述是否正确

{/* Toolbar */} -
+
setKeyword(e.target.value)} + onChange={(e) => setKeyword(e.target.value)} />
-