<template>
	<view class="zd_container">
		<!-- 库存查询 -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">查询类型</span>
					</view>
					<view class="zd-col-18 filter_select">
						<uni-data-select v-model="index1" :localdata="options1" :clear="false"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-18">
						<search-box v-model="val1"/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">物料编码</span>
					</view>
					<view class="zd-col-13">
						<!-- <search-box v-model="materialData.material_code"/> -->
						<input type="text" class="filter_input" v-model="materialData.material_code">
					</view>
					<button class="mini-btn" type="primary" @tap="toJump('mater-save?title=物料维护')">查询</button>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">批号</span>
					</view>
					<view class="zd-col-13">
						<input type="text" class="filter_input" v-model="val2">
					</view>
					<button class="mini-btn" type="primary" @tap="_queryIvt">查询</button>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th>点位</th>
								<th>物料编码</th>
								<th>物料名称</th>
								<th>批号</th>
								<th>数量</th>
								<th>单位</th>
								<th>类别</th>
								<th>入库时间</th>
								<th>载具</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{i+1}}</td>
								<td>{{e.struct_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.canuse_qty}}</td>
								<td>{{e.qty_unit_name}}</td>
								<td>{{e.class_name}}</td>
								<td>{{e.insert_time}}</td>
								<td>{{e.storagevehicle_code}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar" v-if="index1 === 'ZZC01'">
			<!-- <button class="zd-col-5 button-default" @tap="toEmpty">清空</button> -->
			<button class="zd-col-22 button-primary" :class="{'button-info': !val1 ||  !pcsn  || JSON.stringify(materialData) === '{}' || JSON.stringify(suppData) === '{}'}" :disabled="disabled" @tap="labelPrint">打印</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryIvt} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				// options1: [],
				materialData: {},
				options1: [{text:'原料', value: 'WYL01'}, {text:'辅料', value: 'WFL01'}, {text:'批料室', value: 'PZC01'}, {text:'中间站', value: 'ZZC01'}, {text:'内包材', value: 'NBC01'}, {text:'外包材', value: 'WBC01'}],
				index1: 'WYL01',
				val1: '',
				val2: '',
				num: null,
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		onShow () {
			if (this.$store.getters.publicObj !== '') {
				this.materialData = this.$store.getters.publicObj
				this.$store.dispatch('setPublicObj', '')
			}
		},
		methods: {
			toEmpty () {
				this.val1 = ''
				this.dataList = []
				this.disabled = false
			},
			toJump (name) {
				uni.navigateTo({
					url: `/pages/hdyy/tygn/${name}`
				})
			},
			async _queryIvt () {
				try {
					let res = await queryIvt(this.index1, this.val1, this.materialData.material_code, this.val2)
					if (res && res.data) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} catch (e) {
					this.dataList = []
				}
			},
			labelPrint () {
				this.disabled1 = true
				if (!this.val1 || JSON.stringify(this.materialData) === '{}' || JSON.stringify(this.suppData) === '{}') {
					this.disabled1 = false
					return
				}
				let data = Object.assign({}, this.materialData, this.suppData, {pcsn: this.pcsn, create_time: this.date, qty: this.num, bucket_code: this.val1, bucket_weight: this.weight})
				this.toPrint(data)
			},
			toPrint (row) {
				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.disabled1 = false
				    return
				}
				LODOP.SET_SHOW_MODE('HIDE_DISBUTTIN_SETUP', 1)// 隐藏那些无效按钮
				// 打印纸张大小设置https://www.it610.com/article/2094844.html
				LODOP.PRINT_INIT('')
				LODOP.SET_PRINT_PAGESIZE(1, '94mm', '119mm', '')
				LODOP.ADD_PRINT_RECT('1mm', '3mm', '92mm', '117mm', 0, 1)
				LODOP.ADD_PRINT_TEXT('2.88mm', '35.4mm', '32.65mm', '5.95mm', '中 美 华 东 制 药')
				LODOP.ADD_PRINT_TEXT('6.56mm', '22.33mm', '62.02mm', '5.69mm', 'Zhongmei Huadong Pharmaceutical')
				LODOP.ADD_PRINT_TEXT('10.45mm', '13.86mm', '98mm', '7.01mm', '周 转 物 料 卡 Turnover Material Card')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 11)
				LODOP.ADD_PRINT_TEXT('15.48mm', '5.13mm', '93.24mm', '5.69mm', '依据《状态标识牌的有关规定》（QA-SMP-B005）制定此记录')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 8)
				LODOP.ADD_PRINT_TEXT('19.45mm', '5.13mm', '128.69mm', '7.01mm', 'Establish this record according to “SMP for status signboard”')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 8)
				LODOP.ADD_PRINT_TEXT('22.89mm', '5.13mm', '27.62mm', '4.37mm', '(QA-SMP-B005)')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 8)
				LODOP.ADD_PRINT_TEXT('26.86mm', '5.13mm', '66.78mm', '4.37mm', '记录编号 Record No.: ' + this.recordNo + '')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 8)
				LODOP.ADD_PRINT_TEXT('31.64mm', '4.87mm', '87.95mm', '5.69mm', '物 料 名 称 Material Name: ' + row.material_name + '')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('37.17mm', '4.74mm', '42.44mm', '5.69mm', '物 料 批 号 及 代 码')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('40.9mm', '4.74mm', '86.1mm', '5.69mm', 'Material Batch No. and Code: ' + row.pcsn + '_' + row.material_code)
				LODOP.ADD_PRINT_TEXT('46.78mm', '4.47mm', '41.65mm', '5.69mm', '桶 号 Barrel No.: ' + row.bucket_code + '')
				LODOP.ADD_PRINT_TEXT('46.78mm', '48.13mm', '43.5mm', '5.69mm', '皮 重 Tare Weight: ' + row.bucket_weight + '')
				LODOP.ADD_PRINT_TEXT('51.81mm', '48.13mm', '44.03mm', '5.69mm', '总 重 Total Weight: ')
				LODOP.ADD_PRINT_TEXT('51.81mm', '4.47mm', '41.65mm', '5.69mm', '净 重 Net Weight: ')
				LODOP.ADD_PRINT_TEXT('56.83mm', '4.47mm', '86.62mm', '7.01mm', '操 作 日 期 Operation Date: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('62.92mm', '4.47mm', '85.3mm', '7.01mm', '有 效 期 至 Expiry Date: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('69.22mm', '5mm', '22.07mm', '5.69mm', '用 于 产 品')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('73.71mm', '5mm', '11.22mm', '5.69mm', 'Used')
				LODOP.ADD_PRINT_TEXT('73.71mm', '17.44mm', '8.57mm', '5.69mm', 'in')
				LODOP.ADD_PRINT_TEXT('77.68mm', '5mm', '16.77mm', '5.69mm', 'Product')
				LODOP.ADD_PRINT_TEXT('69.45mm', '28.28mm', '23.65mm', '5.69mm', '名 称 Name: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('76.23mm', '28.28mm', '31.86mm', '5.69mm', '规 格 Strength: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('83.98mm', '5.27mm', '51.17mm', '5.69mm', '操 作 人 Operator: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('92.21mm', '5.27mm', '48mm', '5.69mm', '复 核 人 Reviewer: ')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_TEXT('99.7mm', '5.27mm', '39.26mm', '5.69mm', '备 注 Remarks:')
				LODOP.SET_PRINT_STYLEA(0, 'FontSize', 10)
				LODOP.ADD_PRINT_LINE(114, 11, 114, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(136, 11, 136, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(171, 11, 171, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(209, 11, 209, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(231, 11, 231, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(254, 11, 254, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(282, 97, 282, 360, 0, 0)

				LODOP.ADD_PRINT_LINE(309, 11, 309, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(339, 11, 339, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(370, 11, 370, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(397, 11, 397, 360, 0, 0)
				LODOP.ADD_PRINT_LINE(309, 96, 254, 96, 0, 1)
				LODOP.ADD_PRINT_BARCODE('107.13mm', '22.99mm', '57.1mm', '10.74mm', '128A', row.bucket_code)

				LODOP.PRINT()// 打印
				// LODOP.PREVIEW()// 预览
				// LODOP.PRINT_DESIGN()
				uni.showToast({
					title: '操作成功',
					icon: 'none'
				})
				this.disabled1 = false
			}
		}
	}
</script>

<style scoped>
.filter_picker {
	text-align: center
}
</style>