<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">
						<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">
						<input v-model="val2" type="text" class="filter_input">
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7">
						<span class="filter_label">呼叫收卷辊</span>
					</view>
					<view class="relative zd-col-17">
						<switch :checked="isChecked" color="#6798ef" style="transform:scale(0.8)"/>
						<text @tap="setWStatus" style="position: absolute;display: inline-block;width: 52px; height: 32px;left: 0;"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-3 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_needEmptyVehicle">呼叫空辊</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_necessaryEmptyVehicle">空辊回库</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1 || !val2}" :disabled="disabled" @tap="_needEmptyAxisv2">生箔下料</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_confirmBlanking">准备就绪</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {needEmptyVehicle, necessaryEmptyVehicle, needEmptyAxisv2, confirmBlanking} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				isChecked: false,
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			setWStatus () {
				this.isChecked = !this.isChecked
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.isChecked = false
				this.disabled = false
			},
			async _needEmptyVehicle () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await needEmptyVehicle(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _necessaryEmptyVehicle () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await necessaryEmptyVehicle(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _needEmptyAxisv2 () {
				this.disabled = true
				if (!this.val1 || !this.val2) {
					this.disabled = false
					return
				}
				try {
					let checked = this.isChecked ? '1' : '0'
					let res = await needEmptyAxisv2(this.val1, this.val2, checked)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _confirmBlanking () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await confirmBlanking(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
.button-primary
	font-size: 28rpx;
</style>
