<template>
	<view class="contianer">
		<nav-bar type="2" title="退桶任务"></nav-bar>
		<view class="contianer content">
			<view class="zd-row jcenter contianer">
				<view class="setup-wrap">
					<view class="zd-row filter-item">
						<view class="zd-col-6 filter-label">起&nbsp;&nbsp;点</view>
						<view class="zd-col-18 filter-select">
							<uni-data-select v-model="val1" :localdata="options"></uni-data-select>
						</view>
					</view>
					<view class="zd-row jcenter button-wrap">
						<button class="button btn-primary" :class="{'btn-info': !val1}" :disabled="disabled" @click="_callTask">生成任务</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	// import {queryDevices} from '@/utils/mork2.js'
	import {queryDevices, callTask} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				val1: '',
				options: [],
				disabled: false
			};
		},
		mounted () {
			this._queryDevices()
		},
		methods: {
			async _queryDevices () {
				let res = await queryDevices()
				this.options = [...res]
				this.options.map(el => {
					this.$set(el, 'text', el.device_name)
					this.$set(el, 'value', el.device_code)
				})
			},
			async _callTask () {
				this.disabled = true
				try {
					let res = await callTask(this.val1)
					uni.showToast({
						title: res.message,
						icon: 'success'
					})
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
