<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-24 filter_select">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">所属机台</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="val2" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">工单</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="val3" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">剩余物料</span>
					</view>
					<view class="zd-col-16">
						<input type="number" v-model="val4" class="filter_input">
					</view>
					<view class="zd-col-2"><span class="filter_unit">KG</span></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>重量(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">
								<td>{{i+1}}</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>{{['', '待检', '合格', '不合格'][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': !val1 || !val3 || !val4}" :disabled="disabled" @tap="_returnConfirm">确认退回</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getOutGroupInfo, returnConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				materialData: {},
				val1: '',
				val2: '',
				val3: '',
				val4: '',
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				if (e) {
					this.searchList()
				}
			},
			searchList () {
				this.dataList = []
				this._getOutGroupInfo()
			},
			async _getOutGroupInfo () {
				try {
					let res = await getOutGroupInfo(this.val1)
					if (res && res.data.data.length > 0) {
						this.val2 = res.data.bom_code
						this.val3 = res.data.device_code
						this.dataList = res.data.data
						console.log(this.dataList, 666)
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.index = ''
				this.dataList = []
				this.disabled = false
			},
			async _returnConfirm () {
				this.disabled = true
				if (!this.val1 || !this.val3 || !this.val4) {
					this.disabled = false
					return
				}
				try {
					let res = await returnConfirm(this.val1, this.val3, this.val4)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						this.clearUp()
					}
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>