<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">
						<view class="filter_input">缓存货架区域</view>
					</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">
						<uni-data-select v-model="index2" :localdata="options2"></uni-data-select>
					</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}" :disabled="disabled" @tap="_vehicleUnbind">解绑</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {vehicleUnbind} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options2: this.generateArray('CRYHCHJ', '出入窑缓存货架'),
				index2: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			generateArray(prefix, suffix) {
				const array = []
				for (let i = 1; i <= 136; i++) {
					array.push({
						value: `${prefix}${String(i).padStart(3, '0')}`,
						text: `${suffix}${String(i).padStart(3, '0')}`
					})
				}
				return array
			},
			clearUp () {
				this.index2 = ''
				this.disabled = false
			},
			async _vehicleUnbind () {
				this.disabled = true
				if (!this.index2) {
					this.disabled = false
					return
				}
				try {
					let res = await vehicleUnbind(this.index2)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
