<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-6">
						<span class="filter_label">入库点</span>
					</view>
					<view class="zd-col-18">
						<search-box v-model="val1"/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">载具</span>
					</view>
					<view class="zd-col-18">
						<search-box v-model="val2"/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">入库库区</span>
					</view>
					<view class="zd-col-18 filter_select">
						<uni-data-select v-model="index" :localdata="options"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">清空</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !val1 || !val2 || !index}" :disabled="disabled" @tap="_inEmptyVehicle">呼叫入库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getSectList, inEmptyVehicle} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				options: [],
				index: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._getSectList()
		},
		methods: {
			/** 下拉框*/
			async _getSectList () {
				try {
					let res = await getSectList()
					if (res && res.data.length > 0) {
						this.options = [...res.data]
					} else {
						this.options = []
					}
				} catch (e) {
					this.options = []
				}
			},
			toEmpty () {
				this.val1 = ''
				this.val2 = ''
				this.index = ''
				this.disabled = false
			},
			async _inEmptyVehicle () {
				this.disabled = true
				if (!this.val1 || !this.val2 || !this.index) {
					this.disabled = false
					return
				}
				try {
					let res = await inEmptyVehicle(this.index, this.val2, this.val1)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>