<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-7">
						<span class="filter_label">起点</span>
					</view>
					<view class="zd-col-17 filter_select">
						<zxz-uni-data-select v-model="index1" filterable :localdata="options1"></zxz-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">
						<zxz-uni-data-select v-model="index2" filterable :localdata="options2"></zxz-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>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap.stop="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !index1 || !index2 || !val1}" :disabled="disabled1" @tap="_pdaHnby">混碾搬运</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {pdaHnby} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options1: this.generateArray('HNJ', 'DJW', '混碾机', '', 8),
				index1: '',
				options2: this.generateArray('YJ', 'SLW01', '压机', '号上料位', 10),
				index2: '',
				val1: null,
				disabled1: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			generateArray(prefix, suffix, name1, name2, num) {
				const array = []
				for (let i = 1; i <= num; i++) {
					array.push({
						value: `${prefix}${String(i).padStart(2, '0')}${suffix}`,
						text: `${name1}${String(i).padStart(2, '0')}${name2}`
					})
				}
				return array
			},
			clearUp () {
				this.index1 = ''
				this.index2 = ''
				this.val1 = null
				this.disabled1 = false
			},
			async _pdaHnby () {
				this.disabled1 = true
				if (!this.index1 || !this.index2 || !this.val1) {
					this.disabled1 = false
					return
				}
				try {
					let res = await pdaHnby(this.index1, this.index2, this.val1)
					this.disabled1 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			}
		}
	}
</script>

<style lang="stylus">
@import '../../common/style/mixin.styl';
</style>
