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

<script>
	import NavBar from '@/components/NavBar.vue'
	import {getLtxPointList, ltxTask} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				options1: [],
				index1: '',
				options2: [{value: '0', text: '下料'}, {value: '1', text: '上空架'}],
				index2: '',
				disabled: false
			};
		},
		created () {
			this._getLtxPointList()
		},
		methods: {
			selectChange1 (e) {
				this.index1 = e
			},
			selectChange2 (e) {
				this.index2 = e
			},
			/** 下拉框查询 */
			async _getLtxPointList () {
				let res = await getLtxPointList()
				res.map(el => {
					this.$set(el, 'value', el.point_code)
					this.$set(el, 'text', el.point_name)
				})
				this.options1 = [...res]
			},
			toClear () {
				this.index1 = ''
				this.index2 = ''
			},
			async _ltxTask () {
				this.disabled = true
				if (!this.index1 || !this.index2) {
					this.disabled = false
					return
				}
				try {
					let res = await ltxTask(this.index1, this.index2)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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