Files
EmailBill/Web/src/views/ClassificationBatch.vue

141 lines
3.2 KiB
Vue
Raw Normal View History

2025-12-26 15:21:31 +08:00
<template>
2025-12-27 21:15:26 +08:00
<div class="page-container-flex">
2026-01-16 11:15:44 +08:00
<van-nav-bar
title="批量分类"
2025-12-26 15:21:31 +08:00
left-text="返回"
left-arrow
2026-01-16 11:15:44 +08:00
placeholder
@click-left="handleBack"
2025-12-26 15:21:31 +08:00
/>
2025-12-27 21:15:26 +08:00
<div class="scroll-content">
2025-12-30 17:02:30 +08:00
<!-- 未分类账单统计 -->
<div class="unclassified-stat">
<span>未分类账单数: {{ unclassifiedCount }}</span>
</div>
2025-12-26 15:21:31 +08:00
2025-12-30 17:02:30 +08:00
<!-- 分组列表 -->
<van-empty v-if="!hasData && finished" description="暂无数据" />
2026-01-16 11:15:44 +08:00
2025-12-26 15:21:31 +08:00
<van-list
v-model:loading="listLoading"
v-model:error="error"
:finished="finished"
finished-text="没有更多了"
error-text="请求失败,点击重新加载"
@load="onLoad"
>
2025-12-30 17:02:30 +08:00
<ReasonGroupList
ref="groupListRef"
@data-loaded="handleDataLoaded"
@data-changed="handleDataChanged"
/>
2025-12-26 15:21:31 +08:00
</van-list>
</div>
</div>
</template>
<script setup>
2025-12-30 17:02:30 +08:00
import { ref, onMounted } from 'vue'
2025-12-26 15:21:31 +08:00
import { useRouter } from 'vue-router'
2025-12-30 17:02:30 +08:00
import { getUnclassifiedCount } from '@/api/transactionRecord'
import ReasonGroupList from '@/components/ReasonGroupList.vue'
2025-12-26 15:21:31 +08:00
const router = useRouter()
2025-12-30 17:02:30 +08:00
const groupListRef = ref(null)
2025-12-26 15:21:31 +08:00
// 数据状态
const listLoading = ref(false)
const error = ref(false)
const finished = ref(false)
2025-12-30 17:02:30 +08:00
const hasData = ref(false)
2025-12-26 15:21:31 +08:00
const unclassifiedCount = ref(0)
2026-01-01 11:58:21 +08:00
const _loadedUnclassifiedInitially = ref(false)
2025-12-26 15:21:31 +08:00
// 获取未分类账单统计
const loadUnclassifiedCount = async () => {
try {
const res = await getUnclassifiedCount()
if (res.success) {
unclassifiedCount.value = res.data || 0
}
} catch (error) {
console.error('获取未分类账单数量失败:', error)
}
}
2025-12-30 17:02:30 +08:00
// 处理数据加载完成
const handleDataLoaded = ({ groups, finished: isFinished }) => {
2025-12-30 17:02:30 +08:00
hasData.value = groups.length > 0
finished.value = isFinished
2025-12-26 15:21:31 +08:00
}
2025-12-30 17:02:30 +08:00
// 处理数据变更
const handleDataChanged = async () => {
await loadUnclassifiedCount()
2026-01-01 11:58:21 +08:00
// 重新加载数据
listLoading.value = true
await onLoad()
listLoading.value = false
2025-12-26 15:21:31 +08:00
}
2025-12-30 17:02:30 +08:00
// 加载更多
const onLoad = async () => {
if (!groupListRef.value) {
listLoading.value = false
2025-12-26 15:21:31 +08:00
return
}
2026-01-16 11:15:44 +08:00
2025-12-26 15:21:31 +08:00
try {
2025-12-30 17:02:30 +08:00
await groupListRef.value.loadData()
2026-01-01 11:58:21 +08:00
// 首次加载时获取统计信息(确保统计不会丢失)
if (!_loadedUnclassifiedInitially.value) {
2025-12-26 15:21:31 +08:00
await loadUnclassifiedCount()
2026-01-01 11:58:21 +08:00
_loadedUnclassifiedInitially.value = true
2025-12-26 15:21:31 +08:00
}
2026-01-16 11:15:44 +08:00
2025-12-30 17:02:30 +08:00
error.value = false
} catch (err) {
2026-01-01 11:58:21 +08:00
console.error('加载分组数据失败:', err)
2025-12-30 17:02:30 +08:00
error.value = true
} finally {
listLoading.value = false
2025-12-26 15:21:31 +08:00
}
}
// 返回上一页
const handleBack = () => {
router.back()
}
// 页面加载
2025-12-30 17:02:30 +08:00
onMounted(async () => {
// 初始加载数据
listLoading.value = true
2026-01-01 11:58:21 +08:00
try {
// 先确保统计加载,避免统计消失
await loadUnclassifiedCount()
_loadedUnclassifiedInitially.value = true
} catch (e) {
console.error('初始化加载未分类统计失败:', e)
}
2025-12-30 17:02:30 +08:00
await onLoad()
2025-12-26 15:21:31 +08:00
})
</script>
<style scoped>
.unclassified-stat {
padding-left: 16px;
padding-top: 12px;
font-size: 14px;
font-weight: 500;
opacity: 0.6;
}
2025-12-26 18:03:52 +08:00
/* 设置页面容器背景色 */
:deep(.van-nav-bar) {
background: transparent !important;
}
2025-12-26 15:21:31 +08:00
</style>