<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">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></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>重量(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_mode}}</td>
								<td>{{e.quality_time}}</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': !dataList.length}" :disabled="disabled" @tap="toAddMater">加入物料</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {largeMaterialBoxgetType, getInGroupInfo, materialBoxInConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options: [],
				index: '',
				val1: '',
				val2: '',
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._largeMaterialBoxgetType()
		},
		methods: {
			async _largeMaterialBoxgetType () {
				try {
					let res = await largeMaterialBoxgetType('ST_INV_IN_TYPE')
					if (res) {
						this.options = res.data
					} else {
						this.options = []
					}
				} catch (e) {
					this.options = []
				}
			},
			selectChange (e) {
				this.index = e
			},
			searchList () {
				this.dataList = []
				this._getInGroupInfo()
			},
			async _getInGroupInfo () {
				try {
					let res = await getInGroupInfo(this.val1)
					if (res && res.data.length > 0) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.index = ''
				this.dataList = []
				this.disabled = false
			},
			toAddMater () {
				if (!this.dataList.length){
					return
				}
				this.$store.dispatch('setPublicArr', this.dataList)
				let fobj = {
					bill_type: this.index,
					struct_code: this.val2,
					storagevehicle_code: this.val1
				}
				this.$store.dispatch('setPublicObj', fobj)
				uni.navigateTo({
					url: '/pages/Material/mater-save?title=物料维护'
				})
			},
		}
	}
</script>