<template>
	<view class="zd_container">
		<!-- <nav-bar title="烘烤工序"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item is-required">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('grid.point-code')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val1" @handleChange="handleChange1"/>
					</view>
				</view>
				<view class="filter_item is-required">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('filter.mother-roll')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val2" />
					</view>
				</view>
				<view class="filter_item is-required">
					<view class="filter_label">{{$t('filter.temperature')}}</view>
					<view class="filter_input_wraper">
						<!-- <input type="number" class="filter_input" v-model="val3"> -->
						<NumberInput
						v-model="val3"
						input-class="filter_input"
						mode="mixed"
						:decimalLength="3"
						/>
					</view>
				</view>
				<view class="filter_item is-required">
					<view class="filter_label">{{$t('filter.time')}}({{$t('unit.minute')}})</view>
					<view class="filter_input_wraper">
						<!-- <input type="number" class="filter_input" v-model="val4"> -->
						<NumberInput
						v-model="val4"
						input-class="filter_input"
						mode="integer"
						/>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-4 btn-submit btn-default" @tap="clearUp">{{$t('button.clear')}}</button>
			<button class="zd-col-6 btn-submit btn-success" :class="{'btn-info': !val1 || !val2 || !val3 || !val4}" :disabled="disabled" @tap="handleConfirm('1')">{{$t('button.enter-box')}}</button>
			<button class="zd-col-6 btn-submit btn-success" :class="{'btn-info': !val1 || !val2}" :disabled="disabled" @tap="handleConfirm('2')">{{$t('button.out-box')}}</button>
			<button class="zd-col-6 btn-submit btn-success" :disabled="disabled" @click="_inHotByPoint">定点入箱</button>
		</view>
		<view class="msg_wrapper" :class="active ? 'popshow' : 'pophide'" style="height: auto">
			<view class="pop-line"></view>
			<view class="msg_content">
				<view class="zd_wrapper zd_wrapper-1">
					<view class="filter_item">
						<view class="filter_label_wraper">
							<span class="filter_label">{{$t('filter.starting-point')}}</span>
						</view>
						<view class="filter_input_wraper">
							<search-box v-model="val5"/>
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label_wraper">
							<span class="filter_label">{{$t('grid.mother-roll-number')}}</span>
						</view>
						<view class="filter_input_wraper">
							<search-box v-model="val6" />
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label">{{$t('filter.temperature')}}</view>
						<view class="filter_input_wraper">
							<NumberInput
							v-model="val7"
							input-class="filter_input"
							mode="mixed"
							:decimalLength="3"
							/>
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label">{{$t('filter.time')}}({{$t('unit.minute')}})</view>
						<view class="filter_input_wraper">
							<NumberInput
							v-model="val8"
							input-class="filter_input"
							mode="integer"
							/>
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label_wraper">
							<span class="filter_label">{{$t('filter.end')}}</span>
						</view>
						<view class="filter_input_wraper">
							<search-box v-model="val9"/>
						</view>
					</view>
				</view>
			</view>
			<view class="zd-row submitbar">
				<button class="zd-col-11 btn-submit btn-default letter-30" @tap="cancleModal">{{$t('button.cancel')}}</button>
				<button class="zd-col-11 btn-submit btn-success letter-30" @tap="modalToSure">{{$t('button.confirm')}}</button>
			</view>
		</view>
		<view v-if="active" class="msg_mask"></view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import NumberInput from '@/components/NumberInput.vue'
	import { confirmAction } from '@/utils/utils.js'
	import {ovenInAndOut, bakingquery, inHotByPoint} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			NumberInput
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				val3: '',
				val4: '',
				disabled: false,
				active: false,
				val5: '',
				val6: '',
				val7: '',
				val8: '',
				val9: ''
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange1 (e) {
				this._bakingquery(e)
			},
			/** 查询 */
			async _bakingquery (val1) {
				if (!val1) {
					return
				}
				let res = await bakingquery(val1)
				this.val2 = res.data.container_name
			},
			async handleConfirm(type) {
				if ((!this.val1 || !this.val2 ||!this.val3 || !this.val4) && type === '1') {
					return
				}
				if ((!this.val1 || !this.val2) && type === '2') {
					return
				}
				const isConfirmed = await confirmAction("确认操作", "确定要执行此操作吗？")
				if (isConfirmed) {
					if (type === '1') {
						this._ovenInAndOut1(type)
					}
					if (type === '2') {
						this._ovenInAndOut2(type)
					}
				}
			},
			async _ovenInAndOut1 (type) {
				this.disabled = true
				try {
					let res = await ovenInAndOut(this.val1, this.val2,this.val3, this.val4, type)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.clearUp()
				} catch (e) {
					this.disabled = false
				}
			},
			async _ovenInAndOut2 (type) {
				this.disabled = true
				try {
					let res = await ovenInAndOut(this.val1, this.val2,'', '', type)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.clearUp()
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
				this.val4 = ''
				this.disabled = false
			},
			_inHotByPoint () {
				this.active = true
				this.disabled = true
			},
			cancleModal () {
				this.val5 = ''
				this.val6 = ''
				this.val7 = ''
				this.val8 = ''
				this.val9 = ''
				this.active = false
				this.disabled = false
			},
			async modalToSure () {
				try {
					let res = await inHotByPoint(this.val5, this.val6, this.val7, this.val8, this.val9)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.cancleModal()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>