<template>
	<view class="zd_container">
		<!-- 空载具堆叠 -->
		<nav-bar :title="title" :inner="true"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">载具点位</span>
					</view>
					<view class="zd-col-24 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>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.supp_id === pkId}" @tap="toCheck(e)">
								<td>{{i+1}}</td>
								<td>{{e.supp_name}}</td>
								<td>{{e.remark}}</td>
								<td>{{e.remark}}</td>
								<td>{{e.remark}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-24 button-primary" :class="{'button-info': !pkId}" @tap="toSure">呼叫堆叠</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {querySupp} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {}
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				if (e) {
					this._querySupp()
				}
			},
			async _querySupp () {
				try {
					let res = await querySupp(this.val1)
					if (res && res.data.length > 0) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.supp_id ? '' : e.supp_id
				this.pkObj = this.pkId === e.supp_id ? e : {}
			},
			toSure () {
				if (this.pkId) {
					this.$store.dispatch('setFormData', this.pkObj)
					uni.navigateBack()
				}
			}
		}
	}
</script>