<template>
	<view class="zd_container">
		<nav-bar title="客户标签打印"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">木箱</span>
					</view>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						/>
					</view>
				</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>
								<th>生产日期</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.container_name === pkId}">
								<td>{{e.package_box_sn}}</td>
								<td>{{e.quanlity_in_box}}</td>
								<td>{{e.box_weight}}</td>
								<td>{{e.sale_order_name}}</td>
								<td>{{e.product_name}}</td>
								<td>{{e.product_description}}</td>
								<td>{{e.width}}</td>
								<td>{{e.container_name}}</td>
								<td>{{e.net_weight}}</td>
								<td>{{e.date_of_FG_inbound}}</td>
								<td>{{e.date_of_production}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !pkId}" :disabled="disabled2" @tap="_customerPrint">打印</button>
			<button class="submit-button" :class="{'btn-disabled': !val1}" :disabled="disabled1" @tap="_customerInfo">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {customerInfo, customerPrint} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				dataList: [],
				disabled1: false,
				disabled2: false,
				pkId: '',
				pkObj: {}
			};
		},
		methods: {
			toCheck (e) {
				this.pkId = this.pkId === e.container_name ? '' : e.container_name
				this.pkObj = this.pkId === e.container_name ? e : {}
			},
			/** 查询 */
			async _customerInfo () {
				this.disabled1 = true
				if (!this.val1) {
					uni.showToast({
						title: '请扫木箱码',
						icon: 'none'
					})
					this.disabled1 = false
					return
				}
				try {
					let res = await customerInfo(this.val1)
					this.dataList = [...res.data]
					this.disabled1 = false
				} catch (e) {
					this.disabled1 = false
				}	
			},
			/** 打印 */
			async _customerPrint () {
				this.disabled2 = true
				if (!this.pkId) {
					uni.showToast({
						title: '请选择一行',
						icon: 'none'
					})
					this.disabled2 = false
					return
				}
				try {
					let res = await customerPrint(this.pkObj.package_box_sn)
					this.disabled2 = false
					this.pkId = ''
					this.pkObj = {}
					this._customerInfo()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled2 = false
				}	
			},
		}
	}
</script>

<style lang="stylus">

</style>
