<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 border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">载具号</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">订单号</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="val3" @input="_handheldGetRegionCode">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">物料号</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="val4">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">物料数量</span>
					</view>
					<view class="zd-col-19">
						<input type="number" class="filter_input" v-model="val5">
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-5">
						<span class="filter_label">目的地</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="val6">
					</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 || !val6 || !val2 || !val3 || !val4 || !val5}" :disabled="disabled" @tap="_handheldBlanking">入库确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {handheldGetRegionCode, handheldBlanking} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				val3: '',
				val4: '',
				val5: '',
				val6: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			async _handheldGetRegionCode () {
				let res = await handheldGetRegionCode(this.val3)
				if (res.content.length > 0) {
					this.val6 = res.content[0].region_code
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
				this.val4 = ''
				this.val5 = ''
				this.val6 = ''
				this.disabled = false
			},
			async _handheldBlanking () {
				this.disabled = true
				if (!this.val1 || !this.val6 || !this.val2 || !this.val3 || !this.val4 || !this.val5) {
					this.disabled = false
					return
				}
				try {
					let res = await handheldBlanking(this.val1, this.val6, this.val2, {order_code: this.val3, material_code: this.val4, material_qty: this.val5})
					this.clearUp()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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