履约验收

This commit is contained in:
吴红兵
2026-02-25 12:42:33 +08:00
parent b8af3ae5e0
commit 325ee491a9
2 changed files with 65 additions and 27 deletions

View File

@@ -135,14 +135,22 @@ export function getAcceptanceItems(acceptanceType: string) {
}
/**
* 下载履约验收模板
* 导出履约验收评价表(仅填写模式可导出)
* 单期返回 docxexportAll=true 时返回全部期数 zip
*/
export function downloadPerformanceAcceptanceTemplate(purchaseId: string, batch?: number) {
export function downloadPerformanceAcceptanceTemplate(
purchaseId: string,
batch?: number,
exportAll?: boolean
) {
const params: Record<string, any> = { purchaseId }
if (exportAll === true) params.exportAll = true
else if (batch != null) params.batch = batch
return request({
url: '/purchase/purchasingAccept/export-performance-acceptance-template',
method: 'get',
params: { purchaseId, batch },
responseType: 'blob' // 重要:用于文件下载
params,
responseType: 'blob'
})
}

View File

@@ -83,16 +83,22 @@
<template #footer>
<span>
<el-button @click="handleClose"> </el-button>
<!-- 下载履约验收模板按钮 -->
<el-dropdown split-button type="primary" @click="handleDownloadTemplate" @command="handleDownloadTemplateCommand">
下载履约模板
<!-- 仅填写履约验收评价表模式可导出单期 docx全部期数 zip -->
<el-dropdown
v-if="showExportDropdown"
split-button
type="primary"
@click="handleDownloadTemplate"
@command="handleDownloadTemplateCommand"
>
导出履约验收评价表
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="current" :disabled="!activeBatchId">
<el-dropdown-item command="current" :disabled="!canExportCurrentBatch">
下载当前期({{ activeTab }})
</el-dropdown-item>
<el-dropdown-item command="all" :disabled="batches.length === 0">
下载全部期数
<el-dropdown-item command="all" :disabled="!canExportAllBatches">
下载全部期数(zip)
</el-dropdown-item>
</el-dropdown-menu>
</template>
@@ -169,6 +175,17 @@ const activeBatchId = computed(() => {
/** 项目类型 A:货物 B:工程 C:服务,用于批次表单模版下载 */
const acceptProjectType = computed(() => applyInfo.value?.projectType || rowProjectType.value || 'A')
/** 当前期是否为「填写履约验收评价表」模式,仅此模式可导出 */
const canExportCurrentBatch = computed(() => batchForms[Number(activeTab.value)]?.acceptType === '1')
/** 是否存在任一批次为填写模式(可导出全部期数 zip */
const canExportAllBatches = computed(() =>
batches.value.some((b: any) => batchForms[b.batch]?.acceptType === '1')
)
/** 仅在有批次且至少一期为填写模式时显示导出下拉 */
const showExportDropdown = computed(
() => mainTab.value === 'batch' && batches.value.length > 0 && (canExportCurrentBatch.value || canExportAllBatches.value)
)
const getPreviousBatchesTeams = (batchNum: number) => {
const list: { batch: number; team: any[] }[] = []
for (let n = 1; n < batchNum; n++) {
@@ -404,48 +421,61 @@ const handleClose = () => {
emit('refresh')
}
// 下载履约验收模板
// 导出履约验收评价表(仅填写模式可导出)
const handleDownloadTemplate = async () => {
if (!purchaseId.value) {
useMessage().error('请先选择采购项目')
return
}
// 默认下载当前期
if (!canExportCurrentBatch.value) {
useMessage().error('仅填写履约验收评价表模式可导出,请先选择该模式并保存')
return
}
await downloadTemplateForBatch(Number(activeTab.value))
}
// 处理下拉菜单命令
const handleDownloadTemplateCommand = async (command: string) => {
if (!purchaseId.value) {
useMessage().error('请先选择采购项目')
return
}
if (command === 'current') {
if (!canExportCurrentBatch.value) {
useMessage().error('当前期未选择填写履约验收评价表模式,无法导出')
return
}
await downloadTemplateForBatch(Number(activeTab.value))
} else if (command === 'all') {
// 下载全部期数的模板
for (const batch of batches.value) {
await downloadTemplateForBatch(batch.batch)
if (!canExportAllBatches.value) {
useMessage().error('没有填写模式的分期可导出')
return
}
useMessage().success(`已触发${batches.value.length}期模板下载`)
await downloadAllBatchesAsZip()
}
}
// 为指定批次下载模板
const downloadTemplateForBatch = async (batchNum: number) => {
try {
const response = await downloadPerformanceAcceptanceTemplate(String(purchaseId.value), batchNum)
// 使用项目中现有的工具函数处理文件下载
const fileName = `履约验收表-${purchaseId.value}-第${batchNum}期-${new Date().getTime()}.docx`;
const fileName = `履约验收表-${purchaseId.value}-第${batchNum}期.docx`
handleBlobFile(response, fileName)
useMessage().success(`${batchNum}期履约模板下载成功`)
useMessage().success(`${batchNum}期导出成功`)
} catch (error: any) {
console.error('下载模板失败:', error)
useMessage().error(error?.msg || '下载履约模板失败')
console.error('导出失败:', error)
useMessage().error(error?.msg || '导出失败')
}
}
const downloadAllBatchesAsZip = async () => {
try {
const response = await downloadPerformanceAcceptanceTemplate(String(purchaseId.value), undefined, true)
const fileName = `履约验收表-${purchaseId.value}-全部期数.zip`
handleBlobFile(response, fileName)
const count = batches.value.filter((b: any) => batchForms[b.batch]?.acceptType === '1').length
useMessage().success(`已导出${count}期,请查收 zip 文件`)
} catch (error: any) {
console.error('导出全部期数失败:', error)
useMessage().error(error?.msg || '导出全部期数失败')
}
}