import moment from 'moment'
import QRCode from 'qrcodejs2'
import { v4 as uuidv4 } from "uuid";
function codeListPrint(data, domId) {
if (data.length == 0) {
return
}
let preHtml = `
诸暨市新丝维化纤有限公司
`
let endHtml = `
注:不同批号,请勿混用
`
let res = ``;
let uuidList = [];
for (let i = 0; i < data.length; i++) {
let item = data[i]
let {
qrCode,//序号
machineTool,//机台
boxWeight,//箱重-车重
canisterweight,//筒重
canisterNum,//筒数
grossWeight,//毛重
suttle,//净重
workShifts,//班次
tubecolor,//管色
boxOrderNum, //生成的随机码
myNO,//箱号
productionDate, //日期
printFormat, //格式
productName, //产品名
productSpecifications, //规格
productColor, //色泽
lotNum, //批次
levels,//等级
directionOfTwist,//捻向
qrCodeData,
boxNumber//箱号
} = item
let theNumber = Number(printFormat) //小包装:1 大包装:2
while (theNumber > 0) {
let uuid = uuidv4().slice(0, 8);
theNumber--;
res += preHtml;
// let qrCodeData = '123456';
uuidList.push({
id: uuid,
qrCodeData: qrCodeData
})
res += `
品种 |
${productName} |
规格 |
${productSpecifications} |
批号 |
${lotNum} |
色号 |
${productColor} |
等级 |
${levels} |
箱号 |
${qrCode} |
${boxNumber} |
筒数 |
${canisterNum} ${tubecolor} |
捻向 |
${directionOfTwist} |
班次 |
${workShifts} ${machineTool} |
日期 |
${productionDate} |
毛重 |
${grossWeight} |
净重 |
${suttle} |
`
res += endHtml;
}
}
document.body.innerHTML = document.getElementById(domId).innerHTML = res;
for (var i = 0; i < uuidList.length; i++) {
let data = uuidList[i]
new QRCode(document.getElementById("" + data.id), {
text: sleep(1) + data.qrCodeData,
width: 120,
height: 120,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H,
});
}
window.print();//打印
// window.location.reload();
return false;
}
// 延迟
function sleep(ms) {
var unixtime_ms = new Date().getTime();
while (new Date().getTime() < unixtime_ms + ms) { }
return "";
}
export default codeListPrint