<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">
						<link-scan ref="scanChild" @getScanlist="getScanlist"/>
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-5">
						<span class="filter_label">目的地</span>
					</view>
					<view class="zd-col-19 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-8 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !val1 || !val2 || !index}" :disabled="disabled" @tap="_handheldCageFrame">送回确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import LinkScan from '@/components/LinkScan.vue'
	import {handheldCageFrame} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			LinkScan
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				options: [{ value: '1', text: '人工折弯区' }, { value: '2', text: '半自动折弯区' }, { value: '3', text: '内部加工区' }, { value: '4', text: '货架' }],
				index: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			getScanlist (e) {
				this.val2 = e.join()
			},
			async _handheldCageFrame () {
				this.disabled = true
				if (!this.val1 || !this.val2 || !this.index) {
					this.disabled = false
					return
				}
				try {
					let res = await handheldCageFrame(this.index, this.val1, this.val2)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.index = ''
				this.$refs.scanChild.toDel()
				this.disabled = false
			}
		}
	}
</script>

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