<template>
	<view class="zd_container">
		<!-- <nav-bar title="空轴回库"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label">区域</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">尺寸</span>
					</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index3" :localdata="options3"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">代数</span>
					</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index4" :localdata="options4"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-6 btn-submit btn-default letter-30" @tap="clearUp">清空</button>
			<button class="zd-col-15 btn-submit btn-success letter-30" :class="{'btn-info': !index2 || !index3 || !index4}" :disabled="disabled" @tap="toSure">回库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryProductArea} from '@/utils/getData2.js'
	import {shaftGoBack} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				title: '',
				options2: [],
				index2: '',
				options3: [{value: '3', text: '3寸'}, {value: '6', text: '6寸'}],
				index3: '',
				options4: [{value: '4', text: '4'}, {value: '5', text: '5'}],
				index4: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._queryProductArea()
		},
		methods: {
			/** 生产区域下拉框查询 */
			async _queryProductArea () {
				let res = await queryProductArea()
				this.options2 = [...res.data]
			},
			selectChange2(e) {
				this.index2 = e
			},
			toSure () {
				this.disabled = true
				if (!this.index2 || !this.index3 || !this.index4) {
					this.disabled = false
					return
				}
				this._shaftGoBack()
			},
			async _shaftGoBack () {
				try {
					let res = await shaftGoBack(this.index2, this.index3, this.index4)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.index2 = ''
				this.index3 = ''
				this.index4 = ''
				this.disabled = false
			}
		}
	}
</script>