<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="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="toSure">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {regionSearch, pointSearch, taskCarry} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				dataList: [],
				disabled: false,
				options1: [],
				index1: '',
				options2: [],
				index2: '',
				options3: [],
				index3: '',
				options4: [],
				index4: '',
			};
		},
		created () {
			this._regionSearch3('')
			this._regionSearch4('')
		},
		methods: {
			selectChange1 (e) {
				this.index1 = e
			},
			selectChange2 (e) {
				this.index2 = e
			},
			selectChange3 (e) {
				this.index3 = e
				this._pointSearch1(e)
			},
			selectChange4 (e) {
				this.index4 = e
				this._pointSearch2(e)
			},
			async _regionSearch3 (a) {
				let res = await regionSearch(a)
				this.options3 = [...res]
				this.options3.map(el => {
				this.$set(el, 'value', el.region_code)
				this.$set(el, 'text', el.region_name)
				})
			},
			async _regionSearch4 (a) {
				let res = await regionSearch(a)
				this.options4 = [...res]
				this.options4.map(el => {
				this.$set(el, 'value', el.region_code)
				this.$set(el, 'text', el.region_name)
				})
			},
			/** 点位查询1 */
			async _pointSearch1 (a) {
				let res = await pointSearch(a, '', '1')
				this.options1 = [...res]
				this.options1.map(el => {
				this.$set(el, 'value', el.point_code)
				this.$set(el, 'text', el.point_name)
				})
			},
			/** 点位查询2 */
			async _pointSearch2 (a) {
				let res = await pointSearch(a, '', '0')
				this.options2 = [...res]
				this.options2.map(el => {
				this.$set(el, 'value', el.point_code)
				this.$set(el, 'text', el.point_name)
				})
			},
			toClear () {
				this.index1 = ''
				this.index2 = ''
			},
			toSure () {
				this.disabled = true
				if (!this.index1 || !this.index2) {
					this.disabled = false
					return
				}
				uni.showModal({
					title: '提示',
					content: '确认终点无货状态',
					confirmColor: '#ff6a00',
					success: function (res) {
						if (res.confirm) {
							this._taskCarry()
						} else if (res.cancel) {
							this.disabled = false
						}
					}
				})
			},
			async _taskCarry () {
				try {
					let res = await taskCarry(this.index1, this.index2)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">
</style>
