fix
This commit is contained in:
@@ -129,6 +129,7 @@
|
||||
:finished="true"
|
||||
:show-delete="true"
|
||||
@click="handleTransactionClick"
|
||||
@delete="handleTransactionDelete"
|
||||
/>
|
||||
</PopupContainer>
|
||||
|
||||
@@ -143,7 +144,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
||||
import { showToast, showConfirmDialog } from 'vant'
|
||||
import { getEmailList, getEmailDetail, deleteEmail, refreshTransactionRecords, syncEmails, getEmailTransactions } from '@/api/emailRecord'
|
||||
import { getTransactionDetail } from '@/api/transactionRecord'
|
||||
@@ -281,7 +282,7 @@ const handleRefreshAnalysis = async () => {
|
||||
})
|
||||
|
||||
refreshingAnalysis.value = true
|
||||
const response = await refreshTransactionRecords(currentEmail.value.id || currentEmail.value.Id)
|
||||
const response = await refreshTransactionRecords(currentEmail.value.id)
|
||||
|
||||
if (response.success) {
|
||||
showToast('重新分析成功')
|
||||
@@ -325,7 +326,7 @@ const viewTransactions = async () => {
|
||||
if (!currentEmail.value) return
|
||||
|
||||
try {
|
||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||
const emailId = currentEmail.value.id
|
||||
const response = await getEmailTransactions(emailId)
|
||||
|
||||
if (response.success) {
|
||||
@@ -340,6 +341,46 @@ const viewTransactions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 监听全局删除事件,保持弹窗内交易列表一致
|
||||
const onGlobalTransactionDeleted = (e) => {
|
||||
// 如果交易列表弹窗打开,尝试重新加载邮箱的交易列表
|
||||
if (transactionListVisible.value && currentEmail.value) {
|
||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||
getEmailTransactions(emailId).then(response => {
|
||||
if (response.success) {
|
||||
transactionList.value = response.data || []
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
})
|
||||
|
||||
// 监听新增/修改/批量更新事件,刷新弹窗内交易或邮件列表
|
||||
const onGlobalTransactionsChanged = (e) => {
|
||||
if (transactionListVisible.value && currentEmail.value) {
|
||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||
getEmailTransactions(emailId).then(response => {
|
||||
if (response.success) {
|
||||
transactionList.value = response.data || []
|
||||
}
|
||||
}).catch(() => {})
|
||||
} else {
|
||||
// 也刷新邮件列表以保持统计一致
|
||||
loadData(true)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
})
|
||||
|
||||
// 处理点击账单
|
||||
const handleTransactionClick = async (transaction) => {
|
||||
try {
|
||||
@@ -356,16 +397,36 @@ const handleTransactionClick = async (transaction) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleTransactionDelete = (transactionId) => {
|
||||
// 从当前的交易列表中移除该交易
|
||||
transactionList.value = transactionList.value.filter(t => t.id !== transactionId)
|
||||
|
||||
// 刷新邮件列表
|
||||
loadData(true)
|
||||
|
||||
// 刷新当前邮件详情
|
||||
if (currentEmail.value) {
|
||||
const emailId = currentEmail.value.id
|
||||
getEmailDetail(emailId).then(response => {
|
||||
if (response.success) {
|
||||
currentEmail.value = response.data
|
||||
}
|
||||
})
|
||||
}
|
||||
try { window.dispatchEvent(new CustomEvent('transaction-deleted', { detail: transactionId })) } catch(e) {}
|
||||
}
|
||||
|
||||
// 账单保存后刷新列表
|
||||
const handleTransactionSave = async () => {
|
||||
// 刷新账单列表
|
||||
if (currentEmail.value) {
|
||||
const emailId = currentEmail.value.id || currentEmail.value.Id
|
||||
const emailId = currentEmail.value.id
|
||||
const response = await getEmailTransactions(emailId)
|
||||
if (response.success) {
|
||||
transactionList.value = response.data || []
|
||||
}
|
||||
}
|
||||
try { window.dispatchEvent(new CustomEvent('transactions-changed', { detail: { emailId: currentEmail.value?.id } })) } catch(e) {}
|
||||
}
|
||||
|
||||
// 格式化日期
|
||||
|
||||
Reference in New Issue
Block a user