2026-01-27 15:29:25 +08:00
|
|
|
<template>
|
2026-01-10 12:22:37 +08:00
|
|
|
<div class="transaction-list-container transaction-list">
|
2026-01-27 15:29:25 +08:00
|
|
|
<van-list
|
|
|
|
|
:loading="loading"
|
|
|
|
|
:finished="finished"
|
|
|
|
|
finished-text="没有更多了"
|
|
|
|
|
@load="onLoad"
|
|
|
|
|
>
|
|
|
|
|
<van-cell-group
|
|
|
|
|
v-if="transactions && transactions.length"
|
|
|
|
|
inset
|
|
|
|
|
style="margin-top: 10px"
|
|
|
|
|
>
|
2025-12-25 11:20:56 +08:00
|
|
|
<van-swipe-cell
|
|
|
|
|
v-for="transaction in transactions"
|
|
|
|
|
:key="transaction.id"
|
2026-01-10 12:22:37 +08:00
|
|
|
class="transaction-item"
|
2025-12-25 11:20:56 +08:00
|
|
|
>
|
2025-12-26 15:21:31 +08:00
|
|
|
<div class="transaction-row">
|
2026-01-16 11:15:44 +08:00
|
|
|
<van-checkbox
|
2025-12-26 15:21:31 +08:00
|
|
|
v-if="showCheckbox"
|
|
|
|
|
:model-value="isSelected(transaction.id)"
|
|
|
|
|
class="checkbox-col"
|
2026-01-07 14:33:30 +08:00
|
|
|
@update:model-value="toggleSelection(transaction)"
|
2025-12-26 15:21:31 +08:00
|
|
|
/>
|
2026-01-27 15:29:25 +08:00
|
|
|
<div
|
|
|
|
|
class="transaction-card"
|
|
|
|
|
@click="handleClick(transaction)"
|
|
|
|
|
>
|
2025-12-26 15:21:31 +08:00
|
|
|
<div class="card-left">
|
|
|
|
|
<div class="transaction-title">
|
|
|
|
|
<span class="reason">{{ transaction.reason || '(无摘要)' }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="transaction-info">
|
|
|
|
|
<div>交易时间: {{ formatDate(transaction.occurredAt) }}</div>
|
|
|
|
|
<div>
|
2026-01-16 11:15:44 +08:00
|
|
|
<span v-if="transaction.classify"> 分类: {{ transaction.classify }} </span>
|
|
|
|
|
<span
|
|
|
|
|
v-if="
|
|
|
|
|
transaction.upsetedClassify &&
|
2026-01-27 15:29:25 +08:00
|
|
|
transaction.upsetedClassify !== transaction.classify
|
2026-01-16 11:15:44 +08:00
|
|
|
"
|
|
|
|
|
style="color: var(--van-warning-color)"
|
|
|
|
|
>
|
2025-12-26 15:21:31 +08:00
|
|
|
→ {{ transaction.upsetedClassify }}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-01-27 15:29:25 +08:00
|
|
|
<div v-if="transaction.importFrom">
|
|
|
|
|
来源: {{ transaction.importFrom }}
|
|
|
|
|
</div>
|
2025-12-26 15:21:31 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="card-middle">
|
2026-01-27 15:29:25 +08:00
|
|
|
<van-tag
|
|
|
|
|
:type="getTypeTagType(transaction.type)"
|
|
|
|
|
size="medium"
|
|
|
|
|
>
|
2025-12-25 11:20:56 +08:00
|
|
|
{{ getTypeName(transaction.type) }}
|
|
|
|
|
</van-tag>
|
2026-01-16 11:15:44 +08:00
|
|
|
<template
|
|
|
|
|
v-if="
|
|
|
|
|
Number.isFinite(transaction.upsetedType) &&
|
2026-01-27 15:29:25 +08:00
|
|
|
transaction.upsetedType !== transaction.type
|
2026-01-16 11:15:44 +08:00
|
|
|
"
|
2025-12-26 15:21:31 +08:00
|
|
|
>
|
|
|
|
|
→
|
2026-01-27 15:29:25 +08:00
|
|
|
<van-tag
|
|
|
|
|
:type="getTypeTagType(transaction.upsetedType)"
|
|
|
|
|
size="medium"
|
|
|
|
|
>
|
2025-12-26 15:21:31 +08:00
|
|
|
{{ getTypeName(transaction.upsetedType) }}
|
|
|
|
|
</van-tag>
|
|
|
|
|
</template>
|
2025-12-25 11:20:56 +08:00
|
|
|
</div>
|
2025-12-26 15:21:31 +08:00
|
|
|
<div class="card-right">
|
|
|
|
|
<div class="transaction-amount">
|
|
|
|
|
<div :class="['amount', getAmountClass(transaction.type)]">
|
|
|
|
|
{{ formatAmount(transaction.amount, transaction.type) }}
|
|
|
|
|
</div>
|
2026-01-16 11:15:44 +08:00
|
|
|
<div
|
2026-01-27 15:29:25 +08:00
|
|
|
v-if="transaction.balance && transaction.balance > 0"
|
2026-01-16 11:15:44 +08:00
|
|
|
class="balance"
|
|
|
|
|
>
|
2026-01-27 15:29:25 +08:00
|
|
|
余额: {{ formatMoney(transaction.balance) }}
|
2025-12-26 15:21:31 +08:00
|
|
|
</div>
|
2025-12-25 11:20:56 +08:00
|
|
|
</div>
|
2026-01-27 15:29:25 +08:00
|
|
|
<van-icon
|
|
|
|
|
name="arrow"
|
|
|
|
|
size="16"
|
|
|
|
|
color="var(--van-gray-5)"
|
|
|
|
|
/>
|
2025-12-25 11:20:56 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-27 15:29:25 +08:00
|
|
|
<template
|
|
|
|
|
v-if="showDelete"
|
|
|
|
|
#right
|
|
|
|
|
>
|
2026-01-16 11:15:44 +08:00
|
|
|
<van-button
|
2025-12-25 11:20:56 +08:00
|
|
|
square
|
2026-01-16 11:15:44 +08:00
|
|
|
type="danger"
|
2025-12-25 11:20:56 +08:00
|
|
|
text="删除"
|
|
|
|
|
class="delete-button"
|
|
|
|
|
@click="handleDeleteClick(transaction)"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</van-swipe-cell>
|
|
|
|
|
</van-cell-group>
|
|
|
|
|
|
2026-01-16 11:15:44 +08:00
|
|
|
<van-empty
|
|
|
|
|
v-if="!loading && !(transactions && transactions.length)"
|
|
|
|
|
description="暂无交易记录"
|
2025-12-25 11:20:56 +08:00
|
|
|
/>
|
|
|
|
|
</van-list>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-01 11:58:21 +08:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { showConfirmDialog, showToast } from 'vant'
|
|
|
|
|
import { deleteTransaction } from '@/api/transactionRecord'
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
import { defineEmits } from 'vue'
|
|
|
|
|
|
2025-12-26 15:21:31 +08:00
|
|
|
const props = defineProps({
|
2025-12-25 11:20:56 +08:00
|
|
|
transactions: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
|
|
|
|
},
|
|
|
|
|
loading: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
finished: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
showDelete: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true
|
2025-12-26 15:21:31 +08:00
|
|
|
},
|
|
|
|
|
showCheckbox: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
selectedIds: {
|
|
|
|
|
type: Set,
|
|
|
|
|
default: () => new Set()
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2025-12-26 15:21:31 +08:00
|
|
|
const emit = defineEmits(['load', 'click', 'delete', 'update:selectedIds'])
|
2025-12-25 11:20:56 +08:00
|
|
|
|
2026-01-01 11:58:21 +08:00
|
|
|
const deletingIds = ref(new Set())
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
const onLoad = () => {
|
|
|
|
|
emit('load')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleClick = (transaction) => {
|
|
|
|
|
emit('click', transaction)
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 11:58:21 +08:00
|
|
|
const handleDeleteClick = async (transaction) => {
|
|
|
|
|
try {
|
|
|
|
|
await showConfirmDialog({
|
|
|
|
|
title: '提示',
|
|
|
|
|
message: '确定要删除这条交易记录吗?'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
deletingIds.value.add(transaction.id)
|
|
|
|
|
const response = await deleteTransaction(transaction.id)
|
|
|
|
|
deletingIds.value.delete(transaction.id)
|
|
|
|
|
|
|
|
|
|
if (response && response.success) {
|
|
|
|
|
showToast('删除成功')
|
|
|
|
|
emit('delete', transaction.id)
|
|
|
|
|
try {
|
|
|
|
|
window.dispatchEvent(new CustomEvent('transaction-deleted', { detail: transaction.id }))
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// ignore in non-browser environment
|
2026-01-07 14:33:30 +08:00
|
|
|
console.log('非浏览器环境,跳过派发 transaction-deleted 事件', e)
|
2026-01-01 11:58:21 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
showToast(response.message || '删除失败')
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// 用户取消确认会抛出 'cancel' 或类似错误
|
|
|
|
|
if (err !== 'cancel') {
|
|
|
|
|
console.error('删除出错:', err)
|
|
|
|
|
showToast('删除失败')
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-26 15:21:31 +08:00
|
|
|
const isSelected = (id) => {
|
|
|
|
|
return props.selectedIds.has(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toggleSelection = (transaction) => {
|
|
|
|
|
const newSelectedIds = new Set(props.selectedIds)
|
|
|
|
|
if (newSelectedIds.has(transaction.id)) {
|
|
|
|
|
newSelectedIds.delete(transaction.id)
|
|
|
|
|
} else {
|
|
|
|
|
newSelectedIds.add(transaction.id)
|
|
|
|
|
}
|
|
|
|
|
emit('update:selectedIds', newSelectedIds)
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
// 获取交易类型名称
|
|
|
|
|
const getTypeName = (type) => {
|
|
|
|
|
const typeMap = {
|
|
|
|
|
0: '支出',
|
|
|
|
|
1: '收入',
|
|
|
|
|
2: '不计入收支'
|
|
|
|
|
}
|
|
|
|
|
return typeMap[type] || '未知'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取交易类型标签类型
|
|
|
|
|
const getTypeTagType = (type) => {
|
|
|
|
|
const typeMap = {
|
|
|
|
|
0: 'danger',
|
|
|
|
|
1: 'success',
|
|
|
|
|
2: 'default'
|
|
|
|
|
}
|
|
|
|
|
return typeMap[type] || 'default'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取金额样式类
|
|
|
|
|
const getAmountClass = (type) => {
|
2026-01-16 11:15:44 +08:00
|
|
|
if (type === 0) {
|
|
|
|
|
return 'expense'
|
|
|
|
|
}
|
|
|
|
|
if (type === 1) {
|
|
|
|
|
return 'income'
|
|
|
|
|
}
|
2025-12-25 11:20:56 +08:00
|
|
|
return 'neutral'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化金额(带符号)
|
|
|
|
|
const formatAmount = (amount, type) => {
|
|
|
|
|
const formatted = formatMoney(amount)
|
2026-01-16 11:15:44 +08:00
|
|
|
if (type === 0) {
|
|
|
|
|
return `- ${formatted}`
|
|
|
|
|
}
|
|
|
|
|
if (type === 1) {
|
|
|
|
|
return `+ ${formatted}`
|
|
|
|
|
}
|
2025-12-25 11:20:56 +08:00
|
|
|
return formatted
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化金额
|
|
|
|
|
const formatMoney = (amount) => {
|
|
|
|
|
return `¥${Number(amount).toFixed(2)}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
|
const formatDate = (dateString) => {
|
2026-01-16 11:15:44 +08:00
|
|
|
if (!dateString) {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
2025-12-25 11:20:56 +08:00
|
|
|
const date = new Date(dateString)
|
2026-01-16 11:15:44 +08:00
|
|
|
return date.toLocaleString('zh-CN', {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: '2-digit',
|
2025-12-25 11:20:56 +08:00
|
|
|
day: '2-digit',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.transaction-list-container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-26 15:21:31 +08:00
|
|
|
.transaction-row {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.checkbox-col {
|
|
|
|
|
padding: 12px 8px;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
.transaction-card {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
transition: background-color 0.3s;
|
2025-12-26 15:21:31 +08:00
|
|
|
flex: 1;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
position: relative;
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.card-left {
|
|
|
|
|
flex: 1;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
padding-right: 12px;
|
2025-12-26 15:21:31 +08:00
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.card-middle {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 12px;
|
|
|
|
|
right: 20px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
z-index: 1;
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.card-right {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.transaction-title {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
margin-bottom: 8px;
|
2025-12-26 15:21:31 +08:00
|
|
|
overflow: hidden;
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.reason {
|
2025-12-26 15:21:31 +08:00
|
|
|
display: block;
|
2025-12-25 11:20:56 +08:00
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
flex: 1;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.transaction-info {
|
|
|
|
|
font-size: 12px;
|
2026-01-13 17:00:44 +08:00
|
|
|
color: var(--van-text-color-2);
|
2025-12-25 11:20:56 +08:00
|
|
|
line-height: 1.6;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-26 15:21:31 +08:00
|
|
|
.original-info {
|
2026-01-13 17:00:44 +08:00
|
|
|
color: var(--van-orange);
|
2025-12-26 15:21:31 +08:00
|
|
|
font-style: italic;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 4px;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 11:20:56 +08:00
|
|
|
.transaction-amount {
|
|
|
|
|
text-align: right;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: flex-end;
|
|
|
|
|
min-width: 90px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.amount {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
margin-bottom: 4px;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.amount.expense {
|
2026-01-13 17:00:44 +08:00
|
|
|
color: var(--van-danger-color);
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.amount.income {
|
2026-01-13 17:00:44 +08:00
|
|
|
color: var(--van-success-color);
|
2025-12-25 11:20:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.balance {
|
|
|
|
|
font-size: 12px;
|
2026-01-13 17:00:44 +08:00
|
|
|
color: var(--van-text-color-2);
|
2025-12-25 11:20:56 +08:00
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.delete-button {
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|