账单异步生成优化
This commit is contained in:
@@ -17,17 +17,21 @@
|
||||
<el-descriptions-item label="收款账号">{{ mask(detail.bankAccountNo) }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="section-title">订单快照({{ detail.orderCount || 0 }})</div>
|
||||
<el-table :data="detail.details || []" border size="small">
|
||||
<!-- 账单明细独立分页;费用明细在展开行时再懒加载。 -->
|
||||
<div class="section-title">账单明细({{ detail.orderCount || 0 }})</div>
|
||||
<el-table v-loading="detailListLoading" :data="detailRows" row-key="detailId" border size="small" @expand-change="handleExpandChange">
|
||||
<el-table-column type="expand">
|
||||
<template #default="{ row }">
|
||||
<el-table :data="row.fees || []" border size="small" class="fee-table">
|
||||
<el-table-column prop="feeType" label="费用类型" width="140" />
|
||||
<el-table-column prop="feeName" label="费用名称" min-width="160" />
|
||||
<el-table-column prop="amount" label="金额" width="120" align="right"><template #default="{ row: fee }">{{ money(fee.amount) }}</template></el-table-column>
|
||||
<el-table-column prop="currency" label="币种" width="80" />
|
||||
<el-table-column prop="remark" label="说明" show-overflow-tooltip />
|
||||
</el-table>
|
||||
<div v-loading="row.feeLoading" class="fee-panel">
|
||||
<el-empty v-if="row.feesLoaded && !row.fees?.length" description="暂无费用明细" :image-size="60" />
|
||||
<el-table v-else :data="row.fees || []" border size="small" class="fee-table">
|
||||
<el-table-column prop="feeType" label="费用类型" width="140" />
|
||||
<el-table-column prop="feeName" label="费用名称" min-width="160" />
|
||||
<el-table-column prop="amount" label="金额" width="120" align="right"><template #default="{ row: fee }">{{ money(fee.amount) }}</template></el-table-column>
|
||||
<el-table-column prop="currency" label="币种" width="80" />
|
||||
<el-table-column prop="remark" label="说明" show-overflow-tooltip />
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="detailNo" label="#" width="55" align="center" />
|
||||
@@ -38,12 +42,24 @@
|
||||
<el-table-column label="重量/尺寸" min-width="170"><template #default="{ row }">{{ row.chargeWeight || '-' }} kg / {{ dimensions(row) }}</template></el-table-column>
|
||||
<el-table-column prop="totalAmount" label="订单金额" width="120" align="right"><template #default="{ row }">{{ money(row.totalAmount) }}</template></el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="detailTotal > 0"
|
||||
class="detail-pagination"
|
||||
v-model:current-page="detailPageNum"
|
||||
v-model:page-size="detailPageSize"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="detailTotal"
|
||||
@current-change="loadDetails"
|
||||
@size-change="handleDetailSizeChange"
|
||||
/>
|
||||
|
||||
<div class="section-title export-title"><span>导出历史</span><el-button size="small" type="primary" plain icon="Download" @click="$emit('export')">生成新文件</el-button></div>
|
||||
<div class="section-title export-title"><span>导出历史</span><el-button size="small" type="primary" plain icon="Download" :loading="exporting" :disabled="exporting" @click="$emit('export')">{{ exporting ? '生成中' : '生成新文件' }}</el-button></div>
|
||||
<el-table :data="detail.exports || []" border size="small">
|
||||
<el-table-column prop="fileName" label="文件名" min-width="250" show-overflow-tooltip />
|
||||
<el-table-column prop="templateVersion" label="模板版本" width="100" />
|
||||
<el-table-column prop="exportStatus" label="状态" width="100"><template #default="{ row }"><el-tag :type="exportStatusType(row.exportStatus)">{{ exportStatusText(row.exportStatus) }}</el-tag></template></el-table-column>
|
||||
<el-table-column prop="remark" label="失败原因" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column prop="exportBy" label="导出人" width="100" />
|
||||
<el-table-column prop="exportTime" label="导出时间" width="170" />
|
||||
<el-table-column label="操作" width="90"><template #default="{ row }"><el-button v-if="row.exportStatus === AR_EXPORT_STATUS.SUCCESS" link type="primary" @click="$emit('download', row)">下载</el-button></template></el-table-column>
|
||||
@@ -54,10 +70,64 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { listArBillDetails, listArBillDetailFees } from '@/api/ar/bill'
|
||||
import { AR_BILL_STATUS_OPTIONS, AR_BILL_STATUS_TYPES, AR_EXPORT_STATUS, AR_EXPORT_STATUS_OPTIONS, AR_EXPORT_STATUS_TYPES, arEnumLabel } from '@/constants/ar/enums'
|
||||
|
||||
defineProps({ modelValue: Boolean, detail: { type: Object, default: null }, loading: Boolean })
|
||||
const props = defineProps({ modelValue: Boolean, detail: { type: Object, default: null }, loading: Boolean })
|
||||
defineEmits(['update:modelValue', 'download', 'export'])
|
||||
const detailRows = ref([])
|
||||
const detailTotal = ref(0)
|
||||
const detailPageNum = ref(1)
|
||||
// 详情默认每页 10 条,避免几十万条账单明细一次性进入浏览器内存。
|
||||
const detailPageSize = ref(10)
|
||||
const detailListLoading = ref(false)
|
||||
let detailRequestSerial = 0
|
||||
const exporting = computed(() => props.detail?.exports?.some(item => item.exportStatus === AR_EXPORT_STATUS.PROCESSING))
|
||||
|
||||
// 切换账单时重置分页和请求序号,旧账单的慢响应不能覆盖新账单。
|
||||
watch(() => props.detail?.arBillId, billId => {
|
||||
detailRequestSerial += 1
|
||||
detailPageNum.value = 1
|
||||
detailTotal.value = 0
|
||||
detailRows.value = []
|
||||
if (billId) loadDetails()
|
||||
}, { immediate: true })
|
||||
|
||||
// 账单明细接口只返回当前页;分页变化时复用同一账单 ID 重新查询。
|
||||
function loadDetails() {
|
||||
const billId = props.detail?.arBillId
|
||||
if (!billId) return
|
||||
const serial = ++detailRequestSerial
|
||||
detailListLoading.value = true
|
||||
listArBillDetails(billId, { pageNum: detailPageNum.value, pageSize: detailPageSize.value }).then(res => {
|
||||
if (serial !== detailRequestSerial) return
|
||||
detailRows.value = (res.rows || []).map(row => ({ ...row, fees: [], feesLoaded: false, feeLoading: false }))
|
||||
detailTotal.value = Number(res.total) || 0
|
||||
}).finally(() => {
|
||||
if (serial === detailRequestSerial) detailListLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleDetailSizeChange(size) {
|
||||
detailPageSize.value = size
|
||||
detailPageNum.value = 1
|
||||
loadDetails()
|
||||
}
|
||||
|
||||
// 费用明细按行懒加载,并用标记避免同一行重复请求。
|
||||
function handleExpandChange(row, expandedRows) {
|
||||
if (!expandedRows.includes(row) || row.feesLoaded || row.feeLoading) return
|
||||
const billId = props.detail?.arBillId
|
||||
if (!billId || !row.detailId) return
|
||||
row.feeLoading = true
|
||||
listArBillDetailFees(billId, row.detailId).then(res => {
|
||||
row.fees = res.data || []
|
||||
row.feesLoaded = true
|
||||
}).finally(() => {
|
||||
row.feeLoading = false
|
||||
})
|
||||
}
|
||||
|
||||
function date(value) { return value ? String(value).slice(0, 10) : '-' }
|
||||
function money(value) { const num = Number(value); return Number.isNaN(num) ? '-' : num.toFixed(2) }
|
||||
function statusText(value) { return arEnumLabel(AR_BILL_STATUS_OPTIONS, value) }
|
||||
@@ -75,5 +145,7 @@ function mask(value) { if (!value) return '-'; return value.length <= 4 ? '****'
|
||||
.section-title::before { content: ''; width: 3px; height: 15px; border-radius: 2px; background: var(--el-color-primary); }
|
||||
.export-title { justify-content: space-between; }
|
||||
.export-title::before { margin-right: auto; }
|
||||
.detail-pagination { justify-content: flex-end; margin: 12px 0 4px; }
|
||||
.fee-panel { min-height: 54px; padding: 4px 12px 8px 42px; background: #fafafa; }
|
||||
.fee-table { background: #fafafa; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user