opt:仓位打印
This commit is contained in:
@@ -93,16 +93,17 @@
|
||||
</div>
|
||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||
<crudOperation :permission="permission">
|
||||
<!-- <el-button-->
|
||||
<!-- slot="right"-->
|
||||
<!-- class="filter-item"-->
|
||||
<!-- type="warning"-->
|
||||
<!-- icon="el-icon-check"-->
|
||||
<!-- size="mini"-->
|
||||
<!-- @click="openOneCreate"-->
|
||||
<!-- >-->
|
||||
<!-- 一键生成-->
|
||||
<!-- </el-button>-->
|
||||
<el-button
|
||||
slot="right"
|
||||
class="filter-item"
|
||||
type="primary"
|
||||
icon="el-icon-printer"
|
||||
size="mini"
|
||||
:disabled="!crud.selections || crud.selections.length === 0"
|
||||
@click="createPrintPreview"
|
||||
>
|
||||
标签打印
|
||||
</el-button>
|
||||
</crudOperation>
|
||||
|
||||
<!--表单组件-->
|
||||
@@ -252,9 +253,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="simple_name" label="仓位简称" :min-width="flexWidth('simple_name',crud.data,'仓位简称')" />
|
||||
@@ -307,7 +306,13 @@
|
||||
<pagination />
|
||||
</div>
|
||||
<!-- <OneCreateDialog :dialog-show.sync="openOneCreateDialog" />-->
|
||||
|
||||
<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>
|
||||
|
||||
@@ -320,6 +325,7 @@ import udOperation from '@crud/UD.operation'
|
||||
import pagination from '@crud/Pagination'
|
||||
import OneCreateDialog from '@/views/wms/basedata/structattr/OneCreateDialog'
|
||||
import crudSectattr from '@/views/wms/basedata/sectattr/sectattr'
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
const defaultForm = {
|
||||
struct_id: null,
|
||||
@@ -402,6 +408,7 @@ export default {
|
||||
}
|
||||
return {
|
||||
openOneCreateDialog: false,
|
||||
printPreviewVisible: false,
|
||||
sects: [],
|
||||
invtypelist: [],
|
||||
permission: {},
|
||||
@@ -525,6 +532,68 @@ export default {
|
||||
})
|
||||
}).catch(() => {
|
||||
})
|
||||
},
|
||||
createPrintPreview() {
|
||||
const selections = this.crud.selections || []
|
||||
if (selections.length === 0) {
|
||||
this.$message.info('请先勾选需要打印标签的仓位')
|
||||
return
|
||||
}
|
||||
this.printPreviewVisible = true
|
||||
this.$nextTick(() => this.renderPrintContent(selections))
|
||||
},
|
||||
escapePrintValue(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
},
|
||||
async renderPrintContent(rows) {
|
||||
const iframe = this.$refs.printIframe
|
||||
if (!iframe) return
|
||||
const doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document)
|
||||
if (!doc) {
|
||||
setTimeout(() => this.renderPrintContent(rows), 100)
|
||||
return
|
||||
}
|
||||
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 row of rows) {
|
||||
const structCode = row.struct_code || ''
|
||||
const imgSrc = await QRCode.toDataURL(structCode, { width: 300 })
|
||||
html += '<div class="label"><h3>库位标签</h3><table>'
|
||||
html += '<tr><td class="lbl">库位编码</td><td class="val">' + this.escapePrintValue(structCode) + '</td><td class="qr" rowspan="4"><img src="' + imgSrc + '" width="150" height="150"></td></tr>'
|
||||
html += '<tr><td class="lbl">库位名称</td><td class="val">' + this.escapePrintValue(row.struct_name) + '</td></tr>'
|
||||
html += '<tr><td class="lbl">所属库区</td><td class="val">' + this.escapePrintValue(row.sect_name) + '</td></tr>'
|
||||
html += '<tr><td class="lbl">所属仓库</td><td class="val">' + this.escapePrintValue(row.stor_name) + '</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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user