This commit is contained in:
吴红兵
2026-03-05 01:20:15 +08:00
parent c3daa41f10
commit 1e6d6ae981
3 changed files with 46 additions and 3 deletions

View File

@@ -124,6 +124,20 @@ export function canFillForm(purchaseId: string) {
})
}
/**
* 下载履约验收模板根据金额判断使用down/up目录
* @param purchaseId 采购申请ID
* @returns Promise<Blob> - 模板文件 blob
*/
export function downloadTemplate(purchaseId: string) {
return request({
url: '/purchase/purchasingAccept/download-template',
method: 'get',
params: { purchaseId },
responseType: 'blob'
})
}
/**
* 根据品目类型获取验收项配置
*/

View File

@@ -19,7 +19,7 @@
<el-col :span="12" class="mb20">
<el-form-item label="履约验收文件" prop="templateFileIds">
<upload-file v-model="templateFiles" :limit="1" :file-type="['pdf']" :data="{ purchaseId: purchaseId || '', fileType: '110' }" upload-file-url="/purchase/purchasingfiles/upload" :disabled="readonly" />
<el-link v-if="!readonly" type="primary" :href="lyysTemplateUrl" :download="lyysTemplateDownloadName" target="_blank" style="margin-top: 8px; display: inline-flex; align-items: center;">
<el-link v-if="!readonly" type="primary" @click="handleDownloadTemplate" style="margin-top: 8px; display: inline-flex; align-items: center;">
<el-icon><Download /></el-icon>
<span style="margin-left: 4px;">下载{{ lyysTemplateLabel }}</span>
</el-link>
@@ -39,7 +39,9 @@
import { ref, reactive, computed, watch, onMounted } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import { Download } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import UploadFile from "/@/components/Upload/index.vue";
import { downloadTemplate } from "/@/api/purchase/purchasingAccept";
/** 项目类型 A:货物 B:工程 C:服务 */
const LYYS_TEMPLATE_MAP: Record<string, { label: string }> = {
@@ -54,6 +56,8 @@ const props = defineProps<{
purchaseId?: string
/** 项目类型 A:货物 B:工程 C:服务,用于模版下载 */
projectType?: string
/** 预算金额,用于判断模板目录 */
budget?: number
batchNum?: number
}>()
@@ -64,9 +68,33 @@ const formRef = ref<FormInstance>()
const templateFiles = ref<any[]>([])
const projectTypeKey = computed(() => (props.projectType === 'A' || props.projectType === 'B' || props.projectType === 'C' ? props.projectType : 'A'))
const lyysTemplateLabel = computed(() => LYYS_TEMPLATE_MAP[projectTypeKey.value]?.label || LYYS_TEMPLATE_MAP.A.label)
const lyysTemplateLabel = computed(() => {
const amountLabel = (props.budget && props.budget >= 50000) ? '(≥5万)' : '(<5万)'
return LYYS_TEMPLATE_MAP[projectTypeKey.value]?.label + amountLabel || LYYS_TEMPLATE_MAP.A.label + amountLabel
})
const lyysTemplateDownloadName = computed(() => `${lyysTemplateLabel.value}.docx`)
const lyysTemplateUrl = computed(() => `/templates/lyys-template-${projectTypeKey.value}.docx`)
/** 下载模板 - 调用后台接口 */
const handleDownloadTemplate = async () => {
if (!props.purchaseId) {
ElMessage.warning('采购ID不存在')
return
}
try {
const res = await downloadTemplate(props.purchaseId)
const blob = res as unknown as Blob
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = lyysTemplateDownloadName.value
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
} catch (e: any) {
ElMessage.error(e?.message || '下载模板失败')
}
}
const form = reactive({
acceptType: '2', // 固定为上传模式

View File

@@ -63,6 +63,7 @@
:readonly="false"
:purchase-id="String(purchaseId)"
:project-type="acceptProjectType"
:budget="applyInfo?.budget"
:batch-num="b.batch"
/>
</div>