<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>
			<view class="zd-row mgb20">
				<button class="zd-col-11 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_needEmptyVehicle">呼叫空辊</button>
				<button class="zd-col-11 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_necessaryEmptyVehicle">空辊回库</button>
			</view>
			<view class="zd-row mgb20">
				<button class="zd-col-11 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_confirmBlanking('1')">允许进入</button>
				<button class="zd-col-11 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_confirmBlanking('2')">允许离开</button>
			</view>
			<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="val2"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">呼叫收卷辊</span>
					</view>
					<view class="relative zd-col-17">
						<switch :checked="isChecked" color="#6798ef"/>
						<text @tap="setWStatus" style="position: absolute;display: inline-block;width: 52px; height: 32px;left: 0;"></text>
					</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_picker">
						<picker @change="pickerChange" :value="index1" :range="options1" range-key="text">
							<view class="uni-input">{{index1 !== '' ? options1[index1].text : ''}}</view>
						</picker>
					</view>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">幅宽</span>
					</view>
					<view class="zd-col-17 filter_picker">
						<picker @change="pickerChange2" :value="index2" :range="options2" range-key="text">
							<view class="uni-input">{{index2 !== '' ? options2[index2].text : ''}}</view>
						</picker>
					</view>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">温度</span>
					</view>
					<view class="zd-col-14">
						<input v-model="temperature" type="number" class="filter_input">
					</view>
					<view class="zd-col-3 filter_label">度</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">时间</span>
					</view>
					<view class="zd-col-14">
						<input v-model="time" type="number" class="filter_input">
					</view>
					<view class="zd-col-3 filter_label">小时</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="val4" type="number" class="filter_input">
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7">
						<span class="filter_label">重量</span>
					</view>
					<view class="zd-col-17">
						<input v-model="val5" type="number" class="filter_input">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-8 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !val1 || !val2 || index2 === ''}" :disabled="disabled" @tap="_needEmptyAxisv2">生箔下料</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: '',
				val4: '',
				val5: '',
				options1: [{value: '1', text: '大卷'}, {value: '2', text: '小卷'}],
				index1: '',
				options2: [{value: '1', text: '幅宽大于1550'}, {value: '0', text: '幅宽小于1550'}],
				index2: '',
				temperature: null,
				time: null,
				isChecked: false,
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			setWStatus () {
				this.isChecked = !this.isChecked
			},
			pickerChange (e) {
				this.index1 = e.detail.value
			},
			pickerChange2 (e) {
				this.index2 = e.detail.value
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.isChecked = false
				this.disabled = false
				this.val4 = ''
				this.val5 = ''
				this.index1 = ''
				this.temperature = null
				this.time = null
				this.index2 = ''
			},
			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.index2 === '') {
					this.disabled = false
					return
				}
				try {
					let checked = this.isChecked ? '1' : '0'
					let index1 = this.index1 === '' ? '' : this.options1[this.index1].value
					let res = await needEmptyAxisv2(this.val1, this.val2, checked, this.val4, this.val5, index1, this.temperature, this.time, this.options2[this.index2].value)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _confirmBlanking (type) {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await confirmBlanking(this.val1, type)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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