<template>
	<view class="zd_container">
		<!-- 定点作业 -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="is-required">
					<view class="filter_label">{{$t('label.StartPosition')}}</view>
					<search-box
					v-model="val1"
					/>
				</view>
				<view class="is-required">
					<view class="filter_label">{{$t('label.EndPosition')}}</view>
					<search-box
					v-model="val2"
					/>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="clearUp">{{$t('button.clear')}}</button>
			<button class="zd-col-16 button-primary" :class="{'button-info': !val1 || !val2}" :disabled="disabled" @tap="_transferConfirm">{{$t('button.confirm')}}</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {transferConfirm} from '@/utils/getData.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				disabled: false,
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			clearUp () {
				this.val1 = ''
				this.val2 = ''
			},
			async _transferConfirm () {
				this.disabled = true
				if (!this.val1 || !this.val2) {
					this.disabled = false
					return
				}
				try {
					let res = await transferConfirm(this.val1, this.val2)
					if (res.status === '200') {
						this.clearUp()
					}
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
