<template>
	<view class="zd_container">
		<!-- 无人车卸货 -->
		<nav-bar :title="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>
								<th>物料类型</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.class_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<!-- <button class="zd-col-5 button-default" @tap="toEmpty">清空</button> -->
			<button class="zd-col-11 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_unload">卸货</button>
			<button class="zd-col-11 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_back">回库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryNotCarPoint, unload, back} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				title: '',
				dataList: [],
				// dataList: [{material_code: 'm001', qty: 100, checked: false, initialQty: 100}, {material_code: 'm002', qty: 200, checked: false, initialQty: 200}],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryNotCarPoint()
		},
		methods: {
			toEmpty () {
				this.dataList = []
				this.disabled = false
			},
			async _queryNotCarPoint () {
				try {
					let res = await queryNotCarPoint()
					if (res && res.data.length > 0) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			async _unload () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await unload(this.dataList)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			},
			async _back () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await back()
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>