Repository navigation
feat(payables): payment history and missing-statement placement #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d01da29
c414d94
d09fd38
e3bdec2
32aad90
95ae00a
850034b
da616fc
d0f5a31
9cb5b1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect, useState, useCallback, useMemo } from 'react' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect, useState, useCallback, useMemo, useRef } from 'react' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { format } from 'date-fns' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||
| getCardsWithBillsSummary, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,8 +19,9 @@ import { BillDraftsPanel } from '@/components/mobile/BillDraftsPanel' | |||||||||||||||||||||||||||||||||||||||||||||
| import { ManualBillAmountDialog } from '@/components/mobile/ManualBillAmountDialog' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { PayableForm } from '@/components/mobile/PayableForm' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||
| getRecurringPayables, payRecurringPayable, | ||||||||||||||||||||||||||||||||||||||||||||||
| getRecurringPayables, payRecurringPayable, getPayablePayments, | ||||||||||||||||||||||||||||||||||||||||||||||
| type PayableWithStatus, | ||||||||||||||||||||||||||||||||||||||||||||||
| type PayablePaymentRecord, | ||||||||||||||||||||||||||||||||||||||||||||||
| } from '@/lib/api/payables' | ||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||
| formatCardTail, compareBillsListCardsByMode, pickDueReference, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +73,15 @@ function tagSummary( | |||||||||||||||||||||||||||||||||||||||||||||
| return selectedTag === NO_BANK_TAG ? '非银行' : selectedTag | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** 不可变地从 Record 中删除一个 key(无该 key 时返回原对象)。 */ | ||||||||||||||||||||||||||||||||||||||||||||||
| function omitRecordKey<T>(record: Record<string, T>, key: string): Record<string, T> { | ||||||||||||||||||||||||||||||||||||||||||||||
| // 只判断自有属性:`in` 会沿原型链命中 toString/constructor 等 | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!Object.prototype.hasOwnProperty.call(record, key)) return record | ||||||||||||||||||||||||||||||||||||||||||||||
| const next = { ...record } | ||||||||||||||||||||||||||||||||||||||||||||||
| delete next[key] | ||||||||||||||||||||||||||||||||||||||||||||||
| return next | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default function BillsPage() { | ||||||||||||||||||||||||||||||||||||||||||||||
| const { user } = useAuth() | ||||||||||||||||||||||||||||||||||||||||||||||
| const { displayConfig } = useUserPreferences() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -92,6 +102,11 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| // 固定支出(房租/贷款等按月应付) | ||||||||||||||||||||||||||||||||||||||||||||||
| const [payables, setPayables] = useState<PayableWithStatus[]>([]) | ||||||||||||||||||||||||||||||||||||||||||||||
| const [payableFormOpen, setPayableFormOpen] = useState(false) | ||||||||||||||||||||||||||||||||||||||||||||||
| // 固定支出历史还款:按需加载,展开一次后缓存 | ||||||||||||||||||||||||||||||||||||||||||||||
| const [payablePayments, setPayablePayments] = useState<Record<string, PayablePaymentRecord[]>>({}) | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| const [expandedPayableIds, setExpandedPayableIds] = useState<Set<string>>(new Set()) | ||||||||||||||||||||||||||||||||||||||||||||||
| const [payableHistoryErrors, setPayableHistoryErrors] = useState<Record<string, string>>({}) | ||||||||||||||||||||||||||||||||||||||||||||||
| const [payableHistoryLoading, setPayableHistoryLoading] = useState<Set<string>>(new Set()) | ||||||||||||||||||||||||||||||||||||||||||||||
| const [editingPayable, setEditingPayable] = useState<PayableWithStatus | null>(null) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const [celebrationNotice, setCelebrationNotice] = useState<{ open: boolean; message: string }>({ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -125,6 +140,59 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| // 持卡人 id → name 映射 | ||||||||||||||||||||||||||||||||||||||||||||||
| const [holderMap, setHolderMap] = useState<Record<string, string>>({}) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 展开集合的 ref:异步回调里需要读最新值(state 是渲染快照) | ||||||||||||||||||||||||||||||||||||||||||||||
| const expandedPayableIdsRef = useRef(expandedPayableIds) | ||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| expandedPayableIdsRef.current = expandedPayableIds | ||||||||||||||||||||||||||||||||||||||||||||||
| }, [expandedPayableIds]) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 同一笔的在途请求:并发点击或还款后重取都复用同一个 Promise,避免重复 RPC | ||||||||||||||||||||||||||||||||||||||||||||||
| const payableHistoryInFlight = useRef<Map<string, Promise<void>>>(new Map()) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 缓存代次:全量刷新或还款后递增,旧代次发起的请求不再写回 | ||||||||||||||||||||||||||||||||||||||||||||||
| const payableHistoryGeneration = useRef(0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** 拉取并写入历史缓存;同一 payableId 复用进行中的请求。 */ | ||||||||||||||||||||||||||||||||||||||||||||||
| const loadPayableHistory = useCallback((payableId: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const running = payableHistoryInFlight.current.get(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (running) return running | ||||||||||||||||||||||||||||||||||||||||||||||
| const generation = payableHistoryGeneration.current | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayableHistoryLoading(prev => new Set(prev).add(payableId)) | ||||||||||||||||||||||||||||||||||||||||||||||
| let settle!: () => void | ||||||||||||||||||||||||||||||||||||||||||||||
| const current = new Promise<void>(resolve => { settle = resolve }) | ||||||||||||||||||||||||||||||||||||||||||||||
| void (async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| const records = await getPayablePayments(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| // 代次已变(刷新/还款期间发起):结果作废,不写回旧数据 | ||||||||||||||||||||||||||||||||||||||||||||||
| if (payableHistoryGeneration.current !== generation) return | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayablePayments(prev => ({ ...prev, [payableId]: records })) | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayableHistoryErrors(prev => omitRecordKey(prev, payableId)) | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (payableHistoryGeneration.current !== generation) return | ||||||||||||||||||||||||||||||||||||||||||||||
| // 保持未加载状态:再次展开会重试;错误就地展示 | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayableHistoryErrors(prev => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...prev, | ||||||||||||||||||||||||||||||||||||||||||||||
| [payableId]: err instanceof Error ? err.message : '历史还款加载失败', | ||||||||||||||||||||||||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||
| // 只清理自己这条:被新任务顶替或代次已变时不能误删(否则新请求期间不显示加载中) | ||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryInFlight.current.get(payableId) === current && | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryGeneration.current === generation | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+179
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryInFlight.current.delete(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayableHistoryLoading(prev => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const next = new Set(prev) | ||||||||||||||||||||||||||||||||||||||||||||||
| next.delete(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| return next | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+177
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| })().finally(() => settle()) | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryInFlight.current.set(payableId, current) | ||||||||||||||||||||||||||||||||||||||||||||||
| return current | ||||||||||||||||||||||||||||||||||||||||||||||
| }, []) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const loadData = useCallback(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!user) return | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,6 +203,12 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| getHolders(user.id), | ||||||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||||||
| setCardsSummary(summaryData) | ||||||||||||||||||||||||||||||||||||||||||||||
| // 全量刷新:递增代次作废在途响应,清空缓存,并对仍展开的行重拉 | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryGeneration.current += 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryInFlight.current.clear() | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayablePayments({}) | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayableHistoryErrors({}) | ||||||||||||||||||||||||||||||||||||||||||||||
| expandedPayableIdsRef.current.forEach(id => { void loadPayableHistory(id) }) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+209
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| const map: Record<string, string> = {} | ||||||||||||||||||||||||||||||||||||||||||||||
| for (const h of holders) map[h.id] = h.name | ||||||||||||||||||||||||||||||||||||||||||||||
| setHolderMap(map) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -151,7 +225,7 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||
| setLoading(false) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }, [user]) | ||||||||||||||||||||||||||||||||||||||||||||||
| }, [user, loadPayableHistory]) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| loadData() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -416,6 +490,14 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| const handlePayPayable = async (payable: PayableWithStatus) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| await payRecurringPayable(payable.id, payable.amount) | ||||||||||||||||||||||||||||||||||||||||||||||
| // 新还款落库:先等在途旧请求落定(否则它的成功回调会把不含新还款的记录写回), | ||||||||||||||||||||||||||||||||||||||||||||||
| // 再清缓存并重取 | ||||||||||||||||||||||||||||||||||||||||||||||
| // 递增代次:作废还款前发起的请求;随后清缓存 | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryGeneration.current += 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| const running = payableHistoryInFlight.current.get(payable.id) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (running) await running | ||||||||||||||||||||||||||||||||||||||||||||||
| setPayablePayments(prev => omitRecordKey(prev, payable.id)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+496
to
+499
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 不在此处重取:紧随其后的 loadData 会统一清缓存并重拉展开行 | ||||||||||||||||||||||||||||||||||||||||||||||
| setCelebrationNotice({ | ||||||||||||||||||||||||||||||||||||||||||||||
| open: true, | ||||||||||||||||||||||||||||||||||||||||||||||
| message: `🎉 已登记「${payable.name}」本期付款 ${currencySymbol(payable.currency)}${payable.amount.toLocaleString()}`, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -426,6 +508,22 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** 展开/收起固定支出历史:首次展开才拉取该笔记录。 */ | ||||||||||||||||||||||||||||||||||||||||||||||
| const handleTogglePayableHistory = useCallback( | ||||||||||||||||||||||||||||||||||||||||||||||
| (payableId: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const willOpen = !expandedPayableIdsRef.current.has(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| setExpandedPayableIds(prev => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const next = new Set(prev) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (willOpen) next.add(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| else next.delete(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| return next | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!willOpen || payablePayments[payableId]) return | ||||||||||||||||||||||||||||||||||||||||||||||
| void loadPayableHistory(payableId) | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| [payablePayments, loadPayableHistory] | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // 收起态摘要:把当前筛选、分组与排序压成一行可读文本 | ||||||||||||||||||||||||||||||||||||||||||||||
| const filterSummary = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const statusText = | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -506,6 +604,11 @@ export default function BillsPage() { | |||||||||||||||||||||||||||||||||||||||||||||
| onRetry={() => loadData()} | ||||||||||||||||||||||||||||||||||||||||||||||
| onEmptySync={handleSync} | ||||||||||||||||||||||||||||||||||||||||||||||
| payables={filteredPayables} | ||||||||||||||||||||||||||||||||||||||||||||||
| payablePayments={payablePayments} | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryErrors={payableHistoryErrors} | ||||||||||||||||||||||||||||||||||||||||||||||
| payableHistoryLoading={payableHistoryLoading} | ||||||||||||||||||||||||||||||||||||||||||||||
| expandedPayableIds={expandedPayableIds} | ||||||||||||||||||||||||||||||||||||||||||||||
| onTogglePayableHistory={handleTogglePayableHistory} | ||||||||||||||||||||||||||||||||||||||||||||||
| onEditPayable={p => { setEditingPayable(p); setPayableFormOpen(true) }} | ||||||||||||||||||||||||||||||||||||||||||||||
| onPayPayable={handlePayPayable} | ||||||||||||||||||||||||||||||||||||||||||||||
| cards={sortedCards} | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,13 @@ | ||||||||||||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import { useState } from 'react' | ||||||||||||||||||||||||||||||||||
| import { categoryLabel, type PayableWithStatus } from '@/lib/api/payables' | ||||||||||||||||||||||||||||||||||
| import { format } from 'date-fns' | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| categoryLabel, | ||||||||||||||||||||||||||||||||||
| PAYABLE_HISTORY_LIMIT, | ||||||||||||||||||||||||||||||||||
| type PayableWithStatus, | ||||||||||||||||||||||||||||||||||
| type PayablePaymentRecord, | ||||||||||||||||||||||||||||||||||
| } from '@/lib/api/payables' | ||||||||||||||||||||||||||||||||||
| import { payableNextCycleStatus } from '@/lib/utils' | ||||||||||||||||||||||||||||||||||
| import { badgeToneClass, type BillBadgeTone } from '@/lib/bills-view-model' | ||||||||||||||||||||||||||||||||||
| import { currencySymbol } from '@/lib/fx' | ||||||||||||||||||||||||||||||||||
|
|
@@ -11,10 +17,70 @@ export interface PayableRowProps { | |||||||||||||||||||||||||||||||||
| payable: PayableWithStatus | ||||||||||||||||||||||||||||||||||
| /** 归属持卡人姓名;未指定归属时不显示 */ | ||||||||||||||||||||||||||||||||||
| holderName?: string | ||||||||||||||||||||||||||||||||||
| /** 历史还款记录(按账期倒序);undefined = 尚未加载 */ | ||||||||||||||||||||||||||||||||||
| payments?: PayablePaymentRecord[] | ||||||||||||||||||||||||||||||||||
| /** 历史加载失败提示;为空表示无错误 */ | ||||||||||||||||||||||||||||||||||
| historyError?: string | ||||||||||||||||||||||||||||||||||
| /** 历史请求在途(含重试);优先于错误态展示 */ | ||||||||||||||||||||||||||||||||||
| historyLoading?: boolean | ||||||||||||||||||||||||||||||||||
| /** 是否展开历史还款 */ | ||||||||||||||||||||||||||||||||||
| historyOpen?: boolean | ||||||||||||||||||||||||||||||||||
| onToggleHistory?: () => void | ||||||||||||||||||||||||||||||||||
| onEdit: (payable: PayableWithStatus) => void | ||||||||||||||||||||||||||||||||||
| onPay: (payable: PayableWithStatus) => void | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** 展开按钮文案:达到上限时改称「最近 N 笔」,避免误以为已看全。 */ | ||||||||||||||||||||||||||||||||||
| function historyLabel(payments: PayablePaymentRecord[] | undefined): string { | ||||||||||||||||||||||||||||||||||
| if (!payments || payments.length === 0) return '历史还款' | ||||||||||||||||||||||||||||||||||
| if (payments.length >= PAYABLE_HISTORY_LIMIT) return `最近 ${PAYABLE_HISTORY_LIMIT} 笔还款` | ||||||||||||||||||||||||||||||||||
| return `历史还款 ${payments.length} 笔` | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** 历史还款展开区:加载中 / 失败 / 空 / 列表四态,避免嵌套三元。 */ | ||||||||||||||||||||||||||||||||||
| function renderPayableHistory( | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||
| payments: PayablePaymentRecord[] | undefined, | ||||||||||||||||||||||||||||||||||
| historyError: string | undefined, | ||||||||||||||||||||||||||||||||||
| historyLoading: boolean, | ||||||||||||||||||||||||||||||||||
| currency: string | ||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||
| // 顺序必须是 在途 → 失败 → 未加载:失败时 payments 仍为 undefined, | ||||||||||||||||||||||||||||||||||
| // 若把 undefined 并入加载中,错误文案将永远不可达。 | ||||||||||||||||||||||||||||||||||
| if (historyLoading) { | ||||||||||||||||||||||||||||||||||
| return <p className='mt-1.5 text-[11px] text-d-muted'>加载中…</p> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (historyError) { | ||||||||||||||||||||||||||||||||||
| return <p className='mt-1.5 text-[11px] text-d-danger-ink'>{historyError}</p> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (payments === undefined) { | ||||||||||||||||||||||||||||||||||
| // 无在途请求却仍为 undefined:说明缓存被清空但未重取,提示可再次展开 | ||||||||||||||||||||||||||||||||||
| return <p className='mt-1.5 text-[11px] text-d-muted'>展开以加载历史</p> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
Comment on lines
+55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||
| if (payments.length === 0) { | ||||||||||||||||||||||||||||||||||
| return <p className='mt-1.5 text-[11px] text-d-muted'>还没有历史还款记录</p> | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <ul className='mt-1.5 flex flex-col gap-1'> | ||||||||||||||||||||||||||||||||||
| {payments.map(record => ( | ||||||||||||||||||||||||||||||||||
| <li | ||||||||||||||||||||||||||||||||||
| key={record.id} | ||||||||||||||||||||||||||||||||||
| className='flex items-baseline justify-between gap-2 rounded-md bg-d-subtle px-2 py-1' | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| <span className='shrink-0 text-[11px] text-d-muted'>{record.period}</span> | ||||||||||||||||||||||||||||||||||
| <span className='min-w-0 flex-1 truncate text-[11px] text-d-text'> | ||||||||||||||||||||||||||||||||||
| {format(new Date(record.paid_at), 'MM-dd')} | ||||||||||||||||||||||||||||||||||
| {record.note ? ' · ' + record.note : ''} | ||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||
| <span className='shrink-0 text-[11px] font-semibold text-d-text'> | ||||||||||||||||||||||||||||||||||
| {currencySymbol(currency)} | ||||||||||||||||||||||||||||||||||
| {Number(record.amount).toLocaleString()} | ||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||
| </li> | ||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||
| </ul> | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * 单条固定支出卡。从 PayableList 拆出:账单页现在把固定支出混进主列表统一排序。 | ||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||
|
|
@@ -26,7 +92,17 @@ export interface PayableRowProps { | |||||||||||||||||||||||||||||||||
| * 滚动模型(服务端 resolveDisplayPeriod)保证任一时刻卡片只呈现一期: | ||||||||||||||||||||||||||||||||||
| * 「已登记」只可能出现在待出账态,待还款态一定是可登记付款的未付期。 | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
| export function PayableRow({ payable: p, holderName, onEdit, onPay }: PayableRowProps) { | ||||||||||||||||||||||||||||||||||
| export function PayableRow({ | ||||||||||||||||||||||||||||||||||
| payable: p, | ||||||||||||||||||||||||||||||||||
| holderName, | ||||||||||||||||||||||||||||||||||
| payments, | ||||||||||||||||||||||||||||||||||
| historyError, | ||||||||||||||||||||||||||||||||||
| historyLoading = false, | ||||||||||||||||||||||||||||||||||
| historyOpen = false, | ||||||||||||||||||||||||||||||||||
| onToggleHistory, | ||||||||||||||||||||||||||||||||||
| onEdit, | ||||||||||||||||||||||||||||||||||
| onPay, | ||||||||||||||||||||||||||||||||||
| }: PayableRowProps) { | ||||||||||||||||||||||||||||||||||
| const [copiedAccount, setCopiedAccount] = useState(false) | ||||||||||||||||||||||||||||||||||
| const paid = p.status === 'paid' | ||||||||||||||||||||||||||||||||||
| const overdue = p.status === 'overdue' | ||||||||||||||||||||||||||||||||||
|
|
@@ -162,6 +238,22 @@ export function PayableRow({ payable: p, holderName, onEdit, onPay }: PayableRow | |||||||||||||||||||||||||||||||||
| <ClockIcon size={14} /> | ||||||||||||||||||||||||||||||||||
| {detail} | ||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| {onToggleHistory && ( | ||||||||||||||||||||||||||||||||||
| <div className='mt-2.5 border-t border-d-border pt-2'> | ||||||||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||||||||
| type='button' | ||||||||||||||||||||||||||||||||||
| aria-expanded={historyOpen} | ||||||||||||||||||||||||||||||||||
| onClick={e => { e.stopPropagation(); onToggleHistory() }} | ||||||||||||||||||||||||||||||||||
| className='flex w-full items-center justify-between text-[11px] font-semibold text-d-muted' | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+244
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||
| <span>{historyLabel(payments)}</span> | ||||||||||||||||||||||||||||||||||
| <span className='text-d-accent-light'>{historyOpen ? '收起' : '展开'}</span> | ||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||
| {historyOpen && | ||||||||||||||||||||||||||||||||||
| renderPayableHistory(payments, historyError, historyLoading, p.currency)} | ||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,7 @@ import { | |||||||
| type BillsEntityType, | ||||||||
| } from '@/lib/bills-view-model' | ||||||||
| import { PayableRow } from '@/components/mobile/PayableList' | ||||||||
| import type { PayableWithStatus } from '@/lib/api/payables' | ||||||||
| import type { PayableWithStatus, PayablePaymentRecord } from '@/lib/api/payables' | ||||||||
| import { currencySymbol } from '@/lib/fx' | ||||||||
| import { | ||||||||
| AlertIcon, | ||||||||
|
|
@@ -93,6 +93,13 @@ export interface BillsViewProps { | |||||||
| onRetry: () => void | ||||||||
| onEmptySync: () => void | ||||||||
| payables: PayableWithStatus[] | ||||||||
| /** 各固定支出的历史还款记录,key = payable id */ | ||||||||
| payablePayments: Record<string, PayablePaymentRecord[]> | ||||||||
| payableHistoryErrors: Record<string, string> | ||||||||
| payableHistoryLoading: Set<string> | ||||||||
| /** 已展开历史的 payable id */ | ||||||||
| expandedPayableIds: Set<string> | ||||||||
| onTogglePayableHistory: (id: string) => void | ||||||||
| onEditPayable: (p: PayableWithStatus) => void | ||||||||
| onPayPayable: (p: PayableWithStatus) => void | ||||||||
| cards: CardWithBillsSummary[] | ||||||||
|
|
@@ -276,11 +283,6 @@ function BillCard({ | |||||||
| <span className='text-d-muted'> · </span> | ||||||||
| 下期还款日 <span className='font-bold'>{format(new Date(item.nextDueDate), 'MM-dd')}</span> | ||||||||
| </p> | ||||||||
| {missingStatement && ( | ||||||||
| <p className='flex items-center gap-1.5 text-[11px] font-semibold leading-4 text-[color:var(--warning)]'> | ||||||||
| 已过账单日 {missingStatement} 日,未接收到新的账单,请检查 | ||||||||
| </p> | ||||||||
| )} | ||||||||
| {isCleared || sortMode === 'max_interest_free' ? ( | ||||||||
| <p className='flex items-center gap-1.5 text-[11px] font-semibold leading-4 text-d-success-ink'> | ||||||||
| 今日刷卡免息 {item.graceDays} 天 | ||||||||
|
|
@@ -373,6 +375,13 @@ function BillCard({ | |||||||
| )} | ||||||||
| </div> | ||||||||
| )} | ||||||||
|
|
||||||||
| {/* 缺账单提醒放在卡片最末:先看账单数据,再看采集异常 */} | ||||||||
| {missingStatement && ( | ||||||||
| <p className='mt-3 flex items-center gap-1.5 rounded-[10px] bg-d-subtle p-2.5 text-[11px] font-semibold leading-4 text-[color:var(--warning)]'> | ||||||||
| 已过账单日 {missingStatement} 日,未接收到新的账单,请检查 | ||||||||
| </p> | ||||||||
| )} | ||||||||
| </div> | ||||||||
| ) | ||||||||
| } | ||||||||
|
|
@@ -386,6 +395,8 @@ export function BillsView(vm: BillsViewProps) { | |||||||
| selectedTag, onSelectedTag, holderTags, bankTags, | ||||||||
| loading, loadError, onRetry, onEmptySync, payables, cards, allCards, holderMap, | ||||||||
| bankGroups, onOpenPayment, onManualAmount, onAddBill, sortMode, onSortMode, | ||||||||
| payablePayments, payableHistoryErrors, payableHistoryLoading, | ||||||||
| expandedPayableIds, onTogglePayableHistory, | ||||||||
| onEditPayable, onPayPayable, | ||||||||
| } = vm | ||||||||
|
|
||||||||
|
|
@@ -444,6 +455,11 @@ export function BillsView(vm: BillsViewProps) { | |||||||
| key={`payable-${p.id}`} | ||||||||
| payable={p} | ||||||||
| holderName={p.holder_id ? holderMap[p.holder_id] : undefined} | ||||||||
| payments={payablePayments[p.id]} | ||||||||
| historyError={payableHistoryErrors[p.id]} | ||||||||
| historyLoading={payableHistoryLoading.has(p.id)} | ||||||||
| historyOpen={expandedPayableIds.has(p.id)} | ||||||||
| onToggleHistory={() => onTogglePayableHistory(p.id)} | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||
| onEdit={onEditPayable} | ||||||||
| onPay={onPayPayable} | ||||||||
| /> | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key in record会沿原型链查找(如 'toString'、'constructor' 始终返回 true),与该工具函数「判断自有 key」的语义不符:当传入的 key 恰好命中 Object.prototype 上的属性名时,会走删除分支并返回一个新对象而非原对象。当前调用方传入的都是服务端生成的 UUID,实际不可触达,故仅为低风险加固;但这是模块级通用工具函数,建议改用 Object.hasOwn(record, key) 以匹配自身属性的语义。Suggestion: