<template>
	<view class="zd_container">
		<nav-bar title="盘点管理"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label">单据编码</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input" v-model="val1">
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">仓库</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></uni-data-select>
					</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>
								<th>创建时间</th>
								<th>确认人</th>
								<th>确认时间</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.check_code === pkId}">
								<td>{{e.check_code}}</td>
								<td>{{e.check_type}}</td>
								<td>{{e.stor_name}}</td>
								<td>{{e.dtl_num}}</td>
								<td>{{e.status}}</td>
								<td>{{e.is_nok}}</td>
								<td>{{e.input_optname}}</td>
								<td>{{e.input_time}}</td>
								<td>{{e.confirm_optname}}</td>
								<td>{{e.confirm_time}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-15 btn-submit btn-success letter-30" :class="{'btn-info': !pkId}" :disabled="disabled1" @tap="toPandian">盘点</button>
			<button class="zd-col-6 btn-submit btn-success letter-30" @tap="_checkQuery">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {checkQuery, checkgetStor} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
		},
		data() {
			return {
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				options: [],
				index: '1582991156504039424', // 默认兰州仓库
				disabled1: false
			};
		},
		created () {
			this._checkgetStor()
			this._checkQuery()
		},
		methods: {
			/** 初始化查询 */
			async _checkQuery () {
				let res = await checkQuery(this.val1, this.index)
				this.dataList = [...res.data]	
			},
			/** 选择器 */
			selectChange(e) {
				this.index = e
			},
			/** 仓库下拉框查询 */
			async _checkgetStor () {
				let res = await checkgetStor()
				this.options = [...res.data]
			},
			toPandian () {
				if (this.pkId) {
					uni.navigateTo({
						url: '/pages/WarehouseManage/CheckDtl?checkcode=' + this.pkObj.check_code + '&checknum=' + this.pkObj.check_num + '&unchecknum=' + this.pkObj.uncheck_num
					})
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.check_code ? '' : e.check_code
				this.pkObj = this.pkId === e.check_code ? e : {}
			}
		}
	}
</script>