Browse Source

多条打印

hella_vue3 5.1版本
zhang_li 7 months ago
parent
commit
61084b90ca
  1. 203
      src/hybrid/html/point.html
  2. 177
      src/pages/point/index.vue

203
src/hybrid/html/point.html

@ -1,133 +1,76 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title> <title></title>
<script src="../../api/img-to-base64.js"></script> <script src="../../api/img-to-base64.js"></script>
<script type="text/javascript"> <script type="text/javascript">
document.addEventListener('plusready', function() {
document.addEventListener('plusready', function(){ //console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。")
//console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。")
});
</script>
}); <style>
// 解析URL参数 .box {
function getQueryParam(param) { font-size: 14px;
var searchParams = new URLSearchParams(window.location.search); display: flex;
return searchParams.get(param);
} }
// 使用函数获取参数 .left {
document.addEventListener('DOMContentLoaded', function() { border-top: 1px solid #b1b1b1;
// var itemNumber = getQueryParam('itemNumber'); border-left: 1px solid #b1b1b1;
// var itemName = getQueryParam('itemName'); flex: 1;
// var tempFilePath = getQueryParam('tempFilePath') }
// document.getElementById('name1').innerText = itemNumber;
// document.getElementById('name2').innerText = itemName; .left-item {
// // document.getElementById('image1').src = barcodeImage; display: flex;
// console.log(99,tempFilePath) }
// pathToBase64(tempFilePath){
.label {
// } border-bottom: 1px solid #b1b1b1;
// pathToBase64(tempFilePath).then(base64 => { border-right: 1px solid #b1b1b1;
// document.getElementById('image1').src = base64; width: 60px;
// }).catch(err => { padding: 0px 5px;
// console.log(err); height: 67px;
// }) line-height: 67px;
// console.log(document.getElementById('name1')) }
});
.value {
</script> border-bottom: 1px solid #b1b1b1;
<style> border-right: 1px solid #b1b1b1;
.box{ padding: 0px 5px;
font-size: 14px; height: 67px;
display: flex; flex: 1;
width: 0px;
} display: flex;
.left{ align-items: center;
border-top: 1px solid #b1b1b1; word-wrap: break-word;
border-left: 1px solid #b1b1b1; }
flex: 1;
} .right {
.left-item{ width: 200px;
display: flex; }
}
.label{ .image {
border-bottom: 1px solid #b1b1b1; width: 100%;
border-right: 1px solid #b1b1b1; height: 202px;
width: 60px; border-bottom: 1px solid #b1b1b1;
padding: 0px 5px; border-top: 1px solid #b1b1b1;
height: 67px; border-right: 1px solid #b1b1b1;
line-height: 67px; }
}
.value{ .image img {
border-bottom: 1px solid #b1b1b1; width: calc(100% - 4px);
border-right: 1px solid #b1b1b1; height: calc(100% - 4px);
padding: 0px 5px; margin: 2px;
height: 67px; }
flex: 1; </style>
width: 0px; </head>
display: flex; <body>
align-items: center; mainBody
word-wrap: break-word; </body>
} </html>
.right{
width: 200px;
}
.image{
width: 100%;
height: 202px;
border-bottom: 1px solid #b1b1b1;
border-top: 1px solid #b1b1b1;
border-right: 1px solid #b1b1b1;
}
.image img{
width: calc(100% - 4px);
height: calc(100% - 4px);
margin: 2px;
}
</style>
</head>
<body>
<div>
<div class="box">
<div class="left">
<div class="left-item">
<div class="label">物品代码</div>
<div class="value" id="name1">replaceItemNumber</div>
</div>
<div class="left-item">
<div class="label">物品名称</div>
<div class="value" id="name2">replaceItemName</div>
</div>
<div class="left-item">
<div class="label">供应商</div>
<div class="value">replaceSupplierCode</div>
</div>
<div class="left-item">
<div class="label">包装号</div>
<div class="value">replacePackageCode</div>
</div>
<div class="left-item">
<div class="label">订单行</div>
<div class="value">replaceReferenceOrderRow</div>
</div>
</div>
<div class="right">
<div class="image">
<img id='image1' src="replaceBase" alt="" />
</div>
<div class="left-item">
<div class="label">订单号</div>
<div class="value">replaceReferenceOrderCode</div>
</div>
<div class="left-item">
<div class="label">数量</div>
<div class="value">replaceAmount</div>
</div>
</div>
</div>
</div>
</body>
</html>

177
src/pages/point/index.vue

@ -1,48 +1,48 @@
<template> <template>
<view class="content" style="padding:30rpx 20rpx;min-height: calc(100vh - 40rpx);"> <view class="content" style="padding:30rpx 20rpx 100rpx;min-height: calc(100vh - 120rpx);">
<!-- 只用于展示页面 --> <!-- 只用于展示页面 -->
<view class="box"> <view class="box" v-for="(item,index) in data" :key='index' style="margin-bottom: 20rpx;">
<view class="left"> <view class="left">
<view class="left-item"> <view class="left-item">
<view class="label">物品代码</view> <view class="label">物品代码</view>
<view class="value" id="name1">{{data.itemNumber}}</view> <view class="value" id="name1">{{item.itemNumber}}</view>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">物品名称</view> <view class="label">物品名称</view>
<view class="value" id="name2">{{data.itemName}}</view> <view class="value" id="name2">{{item.itemName}}</view>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">供应商</view> <view class="label">供应商</view>
<view class="value">{{data.supplierCode}}</view> <view class="value">{{item.supplierCode}}</view>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">包装号</view> <view class="label">包装号</view>
<view class="value">{{data.packageCode}}</view> <view class="value">{{item.packageCode}}</view>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">订单行</view> <view class="label">订单行</view>
<view class="value">{{data.referenceOrderRow}}</view> <view class="value">{{item.referenceOrderRow}}</view>
</view> </view>
</view> </view>
<view class="right"> <view class="right">
<view class="image"> <view class="image">
<l-qrcode ref="qrcodeRef" :value="data.barcodeString" size="300rpx"></l-qrcode> <l-qrcode ref="qrcodeRef" :value="item.barcodeString" size="300rpx"></l-qrcode>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">订单号</view> <view class="label">订单号</view>
<view class="value">{{data.referenceOrderCode}}</view> <view class="value">{{item.referenceOrderCode}}</view>
</view> </view>
<view class="left-item"> <view class="left-item">
<view class="label">数量</view> <view class="label">数量</view>
<view class="value">{{data.amount}}</view> <view class="value">{{item.amount}}</view>
</view> </view>
</view> </view>
</view> </view>
<view class="" style="position: fixed;width: 100%;bottom: 0rpx;left: 0px;">
<view class="">
<button @click="printImage" <button @click="printImage"
style='background:rgb(60, 156, 255) !important ;color: white;margin-top: 80rpx;'> 打印</button> style='background:rgb(60, 156, 255) !important ;color: white;margin-top: 80rpx;'> 打印</button>
</view> </view>
</view> </view>
</template> </template>
@ -60,8 +60,8 @@
data() { data() {
return { return {
data: {}, data: {},
newHtmlContent: '' //html newHtmlContent: '', //html
isLoadFinish: false,
} }
}, },
@ -89,59 +89,118 @@
} }
// #endif // #endif
}, },
watch: {
isLoadFinish(newVal, oldVal) {
if (newVal == true) {
// html
let str = ''
this.readFile(htmlFileUrl, (htmlContent) => {
this.newHtmlContent = htmlContent
this.data.forEach(item => {
str += `<div class="box" style="page-break-before:always;"><br />
<div class="left">
<div class="left-item">
<div class="label">物品代码</div>
<div class="value" id="name1">${item.itemNumber}</div>
</div>
<div class="left-item">
<div class="label">物品名称</div>
<div class="value" id="name2">${item.itemName}</div>
</div>
<div class="left-item">
<div class="label">供应商</div>
<div class="value">${item.supplierCode}</div>
</div>
<div class="left-item">
<div class="label">包装号</div>
<div class="value">${item.packageCode}</div>
</div>
<div class="left-item">
<div class="label">订单行</div>
<div class="value">${item.referenceOrderRow}</div>
</div>
</div>
<div class="right">
<div class="image">
<img id='image1' src="${item.barcodeBase64}" alt="" />
</div>
<div class="left-item">
<div class="label">订单号</div>
<div class="value">${item.referenceOrderRow}</div>
</div>
<div class="left-item">
<div class="label">数量</div>
<div class="value">${item.amount}</div>
</div>
</div>
</div>`
})
this.newHtmlContent = this.newHtmlContent.replace(
"mainBody", str); //
console.log(this.newHtmlContent)
});
}
}
},
async onShow() { async onShow() {
// //
this.data = { this.data = [{
itemNumber: '555555', itemNumber: '555555',
itemName: 'hahah', itemName: 'hahah',
referenceOrderRow: '60', referenceOrderRow: '55',
referenceOrderCode: '6000', referenceOrderCode: '55',
supplierCode: '888', supplierCode: '555',
packageCode: '9999-8888', packageCode: '9999-8888',
amount: '6000', amount: '55',
barcodeString: 'HMQ;V1.0;Dwork1-line1;F;R2024-04-03T08:28:41;B20240403;PPN0403-000005;I399.960-12;Q5.000000;UEA;' barcodeString: 'HMQ;V1.0;Dwork1-line1;F;R2024-04-03T08:28:41;B20240403;PPN0403-000005;I399.960-12;Q5.000000;UEA;',
} barcodeBase64: ''
this.$nextTick(() => { }, {
itemNumber: '66',
itemName: 'hahah',
referenceOrderRow: '66',
referenceOrderCode: '666',
supplierCode: '66',
packageCode: '66666',
amount: '666666',
barcodeString: 'HMQ;V1.0;Dwork1-line1;F;R2024-04-03T08:28:41;B20240403;PPN0403-000005;I399.960-12;Q5.000000;UEA;',
barcodeBase64: ''
}, {
itemNumber: '66',
itemName: 'hahah',
referenceOrderRow: '66',
referenceOrderCode: '666',
supplierCode: '66',
packageCode: '66666',
amount: '666666',
barcodeString: 'HMQ;V1.0;Dwork1-line1;F;R2024-04-03T08:28:41;',
barcodeBase64: ''
}]
this.$nextTick(async () => {
// //
const el = this.$refs['qrcodeRef'] const el = this.$refs['qrcodeRef']
el.canvasToTempFilePath({ let str = ''
success: async (res) => { el.forEach(async (item, index) => {
// base64 await item.canvasToTempFilePath({
await pathToBase64(res.tempFilePath).then(base64 => { success: async (res) => {
// html // base64
this.readFile(htmlFileUrl, (htmlContent) => { await pathToBase64(res.tempFilePath).then(base64 => {
this.newHtmlContent = htmlContent this.data[index].barcodeBase64 = base64
this.newHtmlContent = this.newHtmlContent.replace( if (index == el.length - 1) {
"replaceItemNumber", this.data this.isLoadFinish = true
.itemNumber); // }
this.newHtmlContent = this.newHtmlContent.replace( }).catch(err => {
"replaceItemName", this.data.itemName console.log(err);
); // })
this.newHtmlContent = this.newHtmlContent.replace( },
"replaceSupplierCode", this.data fail(err) {
.supplierCode); // console.log('err:::', err)
this.newHtmlContent = this.newHtmlContent.replace( }
"replacePackageCode", this.data })
.packageCode); //
this.newHtmlContent = this.newHtmlContent.replace(
"replaceReferenceOrderRow", this.data
.referenceOrderRow); //
this.newHtmlContent = this.newHtmlContent.replace(
"replaceReferenceOrderCode", this.data
.referenceOrderCode); //
this.newHtmlContent = this.newHtmlContent.replace(
"amount", this.data.amount); //
this.newHtmlContent = this.newHtmlContent.replace(
"replaceBase", base64); //
});
}).catch(err => {
console.log(err);
})
},
fail(err) {
console.log('err:::', err)
}
}) })
}) })
}, },

Loading…
Cancel
Save