<template>
	<view class="content">
		<nav-bar :inner2="true" @goIn="goIn" 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">
						<input type="text" class="search-input-l" v-model="val1">
					</view>
				</view>
				<view class="search-item search-item-btns">
					<button class="confirm-button" @tap="toSearch">查询</button>
					<button class="confirm-button" :class="{'confirm-button_disabled': !pkId || !index2 || !val1}" :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>
						<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>
						<td></td>
						<td></td>
						<td></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 {
				val1: '',
				dataList: [],
				pkId: '',
				disabled: false
			};
		},
		methods: {
			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.pkId, this.index3) 
				this.disabled = false
				this.toSearch()
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled = false
			  }
			},
			toRadio (e) {
			  this.pkId = this.pkId === e.position_code ? '' : e.position_code
			},
			goIn () {
				uni.redirectTo({
					url: '/pages/management/FinishedInStore'
				})
			}
		}
	}
</script>

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