优化
This commit is contained in:
@@ -359,7 +359,7 @@ const printLabel = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
defineOptions({ name: 'BarcodePrint' })
|
||||
defineOptions({ name: 'print' })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<div class="step-line"></div>
|
||||
<div class="step-item" :class="{ active: activeStep >= 3, completed: activeStep > 3 }">
|
||||
<div class="step-circle">3</div>
|
||||
<div class="step-title">完成创建</div>
|
||||
<div class="step-title">完成并打印</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -204,47 +204,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 完成创建页面 -->
|
||||
<div v-else-if="activeStep === 3" class="step-content">
|
||||
<div class="completion-content">
|
||||
<div class="completion-icon">
|
||||
<a-icon type="check-circle" :size="64" style="color: #52c41a;" />
|
||||
</div>
|
||||
<h2>{{ workOrderResp.matchResult === 'success' ? '创建成功' : '创建失败' }}</h2>
|
||||
<p>{{ workOrderResp.matchResult === 'success' ? '任务创建成功' : '任务创建失败' }},以下是任务详情:</p>
|
||||
<div class="completion-info">
|
||||
<div class="info-item">
|
||||
<span class="label">任务工单号:</span>
|
||||
<span class="value">{{ workOrderResp.orderNo }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">物料名称:</span>
|
||||
<span class="value">{{ formData.materialName }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">物料编码:</span>
|
||||
<span class="value">{{ formData.encoding }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">物料总个数:</span>
|
||||
<span class="value">{{ workOrderResp.totalCount }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">标准总重量(g):</span>
|
||||
<span class="value">{{ workOrderResp.totalCalculatedWeight }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="label">实际总重量(g):</span>
|
||||
<span class="value">{{ workOrderResp.totalWeight }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="completion-actions">
|
||||
<a-button type="primary" @click="onPrint">打印</a-button>
|
||||
<a-button type="primary" @click="handleBackToFirst">返回首页</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="action-buttons">
|
||||
<a-button
|
||||
@@ -293,6 +252,7 @@ import {brightness, connect, disconnect} from "@/apis/weightManage/light";
|
||||
|
||||
import router from "@/router";
|
||||
import type {TableInstanceColumns} from "@/components/GiTable/type";
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
defineOptions({ name: 'WeightManage' })
|
||||
|
||||
@@ -682,46 +642,205 @@ const fetchMaterialData = async (code: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 生成二维码
|
||||
const generateQRCode = async (data: string) => {
|
||||
try {
|
||||
return await QRCode.toDataURL(data, {
|
||||
width: 120,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#FFFFFF'
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('生成二维码失败:', error)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// 打印标签
|
||||
const printLabel = async (labelData: any) => {
|
||||
const printWindow = window.open('', '_blank')
|
||||
if (printWindow) {
|
||||
const printHTML = `
|
||||
<html>
|
||||
<head>
|
||||
<title>标签打印</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 10mm; font-family: Arial, sans-serif; }
|
||||
.label-container { display: flex; flex-wrap: wrap; gap: 10mm; justify-content: center; }
|
||||
.label { width: 90mm; height: 38.5mm; border: 1px solid #000; padding: 0; box-sizing: border-box; page-break-inside: avoid; }
|
||||
.label-table { width: 100%; height: 100%; border-collapse: collapse; }
|
||||
.label-cell { border: 1px solid #000; padding: 1mm; vertical-align: top; }
|
||||
.qr-cell { width: 24mm; text-align: center; vertical-align: middle; border: 1px solid #000; }
|
||||
.label-row { display: flex; align-items: center; }
|
||||
.label-field { font-size: 7pt; font-weight: bold; margin-right: 2mm; min-width: 25pt; }
|
||||
.label-value { font-size: 7pt; flex: 1; }
|
||||
.qr-code img { width: 20mm; height: 20mm; margin: 1mm 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="label-container">
|
||||
<div class="label">
|
||||
<table class="label-table">
|
||||
<tr>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">零件名称</div>
|
||||
<div class="label-value">${labelData.partName}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">生产日期</div>
|
||||
<div class="label-value">${labelData.productionDate}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="label-cell qr-cell" rowspan="4">
|
||||
<div class="qr-code">
|
||||
<img src="${labelData.qrCodeImage}" alt="QR Code" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">零件号</div>
|
||||
<div class="label-value">${labelData.partNumber}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">数量</div>
|
||||
<div class="label-value">${labelData.totalCount}</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">标重(g)</div>
|
||||
<div class="label-value">${labelData.totalCalculatedWeight}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">包装签字</div>
|
||||
<div class="label-value">${labelData.packingSignature || ''}</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">实重(g)</div>
|
||||
<div class="label-value">${labelData.totalWeight || ''}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="label-cell">
|
||||
<div class="label-row">
|
||||
<div class="label-field">检验签字</div>
|
||||
<div class="label-value">${labelData.inspectionSignature || ''}</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user