<template>
	<view class="zd_container">
		<nav-bar :title="$t('grid.unbind-ship-area')" :inner="true" :show="false"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('filter.box-no')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val1" @handleChange="handleChange"/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">{{$t('grid.bill-code')}}</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input filter_input_disabled" v-model="val2" disabled>
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th class="fontcol2">{{$t('filter.box-no')}}</th>
								<th>{{$t('grid.point-code')}}</th>
								<th>{{$t('grid.point-name')}}</th>
								<th>{{$t('grid.weight')}}</th>
								<th>{{$t('grid.product-code')}}</th>
								<th>{{$t('grid.product-name')}}</th>
								<th>{{$t('grid.order-number')}}</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @tap="_twoPdaIvtbBoxDtlQuery(e.package_box_sn)">
								<td class="fontcol2">{{e.package_box_sn}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.box_weight}}</td>
								<td>{{e.product_name}}</td>
								<td>{{e.product_description}}</td>
								<td>{{e.sale_order_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-5 btn-submit btn-default letter-30" @tap="clearUp">{{$t('button.clear')}}</button>
			<button class="zd-col-8 btn-submit btn-success letter-30" :class="{'btn-info': dataList.length === 0}" :disabled="disabled" @tap="handleConfirm">{{$t('button.confirm')}}</button>
			<button class="zd-col-8 btn-submit btn-success letter-30" @tap="_twoPdaIvtDtlQuery(val1)">{{$t('button.search')}}</button>
		</view>
		<view class="msg_wrapper" :class="show ? 'popshow' : 'pophide'">
			<view class="pop-line"></view>
			<view class="msg_content pdb110">
				<view class="zd_wrapper grid-wraper">
					<view class="slide_new">
						<table>
							<thead>
								<tr>
									<th>{{$t('filter.box-no')}}</th>
									<th>{{$t('grid.sub-roll-number')}}</th>
									<th>{{$t('grid.sap-batch')}}</th>
									<th>{{$t('grid.net-weight')}}</th>
									<th>{{$t('grid.status')}}</th>
									<th>{{$t('grid.order-number')}}</th>
									<th>{{$t('grid.customer-code')}}</th>
									<th>{{$t('grid.customer-name')}}</th>
									<th>{{$t('grid.width')}}</th>
									<th>{{$t('grid.thickness')}}</th>
									<th>{{$t('grid.length')}}</th>
									<th>{{$t('grid.width-required-customer')}}</th>
									<th>{{$t('grid.standard-hickness-mater')}}</th>
									<th>{{$t('grid.shelf-life')}}</th>
									<th>{{$t('grid.manu-completion-date')}}</th>
									<th>{{$t('grid.warehousing-date')}}</th>
								</tr>
							</thead>
							<tbody>
								<tr v-for="e in dtlList" :key="e.package_box_sn">
									<td>{{e.package_box_sn}}</td>
									<td>{{e.container_name}}</td>
									<td>{{e.sap_pcsn}}</td>
									<td>{{e.net_weight}}</td>
									<td>{{e.status}}</td>
									<td>{{e.sale_order_name}}</td>
									<td>{{e.customer_name}}</td>
									<td>{{e.customer_description}}</td>
									<td>{{e.width}}</td>
									<td>{{e.thickness}}</td>
									<td>{{e.length}}</td>
									<td>{{e.width_standard}}</td>
									<td>{{e.thickness_request}}</td>
									<td>{{e.quality_guaran_period}}</td>
									<td>{{e.date_of_production}}</td>
									<td>{{e.date_of_fG_inbound}}</td>
								</tr>
							</tbody>
						</table>
					</view>
				</view>
			</view>
			<view class="zd-row submitbar">
				<button class="zd-col-22 btn-submit btn-success letter-30" @tap.stop="show = false">{{$t('button.return')}}</button>
			</view>
		</view>
		<view v-if="show" class="msg_mask"></view>
		<up-top ref="UT" :scrollTop="top"></up-top>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import UpTop from '@/components/upTop.vue'
	import { confirmAction } from '@/utils/utils.js'
	import {twoPdaIvtDtlQuery, twoPdaIvtbBoxDtlQuery, twoPdaOutConfirm} from '@/utils/getData3.js'
	// import {twoPdaIvtDtlQuery, twoPdaIvtbBoxDtlQuery} from '@/utils/mork2.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			UpTop
		},
		data() {
			return {
				top: 0,
				val1: '',
				val2: '',
				dataList: [],
				dtlList: [],
				show: false,
				disabled: false
			};
		},
		onLoad (options) {
			this.val2 = options.code
		},
		onPageScroll(e) {
			this.$refs.UT.topData(e.scrollTop)
		},
		methods: {
			handleChange (e) {
				this._twoPdaIvtDtlQuery(e)
			},
			async _twoPdaIvtDtlQuery (e) {
				let res = await twoPdaIvtDtlQuery(e, this.val2)
				this.dataList = [...res.data]
			},
			async _twoPdaIvtbBoxDtlQuery (e) {
				let res = await twoPdaIvtbBoxDtlQuery(e)
				this.dtlList = [...res.data]
				this.show = true
			},
			async handleConfirm() {
				if (this.dataList.length === 0) {
					return
				}
				const isConfirmed = await confirmAction(this.$t('toast.prompt'), this.$t('toast.sure-perform-operation'))
				if (isConfirmed) {
					this._twoPdaOutConfirm()
				}
			},
			async _twoPdaOutConfirm () {
				this.disabled = true
				try {
					let res = await twoPdaOutConfirm(this.val1)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.val1 = ''
					this.dataList = []
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.val1 = ''
				this.dataList = []
			}
		}
	}
</script>

<style lang="stylus" scoped>
.pdb110
	padding-bottom 110rpx
</style>