<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-8">
						<span class="filter_label">区域</span>
					</view>
					<view class="zd-col-15 filter_select">
						<uni-data-select v-model="index1" :localdata="options1" @change="change"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-8">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-15 filter_select">
						<uni-data-select v-model="index2" :localdata="options2"></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">条码</span>
					</view>
					<view class="zd-col-17 filter_select">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">重量</span>
					</view>
					<view class="zd-col-17 filter_select">
						<input type="number" class="filter_input" v-model="val2">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">数量</span>
					</view>
					<view class="zd-col-17 filter_select">
						<input type="number" class="filter_input" v-model="val3">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !index2 || !val1 || !val2 || !val3}" :disabled="disabled" @tap="_mlTask">满料搬运</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {mlTask} from '@/utils/getData2.js'
	
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options1: [{value: 0, text: '混碾区域', point: []}, {value: 1, text: '压制区域', point: []}],
				index1: '',
				options2: [],
				index2: '',
				val1: '',
				val2: '',
				val3: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			let point1 = []
			for (let i = 0; i < 8; i++) {
				point1.push({value: `HNJ0${i+1}DJW`, text: `混碾机对接位0${i+1}`})
			}
			let point2 = []
			for (let i = 0; i < 10; i++) {
				if (i >= 9) {
					point2.push({value: `YJ${i+1}XLW01`, text: `压制机${i+1}下料位01`}, {value: `YJ${i+1}XLW02`, text: `压制机${i+1}下料位02`})
				} else {
					point2.push({value: `YJ0${i+1}XLW01`, text: `压制机0${i+1}下料位01`}, {value: `YJ0${i+1}XLW02`, text: `压制机0${i+1}下料位02`})
				}
			}
			this.options1[0].point = point1
			this.options1[1].point = point2
		},
		methods: {
			change (e) {
				this.options1.map((el, i) => {
					if (e === i) {
						this.options2 = el.point
					}
				})
			},
			clearUp () {
				this.index1 = ''
				this.index2 = ''
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
			},
			async _mlTask () {
				this.disabled = true
				if (!this.index2 || !this.val1 || !this.val2 || !this.val3) {
					this.disabled = false
					return
				}
				try {
					let res = await mlTask(this.index2, this.val1, this.val2, this.val3)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>