<template>
	<view class="content">
		<nav-bar title="扫码异常"></nav-bar>
		<view class="search-confirm-wrap">
			<view class="search-wrap">
				<view class="search-item">
					<label class="search-label">生产区域</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">缓存线</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">位置类型</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index3" :localdata="options3" @change="selectChange3"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">满箱码</label>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="search-item_2">
					<!-- <button class="confirm-button" @tap="toSearch">查询</button> -->
					<button class="confirm-button" :class="{'confirm-button_disabled': !index2 || !val1 || !index3}" :disabled="disabled" @tap="toSure">确认</button>
				</view>
			</view>
		</view>
		<!-- <view class="grid-wrap">
			<table class="grid-table">
				<thead>
					<tr>
						<th>选择</th>
						<th>缓存线编码</th>
						<th>缓存线位置编码</th>
						<th>料箱码</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="e in dataList" :key="e.position_code"  @click="toRadio(e)">
						<td>
							<view class="iconfont icon-check" :class="{'icon-checked': pkId === e.position_code}"></view>
						</td>
						<td>{{e.cacheline_code}}</td>
						<td>{{e.position_code}}</td>
						<td>{{e.vehicle_code}}</td>
					</tr>
				</tbody>
			</table>
		</view> -->
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getCacheLine, inOutExceptionInstQuery, inOutExceptionInstConfirm} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				options1: [{text: 'A1', value: 'A1'}, {text: 'A2', value: 'A2'}],
				index1: 'A1',
				options2: [],
				index2: '',
				options3: [{text: '对接位', value: '1'}, {text: '准备位', value: '2'}],
				index3: '1',
				val1: '',
				dataList: [],
				pkId: '',
				disabled: false
			};
		},
		created() {
			this._getCacheLine('A1')
		},
		methods: {
			/** 选择器1 */
			selectChange1(e) {
				this.index1 = e
				if (this.index1) {
					this._getCacheLine(e)
				}
				this.index2 = ''
			},
			/** 选择器2 */
			selectChange2(e) {
				this.index2 = e
			},
			/** 选择器3 */
			selectChange3(e) {
				this.index3 = e
			},
			toSearch () {
			  this.dataList = []
			  this.pkId = ''
			  this._inOutExceptionInstQuery()
			},
			async _getCacheLine (id) {
				let res = await getCacheLine(id)
				this.options2 = [...res]
			},
			// async _inOutExceptionInstQuery () {
			// 	let res = await inOutExceptionInstQuery(this.index2)
			// 	this.dataList = [...res]
			// },
			async toSure () {
			  this.disabled = true
			 //  if (!this.pkId) {
				// uni.showToast({
				// 	title: '请选择',
				// 	icon: 'none'
				// })
				// this.disabled = false
				// return
			 //  }
			  if (!this.index2) {
				uni.showToast({
					title: '请选择缓存线',
					icon: 'none'
				})
				this.disabled = false
				return  
			  }
			  if (!this.index3) {
				uni.showToast({
					title: '请选择位置类型',
					icon: 'none'
				})
				this.disabled = false
				return  
			  }
			  if (!this.val1) {
				uni.showToast({
					title: '请扫满箱码',
					icon: 'none'
				})
				this.disabled = false
				return  
			  }
			  try {
				let res = await inOutExceptionInstConfirm(this.index2, this.val1, this.index3) 
				this.disabled = false
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled = false
			  }
			},
			toRadio (e) {
			  this.pkId = this.pkId === e.position_code ? '' : e.position_code
			}
		}
	}
</script>

<style lang="stylus" scoped>
.grid-wrap	
    height: calc(100% - 187px); /** 42+ 15*5+ 35*2 */
</style>