<template>
	<view class="zd_container">
		<nav-bar :inner2="true" @goIn="goIn" title="物料查询"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料Id</span>
					</view>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</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>配盘批次</th>
								<th>物料数量</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.material_id === pkId}">
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.vehicle_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.material_qty}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar_new">
			<button class="zd-col-11 submit-button_new" :class="{'btn-disabled': !pkId}" @tap="toSure">确认</button>
			<button class="zd-col-11 submit-button_new" @tap="searchList">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryLinkMaterial} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {}
			};
		},
		methods: {
			handleChange (e) {
				this._getMaterial(e)
			},
			searchList () {
				this._getMaterial(this.val1)
			},
			/** grid查询 */
			async _getMaterial (e) {
				let res = await queryLinkMaterial(e)
				this.dataList = [...res]
			},
			toCheck (e) {
				this.pkId = this.pkId === e.material_id ? '' : e.material_id
				this.pkObj = this.pkId === e.material_id ? e : {}
			},
			toSure () {
				if (!this.pkId) {
					return
				}
				this.$store.dispatch('setPublicObj', this.pkObj)
				this.goIn()
				
			},
			goIn () {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="stylus">
</style>
