<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: 'Z00001333'
			};
		},
		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, '80mm', '50mm', '');
				// LODOP.ADD_PRINT_RECT('0.5mm', '0.5mm', '75mm', '45mm', 0, 1);
				LODOP.SET_PRINT_STYLE('FontSize', 12);
				LODOP.SET_PRINT_STYLE('Bold', 1);
				LODOP.ADD_PRINT_TEXT('1mm', '27mm', '25mm', '5.5mm', '物料信息卡');
				LODOP.SET_PRINT_STYLE('FontSize', 7.7);
				LODOP.SET_PRINT_STYLE('Bold', 0);
				LODOP.ADD_PRINT_TEXT('10.5mm', '5mm', '25mm', '5.5mm', '用料单号：');
				LODOP.ADD_PRINT_TEXT('10.5mm', '18mm', '60mm', '5.5mm', data.prd_ppbom_no);
				LODOP.ADD_PRINT_TEXT('16mm', '5mm', '25mm', '5.5mm', '物料编码：');
				LODOP.ADD_PRINT_TEXT('16mm', '18mm', '60mm', '5.5mm', data.material_code);
				LODOP.ADD_PRINT_TEXT('21.5mm', '5mm', '25mm', '5.5mm', '物料名称：');
				LODOP.ADD_PRINT_TEXT('21.5mm', '18mm', '80mm', '2mm', data.material_name);
				LODOP.ADD_PRINT_TEXT('27mm', '5mm', '25mm', '5.5mm', '物料规格：');
				LODOP.ADD_PRINT_TEXT('27mm', '18mm', '60mm', '5.5mm', data.material_spec);
				LODOP.ADD_PRINT_TEXT('32.5mm', '5mm', '60mm', '5.5mm', '物料数量：');
				LODOP.ADD_PRINT_TEXT('32.5mm', '18mm', '60mm', '5.5mm', data.assign_qty);
				LODOP.ADD_PRINT_TEXT('38mm', '5mm', '25mm', '5.5mm', '料箱号：');
				LODOP.ADD_PRINT_TEXT('38mm', '18mm', '60mm', '5.5mm', data.lxCode);
				LODOP.PRINT();
				// LODOP.PREVIEW()
				uni.showToast({
					title: '打印成功',
					icon: 'none'
				})
				if (this.isChecked1) {
					this._savePickTask()
				}
			}
		}
	}
</script>