<template>
	<view class="zd_container">
		<!-- <nav-bar title="生产区发货"></nav-bar> -->
		<nav-bar :title="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 class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">单据号</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val2"  @handleChange="handleChange2" />
					</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>
								<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.bill_code === pkId}">
								<td>{{e.bill_code}}</td>
								<td>{{e.bill_status}}</td>
								<td>{{e.total_qty}}</td>
								<td>{{e.net_weight_num}}</td>
								<td>{{e.detail_count}}</td>
								<td>{{e.cust_code}}</td>
								<td>{{e.cust_name}}</td>
								<td>{{e.source_id}}</td>
								<td>{{e.remark}}</td>
								<td>{{e.input_optname}}</td>
								<td>{{e.input_time}}</td>
								<td>{{e.dis_optname}}</td>
								<td>{{e.dis_time}}</td>
								<td>{{e.confirm_optname}}</td>
								<td>{{e.confirm_time}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-11 btn-submit btn-success letter-30" :class="{'btn-info': !pkId}" :disabled="disabled1" @tap="toSure">确认</button>
			<button class="zd-col-11 btn-submit btn-success letter-30" @tap="_stivtQuery(val1, val2)">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {stivtQuery} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled1: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._stivtQuery(this.val1, this.val2)
		},
		mounted () {
			this.$refs.scanChild.handleFocus()
		},
		methods: {
			handleChange1 (e) {
				this._stivtQuery(e, this.val2)
			},
			handleChange2 (e) {
				this._stivtQuery(this.val1, e)
			},
			/** 初始化查询 */
			async _stivtQuery (val1, val2) {
				let res = await stivtQuery(val1, val2)
				this.dataList = [...res.data]
			},
			toSure () {
				if (this.pkId) {
					uni.navigateTo({
						url: '/pages/WarehouseManage/ProdDeliveryConfirm?billcode=' + this.pkObj.bill_code + '&title=' + this.title
					})
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.bill_code ? '' : e.bill_code
				this.pkObj = this.pkId === e.bill_code ? e : {}
			}
		}
	}
</script>