<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-18 filter_picker">
						<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
							<view class="uni-input">{{date}}</view>
						</picker>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">单据</span>
					</view>
					<view class="zd-col-14">
						<input type="text" placeholder="输入物料关键字" class="filter_input" v-model="keyword" @focus="handleFocus">
					</view>
					<button class="mini-btn" type="primary" size="mini" @tap="_getIoDisDocumentInfo">查询</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>批号</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.iostorinv_id === pkId}" @tap="toCheck(e)">
								<td>{{i+1}}</td>
								<td>{{e.bill_code}}</td>
								<td>{{e.bill_type_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.total_qty}}</td>
								<td>{{e.plan_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 {getIoDisDocumentInfo} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			const currentDate = getDate({
				format: true
			})
			return {
				title: '',
				keyword: null,
				date: currentDate,
				dataList: [],
				statusMap: {
                    '1001': '领料出库',
                    '1002': '质检出库',
                    '1003': '退货出库',
                    '1004': '烘干出库',
                    '1009': '手工出库'
                },
				pkId: '',
				pkObj: {},
			};
		},
		computed: {
			startDate() {
				return getDate('start');
			},
			endDate() {
				return getDate('end');
			}
		},
		onLoad (options) {
			this.title = options.title
			this._getIoDisDocumentInfo()
		},
		methods: {
			handleFocus () {
				this.keyword = null
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			async _getIoDisDocumentInfo () {
				try {
					let res = await getIoDisDocumentInfo(this.keyword, this.date, '1')
					if (res && res.data.length > 0) {
						this.dataList = res.data.map(item => ({
						...item,
						bill_type_name: this.statusMap[item.bill_type] || ''
						}))
					} else {
						this.dataList = []
					}
				} catch (e) {
					this.dataList = []
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.iostorinv_id ? '' : e.iostorinv_id
				this.pkObj = this.pkId === e.iostorinv_id ? e : {}
			},
			toSure () {
				if (this.pkId) {
					this.$store.dispatch('setPublicObj', this.pkObj)
					uni.navigateTo({
						url: '/pages/Material/hw-out-store?title=货位出库'
					})
				}
			}
		}
	}
</script>