<template>
	<view class="zd_container">
		<nav-bar :inner2="true" @goIn="goIn" 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" :focused="true" @handleChange="handleChange1" -->
						<search-box ref="scanChild" v-model="val1" @handleChange="handleChange1"
						/>
					</view>
				</view>
				<!-- <view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val2" />
					</view>
				</view> -->
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">总净重</span>
					</view>
					<view class="filter_input_wraper">
						<input type="number" class="filter_input filter_input_disabled" v-model="net_weight_num" disabled>
					</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>重量kg</th>
								<th>更换外包</th>
								<th>更换内包</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'bgyellow': e.colro_flag === '1'}">
								<td>{{e.package_box_sn}}</td>
								<td>{{e.container_name}}</td>
								<td>{{e.product_name}}</td>
								<td>{{e.product_description}}</td>
								<td>{{e.net_weight}}</td>
								<td>{{e.change_out}}</td>
								<td>{{e.change_in}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-15 btn-submit btn-success" :class="{'btn-info': !dataList.length}" :disabled="disabled1" @tap="_virtualoutConfirm">出库确认</button>
			<button class="zd-col-6 btn-submit btn-success letter-30" @tap="_virtualivtQuery">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {virtualivtQuery, virtualoutConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				val2: '',
				billCode: '',
				dataList: [],
				disabled1: false,
				net_weight_num: ''
			};
		},
		onLoad (option) {
			this.billCode = option.billcode
			this._virtualivtQuery()
		},
		mounted () {
			this.$refs.scanChild.handleFocus()
		},
		methods: {
			handleChange1 (e) {
				this._virtualivtQuery()
			},
			goIn () {
				uni.navigateTo({
					url: `/pages/WarehouseManage/XuniDelivery`
				})
			},
			handleChange (e) {
				// console.log(e)
			},
			/** 初始化查询 */
			async _virtualivtQuery () {
				let res = await virtualivtQuery(this.val1, this.val2, this.billCode)
				this.dataList = [...res.data]
				this.net_weight_num = res.net_weight_num
			},
			async _virtualoutConfirm () {
				if (!this.dataList.length) {
					return
				}
				this.disabled1 = true
				try {
					let res = await virtualoutConfirm(this.dataList, this.val1)
					this.disabled1 = false
					this.val1 = ''
					this.val2 = ''
					this._virtualivtQuery()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.$refs.scanChild.handleFocus()
				} catch (e) {
					this.disabled1 = false
				}
			}
		}
	}
</script>