add:结构件需求单标签打印

This commit is contained in:
zhaoyf
2026-12-03 19:11:25 +08:00
parent 2074aed81e
commit dfe56d7c67

View File

@@ -23,6 +23,7 @@
<crudOperation :permission="permission">
<el-button slot="right" v-permission="permission.del" class="filter-item" type="danger" icon="el-icon-delete" size="mini" :loading="batchDeleting" :disabled="!multipleSelection.length || batchDeleting" @click="handleBatchDelete">批量删除</el-button>
<el-button slot="right" class="filter-item" type="success" icon="el-icon-s-promotion" size="mini" :disabled="isPushDisabled()" @click="handleBatchPush">下推出库</el-button>
<el-button slot="right" class="filter-item" type="primary" icon="el-icon-printer" size="mini" :disabled="!multipleSelection.length" @click="openPrintDialog">标签打印</el-button>
</crudOperation>
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="900px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="110px" label-suffix=":" style="border: 1px solid #cfe0df;margin-top: 10px;padding: 10px;">
@@ -44,6 +45,34 @@
<div slot="footer" class="dialog-footer"><el-button type="text" @click="crud.cancelCU">取消</el-button><el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button></div>
</el-dialog>
<el-dialog title="标签打印" :visible.sync="printDialogVisible" width="460px" :close-on-click-modal="false">
<el-form label-width="90px" label-suffix=":" size="mini">
<el-form-item label="工单编号"><span>{{ printRow.workOrder || '-' }}</span></el-form-item>
<el-form-item label="需求日期"><span>{{ formatDemandDate(printRow.createTime) || '-' }}</span></el-form-item>
<el-form-item label="物料编码"><span>{{ printRow.skuCode || '-' }}</span></el-form-item>
<el-form-item label="物料名称"><span>{{ printRow.skuName || '-' }}</span></el-form-item>
<el-form-item label="用料位置"><span>{{ printRow.targetArea || '-' }}</span></el-form-item>
<el-form-item label="打印数量"><el-input-number v-model="printForm.quantity" :min="1" :max="999" :step="1" controls-position="right" /></el-form-item>
<el-form-item label="打印方式">
<el-radio-group v-model="printForm.mode">
<el-radio label="batch">批次打印</el-radio>
<el-radio label="all">全部打印</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button size="mini" @click="printDialogVisible = false">取消</el-button>
<el-button type="primary" size="mini" @click="createPrintPreview">生成打印预览</el-button>
</span>
</el-dialog>
<el-dialog title="标签打印预览" :visible.sync="printPreviewVisible" width="700px" :close-on-click-modal="false" @close="closePrintPreview">
<iframe ref="printIframe" src="about:blank" style="width: 100%; height: 480px; border: 1px solid #ddd;" />
<div slot="footer" class="dialog-footer">
<el-button size="mini" @click="printPreviewVisible = false">取消</el-button>
<el-button type="primary" size="mini" @click="doPrint">打印</el-button>
</div>
</el-dialog>
<el-table ref="table" :height="590" v-loading="crud.loading" :data="crud.data" size="small" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="workOrder" label="需求单编号" min-width="140" show-overflow-tooltip />
@@ -86,6 +115,7 @@ import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import rrOperation from '@crud/RR.operation.vue'
import pagination from '@crud/Pagination.vue'
import QRCode from 'qrcode'
const createDefaultForm = () => ({ id: null, creator: '', createTime: '', priority: 0, workOrder: '', skuCode: '', skuName: '', qty: undefined, unit: '', targetArea: '', productionLine: '', sn: '' })
@@ -117,6 +147,10 @@ export default {
],
batchDeleting: false,
multipleSelection: [],
printDialogVisible: false,
printPreviewVisible: false,
printRow: {},
printForm: { quantity: 1, mode: 'batch' },
rules: {
creator: [{ required: true, message: '请输入操作人', trigger: 'blur' }],
createTime: [{ required: true, message: '请选择需求日期', trigger: 'change' }],
@@ -208,6 +242,98 @@ export default {
this.$message.error('下推失败')
})
}).catch(() => {})
},
openPrintDialog() {
const selections = this.multipleSelection || []
if (selections.length !== 1) {
this.$message.info('请选择一条需求单打印')
return
}
this.printRow = selections[0]
this.printForm = { quantity: this.getPrintQuantity(selections[0]), mode: 'batch' }
this.printDialogVisible = true
},
getPrintQuantity(row) {
const qty = Number(row && row.qty)
if (!Number.isFinite(qty) || qty < 1) return 1
return Math.min(999, Math.round(qty))
},
createPrintPreview() {
const quantity = Number(this.printForm.quantity)
if (!Number.isInteger(quantity) || quantity < 1) {
this.$message.warning('请输入大于0的整数数量')
return
}
const labels = this.printForm.mode === 'all'
? [{ serial: '全部', quantity }]
: Array.from({ length: quantity }, (_, index) => ({ serial: index + 1, quantity }))
this.printDialogVisible = false
this.printPreviewVisible = true
this.$nextTick(() => this.renderPrintContent(labels))
},
formatDemandDate(value) {
return String(value === undefined || value === null ? '' : value).slice(0, 10)
},
escapePrintValue(value) {
return String(value === undefined || value === null ? '' : value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
},
async renderPrintContent(labels) {
const iframe = this.$refs.printIframe
if (!iframe) return
const doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document)
if (!doc) {
setTimeout(() => this.renderPrintContent(labels), 100)
return
}
const workOrder = this.printRow.workOrder || ''
const demandDate = this.formatDemandDate(this.printRow.createTime)
const skuCode = this.printRow.skuCode || ''
const skuName = this.printRow.skuName || ''
const targetArea = this.printRow.targetArea || ''
let html = '<!DOCTYPE html><html><head><meta charset="utf-8"><style>'
html += '*{margin:0;padding:0;box-sizing:border-box}'
html += 'body{font-family:"Microsoft YaHei",Arial,sans-serif;padding:10px}'
html += '.label{page-break-after:always;padding:6px 0}'
html += '.label:last-child{page-break-after:auto}'
html += 'table{width:100mm;height:28mm;border-collapse:collapse;table-layout:fixed;margin:0 auto;border:2px solid #000}'
html += 'td{border:1px solid #000;padding:0.4mm 1.6mm;font-size:8.5pt;line-height:1.15;vertical-align:middle;word-break:break-all}'
html += '.lbl{height: 25px;width:22mm;white-space:nowrap}'
html += '.val{width:47mm}'
html += '.center{text-align:center}'
html += '.qr{width:31mm;text-align:center;vertical-align:middle}'
html += '.qr img{width:22mm;height:22mm}'
html += '@media print{@page{size:auto;margin:3mm}}'
html += '</style></head><body>'
for (const label of labels) {
const qrText = skuCode + ':' + label.quantity + ':' + (label.serial === '全部' ? 'ALL' : label.serial) + ':' + workOrder
const imgSrc = await QRCode.toDataURL(qrText, { width: 300 })
html += '<div class="label"><table>'
html += '<tr><td class="lbl">工单编号</td><td class="val">' + this.escapePrintValue(workOrder) + '</td><td class="qr" rowspan="6"><img src="' + imgSrc + '"></td></tr>'
html += '<tr><td class="lbl">需求日期</td><td class="val">' + this.escapePrintValue(demandDate) + '</td></tr>'
html += '<tr><td class="lbl">物料编码</td><td class="val">' + this.escapePrintValue(skuCode) + '</td></tr>'
html += '<tr><td class="lbl">物料名称</td><td class="val">' + this.escapePrintValue(skuName) + '</td></tr>'
html += '<tr><td class="lbl">用料位置</td><td class="val">' + this.escapePrintValue(targetArea) + '</td></tr>'
html += '<tr><td class="lbl">序号/数量</td><td class="val center">' + this.escapePrintValue(label.serial + '/' + label.quantity) + '</td></tr>'
html += '</table></div>'
}
html += '</body></html>'
doc.open()
doc.write(html)
doc.close()
},
doPrint() {
const iframe = this.$refs.printIframe
if (!iframe) return
iframe.contentWindow.focus()
iframe.contentWindow.print()
},
closePrintPreview() {
this.printPreviewVisible = false
}
}
}