<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 filter_input_disabled">入库类型</span>
					</view>
					<view class="zd-col-24 filter_select">
						<uni-data-select v-model="index" :localdata="options" disabled></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">载具</span>
					</view>
					<view class="zd-col-24 filter_select">
						<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-24 filter_select">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th>载具号</th>
								<th>物料编码</th>
								<th>物料名称</th>
								<th>批次</th>
								<th>重量(kg)</th>
								<th>生产日期</th>
								<th>供应商编码</th>
								<th>供应商名称</th>
								<th>规格</th>
								<th>型号</th>
								<th>有效期(天)</th>
								<th>执行标准</th>
								<th>品质类型</th>
								<th>烘干次数</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.storagevehicle_code === pkId}" @tap="toCheck(e)">
								<td>{{i+1}}</td>
								<td>{{e.storagevehicle_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.qty}}</td>
								<td>{{e.produce_time}}</td>
								<td>{{e.supp_code}}</td>
								<td>{{e.supp_name}}</td>
								<td>{{e.material_spec}}</td>
								<td>{{e.material_model}}</td>
								<td>{{e.quality_time_day}}</td>
								<td>{{e.execution_stand}}</td>
								<td>{{['', '待检', '合格', '不合格'][Number(e.quality_type)]}}</td>
								<td>{{e.bake_num}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-primary" @tap="searchList">查询</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !index || !val2 || !dataList.length}" :disabled="disabled" @tap="_pdaSmallBoxconfirmIn">确认入库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryGroupInfo, pdaSmallBoxconfirmIn} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options: [{text:'收货入库', value: '0001'}],
				index: '0001',
				val1: '',
				val2: '',
				pkId: '',
				pkObj: {},
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			toCheck (e) {
				this.pkId = this.pkId === e.storagevehicle_code ? '' : e.storagevehicle_code
				this.pkObj = this.pkId === e.storagevehicle_code ? e : {}
				this.val1 = e.storagevehicle_code
				this.searchList()
			},
			searchList () {
				this.dataList = []
				this._queryGroupInfo()
			},
			async _queryGroupInfo () {
				try {
					let res = await queryGroupInfo(this.val1)
					if (res && res.data.length > 0) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			clearUp () {
				this.val1 = ''
				this.dataList = []
				this.disabled = false
			},
			async _pdaSmallBoxconfirmIn () {
				this.disabled = true
				if (!this.index || !this.val2 || !this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await pdaSmallBoxconfirmIn(this.index, this.val2, this.dataList)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						this.clearUp()
					}
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>