<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<!-- 出库确认 -->
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">载具码</span>
					</view>
					<view class="zd-col-19 filter_select">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</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>
							</tr>
						</thead>
						<tbody>
							<tr v-for="e in dataList" :key="e.point_code" :class="{'checked': e.point_code === pkId}" @tap="toCheck(e)">
								<td>{{e.bill_code}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.storagevehicle_code}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.qty}}</td>
								<td>{{e.qty_unit_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !val1 || !pkId}" :disabled="disabled" @tap="_OutConfirm">出库确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {OutGetDtl, OutConfirm} from '@/utils/getData.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				if (e) {
					this._OutGetDtl(e)
				}
			},
			async _OutGetDtl (e) {
				try {
					let res = await OutGetDtl(e)
					if (res) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []	
					}
				} catch (e) {
					this.dataList = []
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.point_code ? '' : e.point_code
				this.pkObj = this.pkId === e.point_code ? e : {}
			},
			clearUp () {
				this.val1 = ''
				this.dataList = []
				this.pkId = ''
				this.disabled = false
			},
			async _OutConfirm () {
				this.disabled = true
				if (!this.val1 || !this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await OutConfirm(this.val1, this.pkId)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this._OutGetDtl(this.val1)
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
