<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="index" filterable :localdata="options"></zxz-uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">载具号</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">子卷号</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-7 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !index || !val1}" :disabled="disabled" @tap="_setEmptyVehicle">绑定空架</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !val2}" :disabled="disabled" @tap="_doClearPoint">清除</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getZxPointList, setEmptyVehicle, doClearPoint} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options: [],
				index: '',
				val1: '',
				val2: '',
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._getZxPointList()
		},
		methods: {
			async _getZxPointList () {
				let res = await getZxPointList()
				this.options = [...res]
			},
			clearUp () {
				this.index = ''
				this.val1 = ''
				this.val2 = ''
				this.disabled = false
			},
			async _setEmptyVehicle () {
				this.disabled = true
				if (!this.index || !this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await setEmptyVehicle(this.index, this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _doClearPoint () {
				this.disabled = true
				if (!this.val2) {
					this.disabled = false
					return
				}
				try {
					let res = await doClearPoint(this.val2)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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