<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_wraper">
						<span class="filter_label">起点</span>
					</view>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						/>
					</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-5 btn-submit btn-default" @tap="toEmpty">清空</button>
			<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index3 || !index4}" :disabled="disabled" @tap="toSure(1)">空轴退回</button>
			<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index3 || !index4}" :disabled="disabled" @tap="toSure(2)">管轴退回</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {remainShaftBack} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				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
		},
		methods: {
			async toSure (type) {
				this.disabled = true
				if (!this.val1 || !this.index3 || !this.index4) {
					this.disabled = false
					return
				}
				try {
					let res = await remainShaftBack(this.val1, this.index3, this.index4, type)
					this.disabled = false
					this.toEmpty()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			toEmpty () {
				this.val1 = ''
				this.index3 = ''
				this.index4 = ''
				this.disabled = false
			}
		}
	}
</script>