<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">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-5">
						<span class="filter_label">载具号</span>
					</view>
					<view class="zd-col-19">
						<link-scan ref="scanChild" @getScanlist="getScanlist"/>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-7 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_callEmptyVehicle">送回确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import LinkScan from '@/components/LinkScan.vue'
	import {getVehicleType, callEmptyVehicle} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			LinkScan
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			getScanlist (e) {
				this.val2 = e.join()
			},
			/** 载具类型下拉框 */
			async _getVehicleType () {
				let res = await getVehicleType()
				this.options1 = [...res]
			},
			pickerChange (e) {
				this.index1 = e.detail.value
			},
			async _callEmptyVehicle () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await callEmptyVehicle(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.$refs.scanChild.toDel()
				this.disabled = false
			}
		}
	}
</script>

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