<template>
	<view class="zd_container">
		<!-- 打印测试 -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<table border=0 cellSpacing=0 cellPadding=0  width="100%" bordercolor="#000000" style="border-collapse:collapse">
					<tbody>
						<tr>
						    <td width="40%">用料单号</td>
						    <td width="60%">{{data.prd_ppbom_no}}</td>
						</tr>
						<tr>
						    <td width="40%">物料编码</td>
						    <td width="60%">{{data.material_code}}</td>
						</tr>
						<tr>
						    <td width="40%">物料名称</td>
						    <td width="60%">{{data.material_name}}</td>
						</tr>
						<tr>
						    <td width="40%">物料规格</td>
						    <td width="60%">{{data.material_spec}}</td>
						</tr>
						<tr>
						    <td width="40%">物料数量</td>
						    <td width="60%">{{data.assign_qty}}</td>
						</tr>
						<tr>
						    <td width="40%">料箱号</td>
						    <td width="60%">{{val1}}</td>
						</tr>
					</tbody>
				</table>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-22 button-primary" @tap="toSure">打印测试</button>
		</view>
	</view>
</template>

<script>
	import {getCLodop} from "@/utils/CLodopfuncs.js"
	import NavBar from '@/components/NavBar.vue'
	import {queryPick} from '@/utils/mork2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				data: {},
				val1: '1000'
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryPick()
		},
		methods: {
			async _queryPick (e) {
				let res = await queryPick('Picking', e)
				this.data = res
			},
			toSure () {
				let data = Object.assign({}, this.data, {lxCode: this.val1})
				this.toPrint(data)
			},
			toPrint (data) {
				let iparr = this.$store.getters.printUrl.split(":")
				let printUrl = iparr[1].slice(2)
				let LODOP = getCLodop();
				if (!(LODOP.webskt && LODOP.webskt.readyState === 1)) {
				    uni.showToast({
						title: '当前配置ip：' + printUrl + '网络不通，请检查',
						icon: 'none',
						duration: 5000
					})
					this.disabled = false
				    return
				}
				LODOP.SET_SHOW_MODE('HIDE_DISBUTTIN_SETUP', 1)// 隐藏那些无效按钮
				LODOP.SET_LICENSES('浙江省烟草专卖局（公司）', 'C0C4A46A3A0D1F526D426018D9F11921', '', '')
				// 更换为打印服务器ip 不需要加前缀
				LODOP.PRINT_INIT(null, printUrl);
				// 打印机序号 规则为打印服务器打印机列表倒数从0开始 -1为默认打印机 
				LODOP.SET_PRINTER_INDEX(-1);
				// 设置打印纸大小
				LODOP.SET_PRINT_PAGESIZE(1, '70mm', '35mm', '');
				// LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
				// LODOP.ADD_PRINT_RECT('0.5mm', '0.5mm', '65mm', '30mm', 0, 1);
				LODOP.SET_PRINT_STYLE('FontSize', 6);
				LODOP.SET_PRINT_STYLE('Bold', 1);
				LODOP.ADD_PRINT_TEXT('2mm', '27mm', '25mm', '4mm', '物料信息卡');
				let tableHtml = `
								<div id="div1">
									<style>table{border:none} td{border: 1px solid #000;height:16px;font-size: 6px;text-align: center}</style>
									
									<table border=0 cellSpacing=0 cellPadding=0  width="100%" bordercolor="#000000" style="border-collapse:collapse">
										<tbody>
											<tr>
											    <td width="40%">用料单号111</td>
											    <td width="60%">${data.prd_ppbom_no}</td>
											</tr>
											<tr>
											    <td width="40%">222</td>
											    <td width="60%">${data.material_code}</td>
											</tr>
											<tr>
											    <td width="40%">aaa</td>
											    <td width="60%">${data.material_name}</td>
											</tr>
											<tr>
											    <td width="40%">物料规格</td>
											    <td width="60%">${data.material_spec}</td>
											</tr>
											<tr>
											    <td width="40%">物料数量</td>
											    <td width="60%">${data.assign_qty}</td>
											</tr>
											<tr>
											    <td width="40%">料箱号</td>
											    <td width="60%">${data.lxCode}</td>
											</tr>
										</tbody>
									</table>
								</div>`
				LODOP.ADD_PRINT_TABLE("5mm",'0mm',"66mm","32mm",tableHtml);
				LODOP.PRINT();
				// LODOP.PREVIEW()
				uni.showToast({
					title: '打印成功',
					icon: 'none'
				})
				if (this.isChecked1) {
					this._savePickTask()
				}
			}
		}
	}
</script>