<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-7">
						<span class="filter_label">起始区域</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">目标区域</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">起点点位</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index3" :localdata="options3" @change="selectChange3"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">目标点位</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index4" :localdata="options4" @change="selectChange4"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">载具类型</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index5" :localdata="options5" @change="selectChange5"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !index || !index2 || !index3 || !index4 || !index5}" :disabled="disabled" @tap="_callTask">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryArea, queryPointByArea, queryVehicleType, callTask } from '@/utils/getData3.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				options: [],
				index: '',
				options2: [],
				index2: '',
				options3: [],
				index3: '',
				options4: [],
				index4: '',
				options5: [],
				index5: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._queryArea ()
			this._queryArea2()
			this._queryVehicleType()
		},
		methods: {
			async _queryArea  () {
				try {
					let res = await queryArea ()
					if (res) {
						this.options = res.data
					} else {
						this.options = []
					}
				} catch (e) {
					this.options = []
				}
			},
			async _queryArea2 () {
				try {
					let res = await queryArea ()
					if (res) {
						this.options2 = res.data
					} else {
						this.options2 = []
					}
				} catch (e) {
					this.options2 = []
				}
			},
			async _queryPointByArea3 () {
				try {
					let res = await queryPointByArea (this.index)
					if (res) {
						this.options3 = res.data
					} else {
						this.options3 = []
					}
				} catch (e) {
					this.options3 = []
				}
			},
			async _queryPointByArea4 () {
				try {
					let res = await queryPointByArea (this.index2)
					if (res) {
						this.options4 = res.data
					} else {
						this.options4 = []
					}
				} catch (e) {
					this.options4 = []
				}
			},
			async _queryVehicleType () {
				try {
					let res = await queryVehicleType ()
					if (res) {
						this.options5 = res.data
					} else {
						this.options5 = []
					}
				} catch (e) {
					this.options5 = []
				}
			},
			selectChange (e) {
				this.index = e
				if (e) {
					this._queryPointByArea3()
				}
			},
			selectChange2 (e) {
				this.index2 = e
				if (e) {
					this._queryPointByArea4()
				}
			},
			selectChange3 (e) {
				this.index3 = e
			},
			selectChange4 (e) {
				this.index4 = e
			},
			selectChange5 (e) {
				this.index5 = e
			},
			clearUp () {
				this.index = ''
				this.index2 = ''
				this.index3 = ''
				this.index4 = ''
				this.index5 = ''
				this.disabled = false
			},
			async _callTask  () {
				this.disabled = true
				if (!this.index3 || !this.index4 || !this.index5) {
					this.disabled = false
					return
				}
				try {
					let res = await callTask (this.index3, this.index4, '3', this.index5)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.clearUp()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
