履约验收
This commit is contained in:
@@ -135,14 +135,22 @@ export function getAcceptanceItems(acceptanceType: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载履约验收模板
|
* 导出履约验收评价表(仅填写模式可导出)
|
||||||
|
* 单期返回 docx,exportAll=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({
|
return request({
|
||||||
url: '/purchase/purchasingAccept/export-performance-acceptance-template',
|
url: '/purchase/purchasingAccept/export-performance-acceptance-template',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: { purchaseId, batch },
|
params,
|
||||||
responseType: 'blob' // 重要:用于文件下载
|
responseType: 'blob'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,16 +83,22 @@
|
|||||||
<template #footer>
|
<template #footer>
|
||||||
<span>
|
<span>
|
||||||
<el-button @click="handleClose">关 闭</el-button>
|
<el-button @click="handleClose">关 闭</el-button>
|
||||||
<!-- 下载履约验收模板按钮 -->
|
<!-- 仅填写履约验收评价表模式可导出;单期 docx,全部期数 zip -->
|
||||||
<el-dropdown split-button type="primary" @click="handleDownloadTemplate" @command="handleDownloadTemplateCommand">
|
<el-dropdown
|
||||||
下载履约模板
|
v-if="showExportDropdown"
|
||||||
|
split-button
|
||||||
|
type="primary"
|
||||||
|
@click="handleDownloadTemplate"
|
||||||
|
@command="handleDownloadTemplateCommand"
|
||||||
|
>
|
||||||
|
导出履约验收评价表
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
<el-dropdown-item command="current" :disabled="!activeBatchId">
|
<el-dropdown-item command="current" :disabled="!canExportCurrentBatch">
|
||||||
下载当前期({{ activeTab }}期)
|
下载当前期({{ activeTab }}期)
|
||||||
</el-dropdown-item>
|
</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-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</template>
|
</template>
|
||||||
@@ -169,6 +175,17 @@ const activeBatchId = computed(() => {
|
|||||||
/** 项目类型 A:货物 B:工程 C:服务,用于批次表单模版下载 */
|
/** 项目类型 A:货物 B:工程 C:服务,用于批次表单模版下载 */
|
||||||
const acceptProjectType = computed(() => applyInfo.value?.projectType || rowProjectType.value || 'A')
|
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 getPreviousBatchesTeams = (batchNum: number) => {
|
||||||
const list: { batch: number; team: any[] }[] = []
|
const list: { batch: number; team: any[] }[] = []
|
||||||
for (let n = 1; n < batchNum; n++) {
|
for (let n = 1; n < batchNum; n++) {
|
||||||
@@ -404,48 +421,61 @@ const handleClose = () => {
|
|||||||
emit('refresh')
|
emit('refresh')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载履约验收模板
|
// 导出履约验收评价表(仅填写模式可导出)
|
||||||
const handleDownloadTemplate = async () => {
|
const handleDownloadTemplate = async () => {
|
||||||
if (!purchaseId.value) {
|
if (!purchaseId.value) {
|
||||||
useMessage().error('请先选择采购项目')
|
useMessage().error('请先选择采购项目')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!canExportCurrentBatch.value) {
|
||||||
// 默认下载当前期
|
useMessage().error('仅填写履约验收评价表模式可导出,请先选择该模式并保存')
|
||||||
|
return
|
||||||
|
}
|
||||||
await downloadTemplateForBatch(Number(activeTab.value))
|
await downloadTemplateForBatch(Number(activeTab.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理下拉菜单命令
|
|
||||||
const handleDownloadTemplateCommand = async (command: string) => {
|
const handleDownloadTemplateCommand = async (command: string) => {
|
||||||
if (!purchaseId.value) {
|
if (!purchaseId.value) {
|
||||||
useMessage().error('请先选择采购项目')
|
useMessage().error('请先选择采购项目')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command === 'current') {
|
if (command === 'current') {
|
||||||
|
if (!canExportCurrentBatch.value) {
|
||||||
|
useMessage().error('当前期未选择填写履约验收评价表模式,无法导出')
|
||||||
|
return
|
||||||
|
}
|
||||||
await downloadTemplateForBatch(Number(activeTab.value))
|
await downloadTemplateForBatch(Number(activeTab.value))
|
||||||
} else if (command === 'all') {
|
} else if (command === 'all') {
|
||||||
// 下载全部期数的模板
|
if (!canExportAllBatches.value) {
|
||||||
for (const batch of batches.value) {
|
useMessage().error('没有填写模式的分期可导出')
|
||||||
await downloadTemplateForBatch(batch.batch)
|
return
|
||||||
}
|
}
|
||||||
useMessage().success(`已触发${batches.value.length}期模板下载`)
|
await downloadAllBatchesAsZip()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 为指定批次下载模板
|
|
||||||
const downloadTemplateForBatch = async (batchNum: number) => {
|
const downloadTemplateForBatch = async (batchNum: number) => {
|
||||||
try {
|
try {
|
||||||
const response = await downloadPerformanceAcceptanceTemplate(String(purchaseId.value), batchNum)
|
const response = await downloadPerformanceAcceptanceTemplate(String(purchaseId.value), batchNum)
|
||||||
|
const fileName = `履约验收表-${purchaseId.value}-第${batchNum}期.docx`
|
||||||
// 使用项目中现有的工具函数处理文件下载
|
|
||||||
const fileName = `履约验收表-${purchaseId.value}-第${batchNum}期-${new Date().getTime()}.docx`;
|
|
||||||
handleBlobFile(response, fileName)
|
handleBlobFile(response, fileName)
|
||||||
|
useMessage().success(`第${batchNum}期导出成功`)
|
||||||
useMessage().success(`第${batchNum}期履约模板下载成功`)
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('下载模板失败:', error)
|
console.error('导出失败:', error)
|
||||||
useMessage().error(error?.msg || '下载履约模板失败')
|
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 || '导出全部期数失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user