包装打印

dev
qiuhongwu 3 months ago
parent f5e3712080
commit ab5c9690e2

@ -2,16 +2,14 @@
<Dialog v-model="dialogVisible" title="打印预选">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="178px"
>
<el-form-item label="要打印的箱数量为:" prop="" style="display:flex;">
<el-form-item label="要打印的箱数量为:" prop="" style="display: flex">
<span> {{ minAmount }}</span>
</el-form-item>
<el-form-item label="打印范围选择:" prop="" style="margin-bottom:50px">
<select class="!w-240px" @change="handleChangeRange()" v-model="rangeval" >
<el-form-item label="打印范围选择:" prop="" style="margin-bottom: 50px">
<select class="!w-240px" @change="handleChangeRange()" v-model="rangeval">
<option v-for="range in ranges" :key="range.label" :value="range.label">{{
range.label
}}</option>
@ -25,13 +23,9 @@
<printDialog ref="printref" :minAmount="minAmount" :formData="formData" />
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { defaultProps, handleTree } from '@/utils/tree'
import * as ProjectOrderApi from '@/api/biz/projectorder'
import printDialog from './printDialog.vue'
defineOptions({ name: 'SystemDeptForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const formData: any = ref({
@ -40,11 +34,10 @@ const formData: any = ref({
/** 打开弹窗 */
const minAmount = ref()
const codes:any = ref()
const Ids:any = ref()
const codes: any = ref()
const vals: any = ref()
const open = async (code, val) => {
codes.value = code
Ids.value = val.id
dialogVisible.value = true
resetForm()
minAmount.value = undefined
@ -52,12 +45,13 @@ const open = async (code, val) => {
if (val.id) {
try {
const data = await ProjectOrderApi.getProjectOrderclauseDetail(val.id)
console.log('data:', data)
formData.value = data
data.forEach((item) => {
item.integer = Math.trunc(item.orderAmount / item.amount)
item.remainder = item.orderAmount - item.integer * item.amount
})
vals.value = data
minAmount.value = data.reduce((min, item) => Math.min(min, item.integer), data[0].integer)
console.log('最小的integer:', minAmount.value)
@ -74,7 +68,6 @@ const open = async (code, val) => {
}
defineExpose({ open }) // open
const submitForm = async () => {}
/** 重置表单 */
const resetForm = () => {}
@ -86,8 +79,7 @@ const printref = ref()
const rangeval = ref()
const handleChangeRange = () => {
console.log(rangeval.value)
printref.value.open(codes.value,Ids.value, rangeval.value)
printref.value.open(codes.value, vals.value, rangeval.value)
selectedRow.value = null
rangeval.value = null
}

@ -0,0 +1,239 @@
<template>
<Dialog
title="打印预览"
v-model="dialogVisible"
width="1000"
:before-close="(doClose) => beforeDialogClose(doClose)"
>
<!-- 打印预览 -->
<div class="print-wrap page" ref="print">
<div id="qrCodeContainer"></div>
</div>
<template #footer>
<!-- 打印 -->
<el-button @click="onPrint" type="primary">打印</el-button>
<el-button @click="outopen"></el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
// import { ref, reactive } from 'vue'
// import { betweenDay, dateFormatter, formatDate } from '@/utils/formatTime'
import QRCode from 'qrcode'
const dialogVisible = ref(false) //
const onPrint = () => {
// dom
const printNode = document.querySelector('.print-wrap')
if (!printNode) return
//
const newIframe: any = document.createElement('iframe')
newIframe.setAttribute(
'style',
'width:0px;height:0px;position:absolute;left:-9999px;top:-9999px;'
)
newIframe.setAttribute('align', 'center')
document.body.appendChild(newIframe)
//
let doc: any = null
doc = newIframe.contentWindow.document
doc.write(`
<style type="text/css">
/* 浏览器打印基本样式 */
.page {
width: 200mm;
min-height: 500px;
margin: auto;
text-align: center;
border: 1px #d3d3d3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
position: relative;
font-size: 14px !important;
}
.qrCodeContainer {
width: 200mm;
height: 69mm;
border: 1px #d3d3d3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
position: relative;
font-size: 14px !important;
}
@page {
size: 200mm 70mm;
margin: 0;
}
@media print {
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
}
.qr-page {
page-break-after: always;
}
.qr-code-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
width: 200mm;
height: 69mm;
margin-bottom: 10px;
}
.qr-code-container-img {
width: 70mm;
height: 69mm;
}
.qr-code-container-item {
width: 100mm;
height: 69mm;
}
</style>
<div>
${printNode.innerHTML}
</div>`)
doc.close()
//
setTimeout(() => {
newIframe.contentWindow.focus()
newIframe.contentWindow.print()
document.body.removeChild(newIframe) //
dialogVisible.value = false
}, 100)
}
// / Dialog
function beforeDialogClose(doClose: (shouldClose: boolean) => void): void {
outopen()
}
//
const outopen = () => {
dialogVisible.value = false
}
const printCodeName = ref([])
const datavals = ref([])
/** 打开弹窗 */
const open = async (code, vals, val) => {
console.log(code, vals, val)
datavals.value = []
printCodeName.value = []
vals.forEach((item) => {
const row = {
projectSubName: item.projectSubName,
spec: '规格' + item.spec,
sort: '序号' + item.sort,
amount: '数量' + item.amount
}
datavals.value.push(row)
})
// val1100
//
val = val.replace('-', ',')
val = val.split(',')
// console.log(val)
for (let i = val[0] * 1; i <= val[1] * 1; i++) {
// printCodeName
const newName = `${code}-${vals[0].clauseId}-${i}`
printCodeName.value.push(newName)
}
// console.log(printCodeName.value)
dialogVisible.value = true
await Promise.all(
printCodeName.value.map(async (item) => {
const qrCodeData = await QRCode.toDataURL(item)
const qrCodeElement = document.getElementById('qrCodeContainer')
if (qrCodeElement) {
var tempString = ""
datavals.value.forEach(e=>{tempString+='<span style="margin-left:30px;">'+e.projectSubName+' , '+e.spec+' , '+e.sort+' , '+e.amount+'</span>'})
qrCodeElement.innerHTML += `<div class="page qr-page">
<div class="qr-code-container" style=" padding:0 5mm; border:1px #d3d3d3 solid;display:flex; justify-content: flex-start; font-size:16px;font-weight:700;">
<img src="${qrCodeData}" width="30%" alt="QR Code"/>
<div style="margin-left:5mm;text-align:left;" >
<p>订单名称(Order name)${code}</p>
<hr/>
<p>产品清单(Product name)</p>`+tempString+`
</div>
</div>
</div>`
}
})
)
}
// <p>${datavals.value[0]?.projectSubName},${datavals.value[0].spec},${datavals.value[0].sort},${datavals.value[0].amount}</p>
// <div class="qr-code-name">${item}</div>
defineExpose({ open }) // open
</script>
<style scoped lang="scss">
.page {
width: 200mm;
min-height: 70mm;
margin: auto;
border: 1px #d3d3d3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.qrCodeContainer {
width: 200mm;
height: 70mm;
border: 1px #d3d3d3 solid;
border-radius: 5px;
background: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
@page {
size: 200mm 70mm;
margin: 0;
}
@media print {
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
}
.qr-page {
page-break-after: always;
}
.qr-code-container {
display: flex;
justify-content: flex-start;
align-items: center;
border: 1px #d3d3d3 solid;
width: 200mm;
height: 69mm;
}
.qr-code-container-item {
width: 100mm;
height: 69mm;
}
/*
A4的大小21cm*29.7cmwidth:794px;
单位换算1 inch = 2.54 cm 1mm = 96 px 1 cm = 37.79528 px*/
</style>
Loading…
Cancel
Save