<template>
|
<div>
|
<vol-box v-model="showDetialBox" :lazy="true" width="500px" :padding="15" title="">
|
<!-- 打印专用容器 -->
|
<div id="printContainer" style="position: absolute; left: -9999px">
|
<div class="print-page" v-for="(item, index) in printData" :key="index">
|
<div class="material-card">
|
<div class="dual-column header-section">
|
<div class="header">卓力能物料标识卡(小包)</div>
|
<VueQrcode :value="generateQr(item)" :size="60" class="qrcode" />
|
</div>
|
<div class="content">
|
<div class="row dual-column">
|
<div class="column">
|
<span class="label">料号</span>
|
<span class="value code-value full-width">{{ item.materialCode }}</span>
|
</div>
|
<div class="column">
|
<span class="label">供应商编码</span>
|
<span class="value full-width">{{ item.supplierCode }}</span>
|
</div>
|
</div>
|
|
<div class="row dual-column">
|
<div class="column">
|
<span class="label">品名</span>
|
<span class="value full-width">{{ item.materialName }}</span>
|
</div>
|
<div class="column">
|
<span class="label">采购单号</span>
|
<span class="value full-width">{{ item.purchaseOrderNo }}</span>
|
</div>
|
</div>
|
|
<div class="row dual-column">
|
<div class="column">
|
<span class="label">规格</span>
|
<span class="value full-width">{{ item.specification }}</span>
|
</div>
|
<div class="column">
|
<span class="label">数量/总数</span>
|
<span class="value full-width">{{ item.quantityTotal }}</span>
|
</div>
|
</div>
|
|
<div class="row dual-column">
|
<div class="column">
|
<span class="label">批号</span>
|
<span class="value full-width">{{ item.batchNumber }}</span>
|
</div>
|
<div class="column">
|
<span class="label">批次</span>
|
<span class="value full-width">{{ item.batch }}</span>
|
</div>
|
</div>
|
|
<div class="row dual-column">
|
<div class="column">
|
<span class="label">厂区</span>
|
<span class="value full-width">{{ item.factory }}</span>
|
</div>
|
<div class="column">
|
<span class="label">日期</span>
|
<span class="value full-width">{{ item.date }}</span>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
|
<!-- 预览区域保持不变 -->
|
<div id="previewContent" class="preview-container">
|
<div class="preview-header">卓力能物料标识卡(小包) - 预览 (共{{ printData.length }}个)</div>
|
<div class="preview-scroll">
|
<div v-for="(item, idx) in printData" :key="idx" class="preview-card">
|
<div class="dual-column preview-card-header-qrcode">
|
<div class="preview-card-header">卓力能物料标识卡(小包)</div>
|
<VueQrcode :value="generateQr(item)" :size="40" class="qrcode-preview" />
|
</div>
|
<div class="preview-wrapper">
|
<div class="content-preview">
|
<div class="row-preview dual-column">
|
<div class="column-preview">
|
<span class="label-preview">料号</span>
|
<span class="value-preview code-value full-width">{{ item.materialCode }}</span>
|
</div>
|
<div class="column-preview">
|
<span class="label-preview">供应商编码</span>
|
<span class="value-preview full-width">{{ item.supplierCode }}</span>
|
</div>
|
</div>
|
|
<div class="row-preview dual-column">
|
<div class="column-preview">
|
<span class="label-preview">品名</span>
|
<span class="value-preview full-width">{{ item.materialName }}</span>
|
</div>
|
<div class="column-preview">
|
<span class="label-preview">采购单号</span>
|
<span class="value-preview full-width">{{ item.purchaseOrderNo }}</span>
|
</div>
|
</div>
|
|
<div class="row-preview dual-column">
|
<div class="column-preview">
|
<span class="label-preview">规格</span>
|
<span class="value-preview full-width">{{ item.specification }}</span>
|
</div>
|
<div class="column-preview">
|
<span class="label-preview">数量/总数</span>
|
<span class="value-preview full-width">{{ item.quantityTotal }}</span>
|
</div>
|
</div>
|
|
<div class="row-preview dual-column">
|
<div class="column-preview">
|
<span class="label-preview">批号</span>
|
<span class="value-preview full-width">{{ item.batchNumber }}</span>
|
</div>
|
<div class="column-preview">
|
<span class="label-preview">批次</span>
|
<span class="value-preview full-width">{{ item.batch }}</span>
|
</div>
|
</div>
|
|
<div class="row-preview dual-column">
|
<div class="column-preview">
|
<span class="label-preview">厂区</span>
|
<span class="value-preview full-width">{{ item.factory }}</span>
|
</div>
|
<div class="column-preview">
|
<span class="label-preview">日期</span>
|
<span class="value-preview full-width">{{ item.date }}</span>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
|
<template #footer>
|
<div class="footer-actions">
|
<span class="print-count">共 {{ printData.length }} 个物料卡待打印</span>
|
<div>
|
<el-button type="primary" size="small" @click="print">打印全部</el-button>
|
<el-button type="danger" size="small" @click="showDetialBox = false">关闭</el-button>
|
</div>
|
</div>
|
</template>
|
</vol-box>
|
</div>
|
</template>
|
|
<script>
|
import VolBox from '@/components/basic/VolBox.vue'
|
import VueQrcode from 'vue-qrcode'
|
|
export default {
|
components: { VolBox, VueQrcode },
|
data() {
|
return {
|
showDetialBox: false,
|
printData: []
|
}
|
},
|
methods: {
|
generateQr(item) {
|
return `${item.batchNumber}`
|
},
|
|
open(rows) {
|
this.showDetialBox = true
|
this.printData = Array.isArray(rows) ? rows : [rows]
|
console.log('打印数据:', this.printData);
|
},
|
|
async print() {
|
if (this.printData.length === 0) {
|
this.$message.warning('没有可打印的数据')
|
return
|
}
|
|
this.$nextTick(() => {
|
try {
|
const printContent = document.getElementById('printContainer').innerHTML
|
const printWindow = window.open('', '_blank', 'width=800,height=600,scrollbars=yes')
|
|
if (!printWindow) {
|
this.$message.error('无法打开打印窗口,请检查浏览器弹窗设置')
|
return
|
}
|
|
printWindow.document.write(`
|
<!DOCTYPE html>
|
<html>
|
<head>
|
<meta charset="UTF-8">
|
<title>物料标识卡打印 - 共${this.printData.length}个</title>
|
<style>
|
* {
|
margin: 0;
|
padding: 0;
|
box-sizing: border-box;
|
-webkit-print-color-adjust: exact !important;
|
print-color-adjust: exact !important;
|
color-adjust: exact !important;
|
}
|
|
body {
|
font-family: "Microsoft YaHei", "SimHei", Arial, sans-serif;
|
background: white !important;
|
margin: 0 !important;
|
padding: 0 !important;
|
width: 80mm !important;
|
}
|
|
.qrcode {
|
width: 15mm !important;
|
height: 15mm !important;
|
display: block;
|
}
|
|
.qrcode canvas {
|
width: 15mm !important;
|
height: 15mm !important;
|
image-rendering: -webkit-optimize-contrast;
|
image-rendering: crisp-edges;
|
}
|
|
@media print {
|
@page {
|
size: 80mm 60mm !important;
|
margin: 0 !important;
|
padding: 0 !important;
|
}
|
|
body {
|
width: 80mm !important;
|
height: 60mm !important;
|
margin: 0 !important;
|
padding: 0 !important;
|
background: white !important;
|
}
|
|
.print-page {
|
width: 80mm !important;
|
height: 60mm !important;
|
page-break-after: always !important;
|
margin: 0 !important;
|
padding: 1mm !important;
|
display: block !important;
|
background: white !important;
|
}
|
|
.print-page:last-child {
|
page-break-after: avoid !important;
|
}
|
|
.material-card {
|
width: 78mm !important;
|
height: 58mm !important;
|
border: 0.5mm solid #000 !important;
|
padding: 1.5mm !important;
|
box-sizing: border-box !important;
|
position: relative !important;
|
background: white !important;
|
font-family: "Microsoft YaHei", "SimHei", Arial, sans-serif !important;
|
}
|
|
.header-section {
|
display: flex !important;
|
justify-content: space-between !important;
|
align-items: center !important;
|
margin-bottom: 1.5mm !important;
|
padding-bottom: 1mm !important;
|
border-bottom: 0.3mm solid #000 !important;
|
}
|
|
.header {
|
font-size: 4mm !important;
|
font-weight: bold !important;
|
white-space: nowrap !important;
|
}
|
|
.content {
|
height: calc(100% - 10mm) !important;
|
position: relative !important;
|
}
|
|
.row {
|
display: flex !important;
|
margin-bottom: 1.2mm !important;
|
min-height: 6.5mm !important;
|
align-items: stretch !important;
|
}
|
|
.dual-column {
|
display: flex !important;
|
justify-content: space-between !important;
|
}
|
|
.column {
|
flex: 1 !important;
|
display: flex !important;
|
align-items: center !important;
|
min-height: 5mm !important;
|
}
|
|
.column:first-child {
|
margin-right: 2.5mm !important;
|
}
|
|
.label {
|
flex: 0 0 8mm !important;
|
white-space: nowrap !important;
|
font-size: 2.5mm !important;
|
line-height: 1.3 !important;
|
}
|
|
.value {
|
flex: 1 !important;
|
overflow: hidden !important;
|
text-overflow: ellipsis !important;
|
white-space: normal !important;
|
word-break: break-all !important;
|
word-wrap: break-word !important;
|
min-height: 4mm !important;
|
font-size: 2.5mm !important;
|
line-height: 1.3 !important;
|
border-bottom: none !important;
|
padding: 0.5mm !important;
|
}
|
|
.full-width {
|
display: block !important;
|
white-space: normal !important;
|
word-break: break-all !important;
|
word-wrap: break-word !important;
|
line-height: 1.3 !important;
|
}
|
|
.code-value {
|
font-weight: bold !important;
|
}
|
}
|
</style>
|
</head>
|
<body>
|
${printContent}
|
<script>
|
window.onload = function() {
|
setTimeout(() => {
|
const canvases = document.querySelectorAll('canvas');
|
canvases.forEach(canvas => {
|
canvas.setAttribute('width', '60');
|
canvas.setAttribute('height', '60');
|
canvas.style.width = '15mm';
|
canvas.style.height = '15mm';
|
});
|
window.print();
|
setTimeout(() => { window.close(); }, 500);
|
}, 800);
|
};
|
<\/script>
|
</body>
|
</html>
|
`)
|
|
printWindow.document.close()
|
} catch (error) {
|
console.error('打印错误:', error)
|
this.$message.error('打印失败: ' + error.message)
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.qrcode {
|
width: 60px;
|
height: 60px;
|
display: block;
|
}
|
|
.qrcode-preview {
|
width: 40px;
|
height: 40px;
|
display: block;
|
}
|
|
.preview-container {
|
max-height: 500px;
|
overflow: hidden;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.preview-header {
|
text-align: center;
|
font-size: 16px;
|
font-weight: bold;
|
margin-bottom: 10px;
|
padding: 8px;
|
background: #f0f0f0;
|
border-radius: 4px;
|
}
|
|
.preview-scroll {
|
max-height: 400px;
|
overflow-y: auto;
|
padding: 10px;
|
border: 1px solid #e0e0e0;
|
border-radius: 4px;
|
background: #f9f9f9;
|
}
|
|
.preview-card {
|
width: 320px;
|
height: 240px;
|
margin: 0 auto 15px auto;
|
padding: 8px;
|
border: 2px solid #000;
|
font-family: 'Microsoft YaHei', sans-serif;
|
box-sizing: border-box;
|
background: white;
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
position: relative;
|
}
|
|
.preview-card:last-child {
|
margin-bottom: 0;
|
}
|
|
.preview-card-header {
|
font-size: 14px;
|
font-weight: bold;
|
white-space: nowrap;
|
}
|
|
.preview-wrapper {
|
position: relative;
|
height: calc(100% - 30px);
|
}
|
|
.content-preview {
|
width: 100%;
|
height: 100%;
|
}
|
|
.row-preview {
|
margin-bottom: 6px;
|
min-height: 24px;
|
display: flex;
|
align-items: center;
|
}
|
|
.dual-column {
|
display: flex;
|
justify-content: space-between;
|
}
|
|
.column-preview {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
min-height: 22px;
|
}
|
|
.column-preview:first-child {
|
margin-right: 8px;
|
}
|
|
.label-preview {
|
font-weight: bold;
|
flex: 0 0 30px;
|
white-space: nowrap;
|
font-size: 12px;
|
line-height: 1.2;
|
}
|
|
.value-preview {
|
flex: 1;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
font-size: 10px;
|
padding-bottom: 2px;
|
line-height: 1.2;
|
font-weight: normal;
|
}
|
|
.code-value {
|
font-weight: bold;
|
}
|
|
.full-width {
|
display: block;
|
white-space: normal;
|
word-break: break-all !important;
|
line-height: 1.2;
|
font-size: 11px;
|
min-height: auto;
|
word-wrap: break-word !important;
|
}
|
|
.preview-card-header-qrcode {
|
display: flex;
|
justify-content: space-between;
|
align-items: flex-start;
|
margin-bottom: 8px;
|
border-bottom: 2px solid #000;
|
padding-bottom: 4px;
|
}
|
|
.footer-actions {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
width: 100%;
|
}
|
|
.print-count {
|
font-size: 14px;
|
color: #409eff;
|
font-weight: bold;
|
}
|
</style>
|