<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>
								<th>盘点库区</th>
								<th>盘点货位</th>
								<th>数量</th>
								<th>盘点数量</th>
								<th>确认人</th>
								<th>确认时间</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{e.check_code}}</td>
								<td>{{e.status}}</td>
								<td>{{e.sect_name}}</td>
								<td>{{e.struct_name}}</td>
								<td>{{e.base_qty}}</td>
								<td><input type="number" class="sin_input" :min="0" v-model="value" @blur="e => {if (e.target.value === '') {value=0}}" v-enter-number></td>
								<td>{{e.check_optname}}</td>
								<td>{{e.check_time}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !dataList.length}" :disabled="disabled1" @tap="_saveCheck">保存</button>
			<button class="submit-button" :class="{'btn-disabled': !dataList.length}" :disabled="disabled1" @tap="_confirmCheck">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {checkQueryDtl, saveCheck, confirmCheck} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
		},
		data() {
			return {
				value: '1',
				checkCode: '',
				dataList: [],
				disabled1: false
			};
		},
		created () {
		},
		onLoad (option) {
			this.checkCode = option.check_code
			this._checkQueryDtl()
		},
		methods: {
			goIn () {
				uni.navigateTo({
					url: `/pages/WarehouseManage/CheckList`
				})
			},
			handleChange (e) {
				// console.log(e)
			},
			/** 初始化查询 */
			async _checkQueryDtl () {
				let res = await checkQueryDtl(this.checkCode)
				this.dataList = [...res.data]
			},
			async _saveCheck () {
				this.disabled1 = true
				try {
					let res = await saveCheck(this.dataList, this.checkCode)
					this.disabled1 = false
					this._checkQueryDtl()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			},
			async _confirmCheck () {
				this.disabled1 = true
				try {
					let res = await confirmCheck(this.dataList, this.checkCode)
					this.disabled1 = false
					this._checkQueryDtl()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			}
		}
	}
</script>

<style lang="stylus">
	.zd_content
		padding-bottom 77rpx
	.slide_new table td:nth-child(1), .slide_new table th:nth-child(1)
		box-shadow 1px 0 2px rgba(0,0,0,.12)
	.bgyellow td
		background-color #E9B451
</style>
