<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">
						<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>
		</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 || !val1 || !val2}" :disabled="disabled1" @tap="_hnlgbd">混碾料罐绑定</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {hnlgbd} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options1: this.generateArray('HNJ', '混碾机', 8),
				index1: '',
				val1: null,
				val2: null,
				disabled1: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			generateArray(prefix, name, num) {
				const array = []
				for (let i = 1; i <= num; i++) {
					array.push({
						value: `${prefix}${String(i).padStart(2, '0')}`,
						text: `${name}${String(i).padStart(2, '0')}`
					})
				}
				return array
			},
			clearUp () {
				this.index1 = ''
				this.val1 = null
				this.val2 = null
				this.disabled1 = false
			},
			async _hnlgbd () {
				this.disabled1 = true
				if (!this.index1 || !this.val1 || !this.val2) {
					this.disabled1 = false
					return
				}
				try {
					let res = await hnlgbd(this.index1, this.val1, this.val2)
					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>
