add:库存打印功能
This commit is contained in:
@@ -68,6 +68,7 @@
|
||||
ext.create_time,
|
||||
attr.struct_code,
|
||||
attr.struct_name,
|
||||
attr.stor_code,
|
||||
attr.stor_name,
|
||||
attr.sect_name,
|
||||
mater.material_code,
|
||||
|
||||
@@ -60,7 +60,18 @@
|
||||
<el-button
|
||||
slot="right"
|
||||
class="filter-item"
|
||||
type="primary"
|
||||
icon="el-icon-printer"
|
||||
size="mini"
|
||||
:disabled="!crud.selections || crud.selections.length === 0"
|
||||
@click="openPrintDialog"
|
||||
>
|
||||
库存打印
|
||||
</el-button>
|
||||
<el-button
|
||||
slot="right"
|
||||
v-has-user="['admin']"
|
||||
class="filter-item"
|
||||
type="warning"
|
||||
icon="el-icon-refresh"
|
||||
size="mini"
|
||||
@@ -79,6 +90,7 @@
|
||||
style="width: 100%;"
|
||||
@selection-change="crud.selectionChangeHandler"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="struct_code" label="仓位编码" :min-width="flexWidth('struct_code',crud.data,'仓位编码')" />
|
||||
<el-table-column prop="struct_name" label="仓位名称" :min-width="flexWidth('struct_name',crud.data,'仓位名称')" />
|
||||
<el-table-column prop="stor_name" label="仓库" :min-width="flexWidth('stor_name',crud.data,'仓库')" />
|
||||
@@ -122,6 +134,46 @@
|
||||
<el-button type="primary" :loading="syncLoading" @click="doSyncStock">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="库存打印"
|
||||
:visible.sync="printDialogVisible"
|
||||
width="420px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form label-width="90px" label-suffix=":" size="mini">
|
||||
<el-form-item label="物料编码">
|
||||
<span>{{ printRow.material_code }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="打印数量">
|
||||
<el-input-number v-model="printForm.quantity" :min="1" :max="999999" :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: 500px; 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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -135,6 +187,7 @@ import crudSectattr from '@/views/wms/basedata/sectattr/sectattr'
|
||||
import { download } from '@/api/data'
|
||||
import { downloadFile } from '@/utils'
|
||||
import request from '@/utils/request'
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
export default {
|
||||
name: 'Structivt',
|
||||
@@ -161,7 +214,14 @@ export default {
|
||||
rules: {},
|
||||
syncDialogVisible: false,
|
||||
syncWarehouseCode: '',
|
||||
syncLoading: false
|
||||
syncLoading: false,
|
||||
printDialogVisible: false,
|
||||
printPreviewVisible: false,
|
||||
printRow: {},
|
||||
printForm: {
|
||||
quantity: 1,
|
||||
mode: 'batch'
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -232,6 +292,95 @@ export default {
|
||||
}).finally(() => {
|
||||
this.syncLoading = false
|
||||
})
|
||||
},
|
||||
openPrintDialog() {
|
||||
const selections = this.crud.selections || []
|
||||
if (selections.length !== 1) {
|
||||
this.$message.info('请选择一条库存记录打印')
|
||||
return
|
||||
}
|
||||
this.printRow = selections[0]
|
||||
this.printForm = { quantity: 1, mode: 'batch' }
|
||||
this.printDialogVisible = true
|
||||
},
|
||||
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: 'ALL', quantity }]
|
||||
: Array.from({ length: quantity }, (_, index) => ({ serial: index + 1, quantity }))
|
||||
this.printDialogVisible = false
|
||||
this.printPreviewVisible = true
|
||||
this.$nextTick(() => this.renderPrintContent(labels))
|
||||
},
|
||||
escapePrintValue(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
},
|
||||
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 materialCode = this.printRow.material_code || ''
|
||||
const materialName = this.printRow.material_name || ''
|
||||
const warehouseCode = this.printRow.stor_code || ''
|
||||
const date = this.formatPrintDate(new Date())
|
||||
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:10px;text-align:center}'
|
||||
html += '.label:last-child{page-break-after:auto}'
|
||||
html += 'h3{text-align:center;font-size:14px;margin-bottom:6px}'
|
||||
html += 'table{width:463px;border-collapse:collapse;margin:0 auto;min-height:224px}'
|
||||
html += 'td{padding:5px;border:2px solid #333;font-size:16px;line-height:1.3}'
|
||||
html += '.lbl{width:25%;text-align:right;background:#f9f9f9}'
|
||||
html += '.val{width:45%;text-align:left;word-break:break-all}'
|
||||
html += '.qr{width:30%;text-align:center;vertical-align:middle}'
|
||||
html += '@media print{@page{size:auto;margin:5mm}}'
|
||||
html += '</style></head><body>'
|
||||
for (const label of labels) {
|
||||
const serial = label.serial
|
||||
const qrText = materialCode + ':' + label.quantity + ':' + serial + ':' + warehouseCode
|
||||
const imgSrc = await QRCode.toDataURL(qrText, { width: 300 })
|
||||
html += '<div class="label">'
|
||||
html += '<h3>库存标签</h3><table>'
|
||||
html += '<tr><td class="lbl">物料编码</td><td class="val">' + this.escapePrintValue(materialCode) + '</td><td class="qr" rowspan="6"><img src="' + imgSrc + '" width="150" height="150"></td></tr>'
|
||||
html += '<tr><td class="lbl">物料名称</td><td class="val">' + this.escapePrintValue(materialName) + '</td></tr>'
|
||||
html += '<tr><td class="lbl">数量</td><td class="val">' + this.escapePrintValue(label.quantity) + '</td></tr>'
|
||||
html += '<tr><td class="lbl">序号</td><td class="val">' + this.escapePrintValue(serial) + '</td></tr>'
|
||||
html += '<tr><td class="lbl">日期</td><td class="val">' + date + '</td></tr>'
|
||||
html += '<tr><td class="lbl">仓库编码</td><td class="val">' + this.escapePrintValue(warehouseCode) + '</td></tr>'
|
||||
html += '</table></div>'
|
||||
}
|
||||
html += '</body></html>'
|
||||
doc.open()
|
||||
doc.write(html)
|
||||
doc.close()
|
||||
},
|
||||
formatPrintDate(date) {
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return date.getFullYear() + '-' + month + '-' + day
|
||||
},
|
||||
doPrint() {
|
||||
const iframe = this.$refs.printIframe
|
||||
if (!iframe) return
|
||||
iframe.contentWindow.focus()
|
||||
iframe.contentWindow.print()
|
||||
},
|
||||
closePrintPreview() {
|
||||
this.printPreviewVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user