<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-6">
						<span class="filter_label">单据</span>
					</view>
					<view class="zd-col-13">
						<search-box v-model="keyword"/>
					</view>
					<button class="mini-btn" type="primary" size="mini" @tap="_getCheckDocumentInfo">查询</button>
				</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>
								<th>重量(kg)</th>
								<th>盘点重量(kg)</th>
								<th>生产日期</th>
								<th>供应商编码</th>
								<th>供应商名称</th>
								<th>烘干次数</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.check_id === pkId}" @tap="toCheck(e)">
								<td>{{i+1}}</td>
								<td>{{e.check_result_name}}</td>
								<td>{{e.struct_code}}</td>
								<td>{{e.storagevehicle_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.base_qty}}</td>
								<td>{{e.fac_qty}}</td>
								<td>{{e.produce_time}}</td>
								<td>{{e.supp_code}}</td>
								<td>{{e.supp_name}}</td>
								<td>{{e.bake_num}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-24 button-primary" :class="{'button-info': !pkId}" @tap="toSure">扫码盘点</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getDate} from '@/utils/utils.js'
	import {getCheckDocumentInfo} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				keyword: '',
				dataList: [],
				statusMap: {
                    '10': '生成',
                    '20': '盘点中',
                    '99': '完成'
                },
				pkId: '',
				pkObj: {}
			};
		},
		onLoad (options) {
			this.title = options.title
			this._getCheckDocumentInfo()
		},
		methods: {
			async _getCheckDocumentInfo () {
				try {
					let res = await getCheckDocumentInfo(this.keyword, '1')
					if (res && res.data.length > 0) {
						this.dataList = res.data.map(item => ({
						...item,
						check_result_name: this.statusMap[item.check_result] || ''
						}))
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.check_id ? '' : e.check_id
				this.pkObj = this.pkId === e.check_id ? e : {}
			},
			toSure () {
				if (this.pkId) {
					this.$store.dispatch('setPublicObj', this.pkObj)
					uni.navigateTo({
						url: '/pages/Material/hw-check?title=货位盘点'
					})
				}
			}
		}
	}
</script>