<template>
	<view class="zd_container">
		<nav-bar title="空盘入库"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>起点</th>
								<th>终点</th>
								<th>任务状态</th>
								<th>备注</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @tap="toCheck(e)" :class="{'checked': e.group_id === pkId}">
								<td>{{e.point_code}}</td>
								<td>{{e.device_code}}</td>
								<td>{{e.standing_time}}</td>
								<td>{{e.timeDifferenceMinutes}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" @tap="_emptyDiskIntoStorageShow">刷新</button>
			<button class="submit-button" :class="{'btn-disabled': !pkId}" :disabled="disabled" @tap="toSure">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {emptyDiskIntoStorageShow, emptyDiskIntoStorageTask} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled: false
			};
		},
		created () {
			this._emptyDiskIntoStorageShow()
		},
		methods: {
			/** grid查询 */
			async _emptyDiskIntoStorageShow () {
				let res = await emptyDiskIntoStorageShow()
				this.dataList = [...res]
			},
			/** 确认 */
			async toSure () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await emptyDiskIntoStorageTask()
					this.disabled = false
					this.pkId = ''
					this.pkObj = {}
					this._emptyDiskIntoStorageShow()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.group_id ? '' : e.group_id
				this.pkObj = this.pkId === e.group_id ? e : {}
			}
		}
	}
</script>

<style lang="stylus">
</style>
