diff --git a/src/api/purchase/purchasingAccept.ts b/src/api/purchase/purchasingAccept.ts index eaaf2ad..9ea8940 100644 --- a/src/api/purchase/purchasingAccept.ts +++ b/src/api/purchase/purchasingAccept.ts @@ -124,6 +124,20 @@ export function canFillForm(purchaseId: string) { }) } +/** + * 下载履约验收模板(根据金额判断使用down/up目录) + * @param purchaseId 采购申请ID + * @returns Promise - 模板文件 blob + */ +export function downloadTemplate(purchaseId: string) { + return request({ + url: '/purchase/purchasingAccept/download-template', + method: 'get', + params: { purchaseId }, + responseType: 'blob' + }) +} + /** * 根据品目类型获取验收项配置 */ diff --git a/src/views/purchase/purchasingrequisition/accept/AcceptBatchForm.vue b/src/views/purchase/purchasingrequisition/accept/AcceptBatchForm.vue index 3557846..a3a2f06 100644 --- a/src/views/purchase/purchasingrequisition/accept/AcceptBatchForm.vue +++ b/src/views/purchase/purchasingrequisition/accept/AcceptBatchForm.vue @@ -19,7 +19,7 @@ - + 下载{{ lyysTemplateLabel }} @@ -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 = { @@ -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() const templateFiles = ref([]) 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', // 固定为上传模式 diff --git a/src/views/purchase/purchasingrequisition/accept/PurchasingAcceptModal.vue b/src/views/purchase/purchasingrequisition/accept/PurchasingAcceptModal.vue index 6cd1b96..a869e2a 100644 --- a/src/views/purchase/purchasingrequisition/accept/PurchasingAcceptModal.vue +++ b/src/views/purchase/purchasingrequisition/accept/PurchasingAcceptModal.vue @@ -63,6 +63,7 @@ :readonly="false" :purchase-id="String(purchaseId)" :project-type="acceptProjectType" + :budget="applyInfo?.budget" :batch-num="b.batch" />