打印标签

This commit is contained in:
2024-12-11 18:47:47 +08:00
parent ff283141e0
commit a8026ff42b

View File

@@ -76,7 +76,8 @@
<el-button class="tool-box" color="#00aa00" icon="Upload" @click="handleExport"> 工单导出 </el-button> <el-button class="tool-box" color="#00aa00" icon="Upload" @click="handleExport"> 工单导出 </el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button class="tool-box" color="#E6A23C" icon="Printer" @click="handlePrint"> 工单打印 </el-button> <el-button class="tool-box" color="#E65100" icon="Printer" @click="handlePrint"> 打印所勾选标签
</el-button>
</el-col> </el-col>
<!-- <el-col :span="1.5"> <!-- <el-col :span="1.5">
<el-button class="tool-box" color="#55557f" v-hasPermi="['productManagement:proworkorder:list']" icon="Printer" @click="handlePrint"> 打印 </el-button> <el-button class="tool-box" color="#55557f" v-hasPermi="['productManagement:proworkorder:list']" icon="Printer" @click="handlePrint"> 打印 </el-button>
@@ -105,8 +106,11 @@
</el-row> --> </el-row> -->
<el-table :data="dataList" v-loading="loading" ref="table" border stripe size="small" <el-table :data="dataList" v-loading="loading" ref="table" border stripe size="small"
header-row-class-name="table-header" :cell-class-name="tableCellClassName" @sort-change="sortChange"> @selection-change="handleSelectionChange" header-row-class-name="table-header"
:cell-class-name="tableCellClassName" @sort-change="sortChange">
<el-table-column type="selection" align="center" width="55" />
<el-table-column type="index" width="50" align="center" /> <el-table-column type="index" width="50" align="center" />
<!-- <el-table-column prop="sort" label="编号" align="center" /> --> <!-- <el-table-column prop="sort" label="编号" align="center" /> -->
<el-table-column prop="workorder" label="工单号" align="center" width="160"> <el-table-column prop="workorder" label="工单号" align="center" width="160">
<template #default="scope"> <template #default="scope">
@@ -1163,15 +1167,18 @@ const printObj = {
} }
function handlePrint() { function handlePrint() {
PrintDialogShow.value = true PrintDialogShow.value = true
printList.value = getPrintList() printList.value = allList.value
exportWorkorderPDF(getPrintList()) exportWorkorderPDF(getPrintList())
} }
const selectList = ref([])
function handleSelectionChange(val) {
selectList.value = val
}
function getPrintList() { function getPrintList() {
const _list = allList.value.map(item => { const _list = selectList.value.map(item => {
return item.workorder return item.workorder
}) })
console.log(_list);
return _list return _list
// const groupedData = _list.reduce((acc, item) => { // const groupedData = _list.reduce((acc, item) => {
// const key = item.groupCode // const key = item.groupCode
@@ -1183,31 +1190,18 @@ function getPrintList() {
// }, {}) // }, {})
// return Object.values(groupedData) // return Object.values(groupedData)
} }
import axios from 'axios';
// 打印pdf // 打印pdf
async function exportWorkorderPDF(workorderArray) { async function exportWorkorderPDF(workorderArray) {
const url = '/mes/productManagement/ProWorkorder/print' let url = '/mes/productManagement/ProWorkorder/print?'
try { if (workorderArray.length === 0) {
const response = await axios.get(url, { proxy.$modal.msgError('无勾选工单打印')
params: { return
workorderArray
} }
}); for (let index = 0; index < workorderArray.length; index++) {
url += 'workorderArray=' + workorderArray[index] + '&'
// 下面是处理后端返回的数据
const filename = '工单打印';
const fileBlob = new Blob([response.data], { type: 'application/pdf' });
console.log(fileBlob);
// 创建一个隐藏的 a 标签来触发 PDF 下载
const link = document.createElement('a');
link.href = URL.createObjectURL(fileBlob);
link.download = filename;
link.click();
URL.revokeObjectURL(link.href); // 清除对象 URL
} catch (error) {
console.error('打印异常:', error);
} }
proxy.download(url, '工单标签打印模板')
return
} }
// 获取打印时间 // 获取打印时间
function getPrintTime() { function getPrintTime() {