From d1aca2113dce3001b158efefab90aa70c7797ec3 Mon Sep 17 00:00:00 2001 From: zc Date: Sat, 11 Apr 2026 23:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/barcodePrint/index.vue | 2 +- src/views/weightManage/index.vue | 277 ++++++++++++++++++++++--------- 2 files changed, 199 insertions(+), 80 deletions(-) diff --git a/src/views/barcodePrint/index.vue b/src/views/barcodePrint/index.vue index 13a544b..457421c 100644 --- a/src/views/barcodePrint/index.vue +++ b/src/views/barcodePrint/index.vue @@ -359,7 +359,7 @@ const printLabel = async () => { } } -defineOptions({ name: 'BarcodePrint' }) +defineOptions({ name: 'print' }) + + +
+
+ + + + + + + + + + + + + + + + + + +
+
+
零件名称
+
${labelData.partName}
+
+
+
+
生产日期
+
${labelData.productionDate}
+
+
+
+ QR Code +
+
+
+
零件号
+
${labelData.partNumber}
+
+
+
+
数量
+
${labelData.totalCount}
+
+
+
+
标重(g)
+
${labelData.totalCalculatedWeight}
+
+
+
+
包装签字
+
${labelData.packingSignature || ''}
+
+
+
+
实重(g)
+
${labelData.totalWeight || ''}
+
+
+
+
检验签字
+
${labelData.inspectionSignature || ''}
+
+
+
+
+ + + ` + + printWindow.document.write(printHTML) + printWindow.document.close() + + printWindow.onload = () => { + setTimeout(() => { + printWindow.focus() + printWindow.print() + printWindow.close() + }, 500) + } + } +} + // 处理下一步 const handleNext = async () => { - // 步骤2:显示确认弹框 + // 步骤2:直接完成称重登记 if (activeStep.value === 2) { - Modal.confirm({ - title: '确认完成', - content: '确定要完成称重登记吗?', - onOk: async () => { - try { - // 准备工作订单数据 - const workOrderData = { - materialId: formData.id, - workOrderInfos: weighingList.value, - } - // 调用后端接口 - addWorkOrder(workOrderData).then((res) => { - if (res.code === '0') { - Notification.success({ - title: '操作成功', - content: `工单创建成功!`, - }) - workOrderResp.value.id = res.data?.id || '' - workOrderResp.value.matchResult = 'success' - workOrderResp.value.title = res.data?.title || '' - workOrderResp.value.orderNo = res.data?.orderNo || '' - workOrderResp.value.totalWeight = res.data?.totalWeight || '' - workOrderResp.value.totalCalculatedWeight = res.data?.totalCalculatedWeight || '' - workOrderResp.value.totalCount = res.data?.totalCount || '' + try { + // 准备工作订单数据 + const workOrderData = { + materialId: formData.id, + workOrderInfos: weighingList.value, + } + + // 调用后端接口 + const res = await addWorkOrder(workOrderData) + console.log('工单创建响应:', res) + + if (res.code === '0') { + console.log('工单创建成功,准备生成并打印标签') + Notification.success({ + title: '操作成功', + content: `工单创建成功!`, + }) + workOrderResp.value.id = res.data?.id || '' + workOrderResp.value.matchResult = 'success' + workOrderResp.value.title = res.data?.title || '' + workOrderResp.value.orderNo = res.data?.orderNo || '' + workOrderResp.value.totalWeight = res.data?.totalWeight || '' + workOrderResp.value.totalCalculatedWeight = res.data?.totalCalculatedWeight || '' + workOrderResp.value.totalCount = res.data?.totalCount || '' + workOrderResp.value.materialName = formData.materialName || '' + workOrderResp.value.encoding = formData.encoding || '' + + // 格式化生产日期为 yyyyMMddHHmm 格式 + const now = new Date() + const formattedDate = now.getFullYear().toString() + + String(now.getMonth() + 1).padStart(2, '0') + + String(now.getDate()).padStart(2, '0') + + String(now.getHours()).padStart(2, '0') + + String(now.getMinutes()).padStart(2, '0') - // 跳转到完成页面 - activeStep.value++ - return true - } - }) - } catch (error) { - console.error('创建工作订单失败:', error) - Message.error('创建工作订单失败') + const formattedDate2 = now.getFullYear().toString() + + String(now.getMonth() + 1).padStart(2, '0') + + String(now.getDate()).padStart(2, '0') + + // 使用物料批次作为生产批次 + const productionBatch = formData.batch || '' + + // 计算二维码数据 + const qrCodeData = `10#${formData.encoding}$11#9DP$12#${productionBatch}$17#${workOrderResp.value.totalCount}$20#${formattedDate2}$31#${workOrderResp.value.orderNo}$DY` + + // 生成二维码图片 + const qrCodeImage = await generateQRCode(qrCodeData) + + // 准备标签数据 + const labelData = { + partName: formData.materialName || '', + partNumber: formData.encoding || '', + totalCalculatedWeight: workOrderResp.value.totalCalculatedWeight || '', + totalWeight: workOrderResp.value.totalWeight || '', + productionDate: formattedDate, + totalCount: workOrderResp.value.totalCount || '', + packingSignature: '', + inspectionSignature: '', + qrCodeData: qrCodeData, + qrCodeImage: qrCodeImage } - }, - }) + + // 直接打印标签 + await printLabel(labelData) + } else { + console.error('工单创建失败,响应码:', res.code, '消息:', res.msg) + Message.error(res.msg || '创建工单失败') + } + } catch (error) { + console.error('创建工作订单失败:', error) + Message.error('创建工作订单失败') + } return; } @@ -779,9 +898,9 @@ const handlePrevious = () => { } // 打印 -const onPrint = () => { +const onPrint = async () => { // 跳转到标签打印页面,并传递数据 - router.push({ + await router.push({ path: '/print', query: { workerOrderId: workOrderResp.value.id,