<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 ref="scanChild" v-model="val1" @handleChange="handleChange1"
						/>
					</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>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td style="text-decoration: underline;" @tap="toXq(e.package_box_sn)">{{e.package_box_sn}}</td>
								<td>{{e.box_weight}}</td>
								<td>{{e.net_weight_num}}</td>
								<td>{{e.product_description}}</td>
								<!-- <td>{{Number(i) + 1}}</td> -->
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.product_name}}</td>
								<td>{{e.sale_order_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<!-- <button class="submit-button" @tap="handleTest">Test</button> -->
			<button class="zd-col-11 btn-submit btn-success" :class="{'btn-info': !val1}" :disabled="disabled1" @tap="_stoutConfirm">出库确认</button>
			<button class="zd-col-11 btn-submit btn-success letter-30" @tap="_stivtDtlQuery">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {stivtDtlQuery, stoutConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				billCode: '',
				dataList: [],
				disabled1: false
			};
		},
		onLoad (option) {
			this.billCode = option.billcode
			this.title = option.title
			this._stivtDtlQuery()
		},
		mounted () {
			this.$refs.scanChild.handleFocus()
		},
		methods: {
			handleChange1 (e) {
				this._stivtDtlQuery()
			},
			goIn () {
				uni.navigateTo({
					url: `/pages/WarehouseManage/ProdDelivery?title=` + this.title
				})
			},
			toXq (code) {
				uni.navigateTo({
					url: '/pages/WarehouseManage/ProdDeliveryDtl?boxno=' + code + '&billcode=' + this.billCode + '&title=' + this.title
				})
			},
			/** 初始化查询 */
			async _stivtDtlQuery () {
				let res = await stivtDtlQuery(this.val1, this.billCode)
				this.dataList = [...res.data]	
			},
			async _stoutConfirm () {
				this.disabled1 = true
				try {
					let res = await stoutConfirm(this.val1)
					this.disabled1 = false
					this.val1 = ''
					this.dataList = []
					this._stivtDtlQuery()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.$refs.scanChild.handleFocus()
				} catch (e) {
					this.disabled1 = false
				}
			}
		}
	}
</script>