<template>
	<view class="zd_container">
		<nav-bar 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="index5" :localdata="options5" @change="selectChange5"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">起始区域</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index3" :localdata="options3" @change="selectChange3"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">目标区域</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index4" :localdata="options4" @change="selectChange4"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">起始点位</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
					</view>
				</view>
				<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>
		</view>
		<view class="zd-row submit-bar_new">
			<button class="zd-col-7 submit-button_c" @tap="toClear">清空</button>
			<button class="zd-col-15 submit-button_new" :class="{'btn-disabled': !index1 || !index2}" :disabled="disabled" @tap="toPop">确认</button>
		</view>
		<view class="zd_content msg_wrapper" :class="show ? 'popshow' : 'pophide'">
			<view class="pop-line"></view>
			<view class="msg_content">
				<view class="zd-row">
					<view class="zd-col-24">
						<span class="filter_label">确认下发任务？</span>
					</view>
				</view>
			</view>
			<view class="zd-row submit-bar">
				<button class="zd-col-11 button-default" @tap.stop="show = false">关闭</button>
				<button class="zd-col-11 button-primary" :disabled="disabled" @tap="_callTask">确定</button>
			</view>
		</view>
		<view v-if="show" class="msg_mask"></view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryBusinessProcesses, queryPointByArea, callTask} from '@/utils/getData0.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				show: false,
				disabled: false,
				options1: [],
				index1: '',
				options2: [],
				index2: '',
				options3: [],
				index3: '',
				options4: [],
				index4: '',
				options5: [],
				index5: '',
				retData: '',
				descObj: {},
				dtel: ''
			};
		},
		created () {
			this._queryBusinessProcesses()
		},
		methods: {
			selectChange1 (e) {
				if(!e){
					return
				}
				this.index1 = e
			},
			selectChange2 (e) {
				if(!e){
					return
				}
				this.index2 = e
			},
			selectChange3 (e) {
				if(!e){
					return
				}
				this.index3 = e
				this._queryPointByArea1(e)
			},
			selectChange4 (e) {
				if(!e){
					return
				}
				this.index4 = e
				this._queryPointByArea2(e)
			},
			selectChange5 (e) {
				this.index1 = ''
				this.index2 = ''
				this.index3 = ''
				this.index4 = ''
				this.options1 = []
				this.options2 = []
				this.options3 = []
				this.options4 = []
				if(!e){
					return
				}
				this.index5 = e
				let descObj = this.retData.find(item => item.name == e);
				let dictArr = descObj.dictDetails
				dictArr.map(el => {
					if (el.dictSort == 1) {
						this.options3.push({'value': el.value, 'text' :el.label})
					}
					if (el.dictSort == 2) {
						this.options4.push({'value': el.value, 'text' :el.label})
					}
				})
			},
			async _queryBusinessProcesses () {
				let res = await queryBusinessProcesses()
				console.log(res)
				this.retData = res.data
				res.data.map(el => {
					this.options5.push({'value': el.name, 'text' :el.description})
				})
			},
			/** 点位查询1 */
			async _queryPointByArea1 (a) {
				let res = await queryPointByArea(a)
				this.options1 = [...res.data]
				this.options1.map(el => {
				this.$set(el, 'value', el.device_code)
				this.$set(el, 'text', el.device_name)
				})
			},
			/** 点位查询2 */
			async _queryPointByArea2 (a) {
				let res = await queryPointByArea(a)
				this.options2 = [...res.data]
				this.options2.map(el => {
				this.$set(el, 'value', el.device_code)
				this.$set(el, 'text', el.device_name)
				})
			},
			toClear () {
				this.index1 = ''
				this.index2 = ''
				this.index3 = ''
				this.index4 = ''
				this.index5 = ''
				this.options1 = []
				this.options2 = []
				this.options3 = []
				this.options4 = []
				this.options5 = []
			},
			toPop () {
				if (this.index1 && this.index2 && this.index3 && this.index4) {
					this.show = true
				}
			},
			async _callTask () {
				this.disabled = true
				if (!this.index1 || !this.index2) {
					this.disabled = false
					return
				}
				try {
					let res = await callTask(this.index1, this.index2, '3', '')
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">
@import '../../common/style/mixin.styl';
.msg_wrapper
	height auto
	min-height 30%
</style>
