<template>
	<view class="zd_container">
		<nav-bar :inner2="true" @goIn="goIn" title="物料查询"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<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.material_code}}</td>
								<td>{{e.material_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar_new">
			<button class="zd-col-24 submit-button_new" :class="{'btn-disabled': !pkId}" @tap="toSure">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryMaterial} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				dataList: [],
				pkId: '',
				pkObj: {}
			};
		},
		created () {
			this._getMaterial()
		},
		methods: {
			handleChange (e) {
				this._getMaterial(e)
			},
			async _getMaterial (e) {
				let res = await queryMaterial(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>
