<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-7">
						<span class="filter_label">载具点位</span>
					</view>
					<view class="zd-col-24 filter_select">
						<search-box v-model="val1" />
					</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.point_code === pkId}" @tap="toCheck(e)">
								<td>{{i+1}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.vehicle_qty}}</td>
								<td>{{e.execution_task}}</td>
								<td>{{e.remaining_qty}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-24 button-primary" :class="{'button-info': !val1 || !pkId}" @tap="_callStackPlates">呼叫堆叠</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPointDtl, callStackPlates} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {}
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryPointDtl()
		},
		methods: {
			async _queryPointDtl () {
				try {
					let res = await queryPointDtl(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.point_code ? '' : e.point_code
				this.pkObj = this.pkId === e.point_code ? e : {}
			},
			async _callStackPlates () {
				this.disabled = true
				if (!this.val1 || !this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await callStackPlates(this.val1, this.pkObj)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>