<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-10">
						<span class="filter_label">托盘码</span>
					</view>
					<view class="zd-col-24">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">盘点单</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.code">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">盘点仓库</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.form_data.stor_code">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">创建时间</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.create_time">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">作业数量</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.dtl">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">已盘作业数量</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.finish_dtl">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">物料名称</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.material_name">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">物料编码</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.material_code">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">物料批次</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.material_spec">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-10">
						<span class="filter_label">盘点货位</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.children_form_Data.end_struct_code">
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-10">
						<span class="filter_label">盘点数量</span>
					</view>
					<view class="zd-col-24">
						<input type="text" class="filter_input" v-model="data.check_qty">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-16 button-primary" :class="{'button-info': JSON.stringify(data) === JSON.stringify({form_data: {}, children_form_Data: {}})}" :disabled="disabled" @tap="_checkSaveCheckTask">盘点确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {checkByVehicle, checkSaveCheckTask} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				data: {form_data: {}, children_form_Data: {}},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			console.log(JSON.stringify(this.data))
		},
		methods: {
			handleChange (e) {
				this._checkByVehicle(e)
			},
			async _checkByVehicle (e) {
				let res = await checkByVehicle(e)
				this.data = res.data
			},
			clearUp () {
				this.val1 = ''
				this.data = {form_data: {}, children_form_Data: {}}
			},
			async _checkSaveCheckTask () {
				this.disabled = true
				if (JSON.stringify(this.data) === JSON.stringify({form_data: {}, children_form_Data: {}})) {
					this.disabled = false
					return
				}
				try {
					let res = await checkSaveCheckTask(this.data.children_id, this.data.children_vehicle_code, this.data.check_qty, this.data.children_qty)
					if (res.code === '200') {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.clearUp()
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.disabled = false
					}
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
