<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row mgb20 border-bottom">
					<uni-icons type="arrow-up" size="18" color="#ff6a00"></uni-icons>
					<view class="zd-col-6 filter_label">任务起点</view>
					<view class="zd-col-18 relative">
						<input type="text" class="filter_input" v-model="sCode">
					</view>
				</view>
				<view class="zd-row">
					<uni-icons type="arrow-down" size="18" color="#ff6a00"></uni-icons>
					<view class="zd-col-6 filter_label">任务终点</view>
					<view class="zd-col-18 relative">
						<input type="text" class="filter_input" v-model="nCode">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-11 button-primary" :disabled="disabled" @tap="toSure('1')">搬运任务</button>
			<button class="zd-col-11 button-primary" :disabled="disabled" @tap="toCharge">充电任务</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryArea, queryPointByArea, callTask, taskCharge} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				title: '',
				disabled: false,
				sCode: 'QFQ_2',
				nCode: 'QFQ_4'
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			toSure (type) {
				this.disabled = true
				uni.showModal({
					title: '提示',
					cancelText: '取消',
					confirmText: '确定',
					content: '是否需要下发？',
					success: (res) => {
						if (res.confirm) {
							this._callTask(type)
						} else if (res.cancel) {
							this.disabled = false
						}
					}
				})
			},
			async _callTask (type) {
				try {
					let res = await callTask(this.sCode, this.nCode, type)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (err) {
					this.disabled = false
				}
			},
			toCharge () {
				this.disabled = true
				uni.showModal({
					title: '提示',
					cancelText: '取消',
					confirmText: '确定',
					content: '是否需要充电？',
					success: (res) => {
						if (res.confirm) {
							this._taskCharge()
						} else if (res.cancel) {
							this.disabled = false
						}
					}
				})
			},
			async _taskCharge () {
				try {
					let res = await taskCharge()
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (err) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.item-font-6
	color #fff
.filter_label
	padding-left 0
.pop_point_content_up
	top -200rpx
</style>
