合同打印增加
parent
08179a9f7f
commit
cd17dd9d5f
|
|
@ -147,9 +147,14 @@ export const getOrgInfo = async (params) => {
|
||||||
|
|
||||||
// 打印合同
|
// 打印合同
|
||||||
export const printContract = async (id: number) => {
|
export const printContract = async (id: number) => {
|
||||||
return await request.put({ url: `/crm/contract/print?id=${id}` })
|
return await request.get({
|
||||||
|
url: `/crm/contract/print`,
|
||||||
|
params: { contractId: id },
|
||||||
|
responseType: 'blob' // 必须加这个才能下载文件
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==================== 子表(CRM 合同产品关联) ====================
|
// ==================== 子表(CRM 合同产品关联) ====================
|
||||||
|
|
||||||
// 获得CRM 合同产品关联列表
|
// 获得CRM 合同产品关联列表
|
||||||
|
|
|
||||||
|
|
@ -446,10 +446,45 @@ const handleSubmit = async (row: ContractApi.ContractVO) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPrintContract = async (row: ContractApi.ContractVO) => {
|
const onPrintContract = async (row: ContractApi.ContractVO) => {
|
||||||
await message.confirm(`您确定打印【${row.name}】合同吗?`)
|
try {
|
||||||
await ContractApi.printContract(row.id)
|
await message.confirm(`您确定打印【${row.name}】合同吗?`)
|
||||||
message.success('提交审核成功!')
|
const res = await ContractApi.printContract(row.id)
|
||||||
await getList()
|
|
||||||
|
if (!res) {
|
||||||
|
throw new Error('返回的合同文件为空')
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentType = res.type.toLowerCase()
|
||||||
|
let fileType = 'application/msword' // 默认使用 .doc 的 MIME 类型
|
||||||
|
let extension = '.doc'
|
||||||
|
|
||||||
|
if (contentType.includes('wordprocessingml')) {
|
||||||
|
fileType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' // 对应 .docx 文件的 MIME 类型
|
||||||
|
extension = '.docx'
|
||||||
|
}
|
||||||
|
// 创建 blob 对象并设置文件类型
|
||||||
|
const blob = new Blob([res], { type: fileType })
|
||||||
|
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
const disposition = res.headers['content-disposition']
|
||||||
|
let fileName = '合同.docx'
|
||||||
|
if (disposition && disposition.includes('filename=')) {
|
||||||
|
const match = disposition.match(/filename="?([^"]+)"?/)
|
||||||
|
if (match?.[1]) {
|
||||||
|
fileName = decodeURIComponent(match[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
link.click()
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
|
||||||
|
message.success('提交审核成功!')
|
||||||
|
await getList()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('合同下载失败', error)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 查看审批 */
|
/** 查看审批 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue