✨ 支持应收账单选择模板并导出产品汇总与运费明细

This commit is contained in:
caojia
2026-11-18 15:59:08 +08:00
parent b4569e5c15
commit 69491b07d9
21 changed files with 1973 additions and 961 deletions
+6 -2
View File
@@ -88,8 +88,12 @@ export function getArBillVoidTask(taskId) {
return request({ url: '/ar/bill/void/task/' + taskId, method: 'get' })
}
export function exportArBill(arBillId) {
return request({ url: '/ar/bill/' + arBillId + '/export', method: 'post' })
export function listArBillExportTemplates(arBillId) {
return request({ url: '/ar/bill/' + arBillId + '/export-templates', method: 'get' })
}
export function exportArBill(arBillId, data) {
return request({ url: '/ar/bill/' + arBillId + '/export', method: 'post', data })
}
export function listArBillExports(arBillId) {
@@ -59,7 +59,7 @@
@size-change="handleDetailSizeChange"
/>
<div class="section-title export-title"><span>导出历史</span><el-button size="small" type="primary" plain icon="Download" v-hasPermi="['ar:bill:export']" :loading="exporting" :disabled="exporting" @click="$emit('export')">{{ exporting ? '生成中' : '导出账单明细' }}</el-button></div>
<div class="section-title export-title"><span>导出历史</span><el-button size="small" type="primary" plain icon="Download" v-hasPermi="['ar:bill:export']" @click="$emit('export')">导出账单明细</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" />
@@ -87,7 +87,6 @@ const detailPageNum = ref(1)
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 => {
@@ -0,0 +1,86 @@
<template>
<el-dialog :model-value="modelValue" title="导出账单" width="480px" append-to-body
:close-on-click-modal="false" :close-on-press-escape="!submitting" :show-close="!submitting"
@update:model-value="$emit('update:modelValue', $event)">
<el-form label-width="88px" v-loading="loading">
<el-form-item label="账单号">
<span>{{ bill?.billNo || '-' }}</span>
</el-form-item>
<el-form-item label="导出模板" required>
<el-select v-model="templateId" placeholder="请选择导出模板" :disabled="loading || submitting" style="width: 100%">
<el-option v-for="item in templates" :key="item.templateId" :value="item.templateId"
:label="item.templateName" />
</el-select>
</el-form-item>
</el-form>
<div v-if="loadError" class="template-load-error">
<span>模板加载失败</span>
<el-button link type="primary" @click="loadTemplates">重新加载</el-button>
</div>
<el-alert v-else-if="!loading && !templates.length" title="暂无可用的账单导出模板" type="info" :closable="false" />
<template #footer>
<el-button :disabled="submitting" @click="$emit('update:modelValue', false)">取消</el-button>
<el-button type="primary" :loading="submitting" :disabled="loading || !templateId" @click="submit">开始导出</el-button>
</template>
</el-dialog>
</template>
<script setup>
import { exportArBill, listArBillExportTemplates } from '@/api/ar/bill'
const props = defineProps({ modelValue: Boolean, bill: { type: Object, default: null } })
const emit = defineEmits(['update:modelValue', 'success', 'submitting'])
const templates = ref([])
const templateId = ref()
const loading = ref(false)
const loadError = ref(false)
const submitting = ref(false)
let requestSerial = 0
watch(() => [props.modelValue, props.bill?.arBillId], ([open]) => {
requestSerial += 1
if (open) loadTemplates()
})
async function loadTemplates() {
const billId = props.bill?.arBillId
if (!billId) return
const serial = ++requestSerial
templates.value = []
templateId.value = undefined
loadError.value = false
loading.value = true
try {
const res = await listArBillExportTemplates(billId)
if (serial !== requestSerial) return
templates.value = res.data || []
templateId.value = templates.value.find(item => String(item.isDefault) === '1')?.templateId
?? templates.value[0]?.templateId
} catch (_) {
if (serial === requestSerial) loadError.value = true
} finally {
if (serial === requestSerial) loading.value = false
}
}
async function submit() {
if (submitting.value || loading.value || !templateId.value || !props.bill?.arBillId) return
const bill = props.bill
submitting.value = true
emit('submitting', true)
try {
const res = await exportArBill(bill.arBillId, { templateId: templateId.value })
emit('update:modelValue', false)
emit('success', { bill, exportTask: res.data })
} catch (_) {
// 请求错误统一由 request 封装提示,保留弹窗中的选择便于重试。
} finally {
submitting.value = false
emit('submitting', false)
}
}
</script>
<style scoped>
.template-load-error { display: flex; align-items: center; gap: 12px; color: var(--el-color-danger); }
</style>
+17 -14
View File
@@ -60,6 +60,8 @@
<bill-detail v-model="detailOpen" :detail="detail" :loading="detailLoading" @download="downloadExport" @export="exportBill(detail)" />
<generate-bill-dialog v-model="generateOpen" @success="handleGenerateSuccess" />
<export-bill-dialog v-model="exportOpen" :bill="exportBillTarget" @success="handleExportSuccess"
@submitting="exportSubmittingCount = $event ? 1 : 0" />
<el-dialog v-model="cancelConfirmVisible" title="取消账单生成" width="420px" append-to-body
:close-on-click-modal="false" :close-on-press-escape="!cancelConfirmLoading"
:show-close="!cancelConfirmLoading" @closed="handleCancelConfirmClosed">
@@ -75,9 +77,10 @@
<script setup name="ArBill">
import { saveAs } from 'file-saver'
import { listArBillCustomerOptions, listArBill, getArBill, confirmArBill, voidArBill, getArBillVoidTask, exportArBill, getArBillExport, downloadArBillExport, getArBillExportDownloadInfo, getArBillGenerateTask, listActiveArBillGenerateTasks, cancelArBillGenerateTask, retryArBillGenerateTask } from '@/api/ar/bill'
import { listArBillCustomerOptions, listArBill, getArBill, confirmArBill, voidArBill, getArBillVoidTask, getArBillExport, downloadArBillExport, getArBillExportDownloadInfo, getArBillGenerateTask, listActiveArBillGenerateTasks, cancelArBillGenerateTask, retryArBillGenerateTask } from '@/api/ar/bill'
import BillDetail from './components/BillDetail.vue'
import GenerateBillDialog from './components/GenerateBillDialog.vue'
import ExportBillDialog from './components/ExportBillDialog.vue'
import { AR_BILL_STATUS, AR_BILL_STATUS_OPTIONS, AR_BILL_STATUS_TYPES } from '@/constants/ar/bill'
const { proxy } = getCurrentInstance()
@@ -102,6 +105,8 @@ const voidPollTimers = new Map()
let voidPageClosed = false
const openedBillId = ref()
const generateOpen = ref(false)
const exportOpen = ref(false)
const exportBillTarget = ref(null)
// 任务可能在首次轮询前就完成,至少展示一段时间让用户感知到“正在生成”。
const MIN_GENERATE_STATUS_VISIBLE_MS = 1800
// 每个任务独立保存轮询、收尾定时器和开始展示时间,避免多个账单任务互相覆盖。
@@ -377,19 +382,17 @@ function pollVoidTask(billId, taskId) {
}
function exportBill(row) {
if (!row?.arBillId) return
exportSubmittingCount.value += 1
exportArBill(row.arBillId).then(res => {
const exportTask = res.data
tableRef.value?.refresh()
// 导出同样是异步任务;打开详情展示“生成中”状态及完成后的下载入口。
viewBill(row)
if (exportTask?.exportId) {
exportTasks.set(exportTask.exportId, exportTask)
startExportPolling(exportTask.exportId)
}
}).finally(() => {
exportSubmittingCount.value = Math.max(0, exportSubmittingCount.value - 1)
})
exportBillTarget.value = row
exportOpen.value = true
}
function handleExportSuccess({ bill, exportTask }) {
tableRef.value?.refresh()
viewBill(bill)
if (exportTask?.exportId) {
exportTasks.set(exportTask.exportId, exportTask)
startExportPolling(exportTask.exportId)
}
}
onMounted(loadActiveGenerateTasks)