<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-17">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">载具类型</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">载具库区</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">出库数量</span>
					</view>
					<view class="zd-col-17">
						<NumberInput v-model="qty" />
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !qty || !val2 || !index || !index2}" :disabled="disabled" @tap="_vehicleOut">呼叫出库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import NumberInput from '@/components/NumberInput.vue'
	import {queryVehicleType} from '@/utils/getData2.js'
	import {querySectCode, vehicleOut} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			NumberInput
		},
		data() {
			return {
				title: '',
				val2: '',
				options: [],
				index: '',
				options2: [],
				index2: '',
				qty: 1,
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._queryVehicleType()
			this._querySectCode()
		},
		methods: {
			async _queryVehicleType () {
				try {
					let res = await queryVehicleType()
					if (res) {
						this.options = res.data
					} else {
						this.options = []
					}
				} catch (e) {
					this.options = []
				}
			},
			async _querySectCode () {
				try {
					let res = await querySectCode()
					if (res) {
						this.options2 = res.data
					} else {
						this.options2 = []
					}
				} catch (e) {
					this.options2 = []
				}
			},
			selectChange (e) {
				this.index = e
			},
			selectChange (e) {
				this.index2 = e
			},
			clearUp () {
				this.qty = ''
				this.val2 = ''
				this.index = ''
				this.index2 = ''
				this.disabled = false
			},
			async _vehicleOut () {
				this.disabled = true
				if (!this.qty || !this.val2 || !this.index || !this.index2) {
					this.disabled = false
					return
				}
				try {
					let res = await vehicleOut(this.qty, this.val2, this.index, this.index2)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.clearUp()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
