<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-5">
						<span class="filter_label">载具编码</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">出库点位</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-5">
						<span class="filter_label">物料编码</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="data.material_code" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-5">
						<span class="filter_label">物料名称</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="data.material_name" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-5">
						<span class="filter_label">配盘批次</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="data.pcsn" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-5">
						<span class="filter_label">物料数量</span>
					</view>
					<view class="zd-col-19">
						<input type="text" class="filter_input" v-model="data.material_qty" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">出库数量</span>
					</view>
					<view class="zd-col-19">
						<input type="number" class="filter_input" v-model="val3">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">剩余数量</span>
					</view>
					<view class="zd-col-19">
						<input type="number" class="filter_input" v-model="val4">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-7 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-7 button-primary" :class="{'button-info': !val1 || !val2 ||!val4}" :disabled="disabled1" @tap="_emptyInStore">出库确认</button>
			<button class="zd-col-7 button-primary" :class="{'button-info': !val1 || !val2 ||!val4}" :disabled="disabled2" @tap="_emptyInStore">回库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryGroupInfoByVehicle, fullVehicleOutConfirm, vehicleGoBack} from '@/utils/getData2.js'
	import {accSubtract} from '@/utils/utils.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				val2: '',
				val3: '',
				data: {},
				title: '',
				disabled1: false,
				disabled2: false
			};
		},
		computed: {
			val4 () {
				let res = ''
				if (JSON.stringify(this.data) !== '{}') {
					res = accSubtract(this.data.material_qty, this.val3)
				}
				return res
			}
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				this._queryGroupInfoByVehicle(e)
			},
			async _queryGroupInfoByVehicle (e) {
				let res = await queryGroupInfoByVehicle(e)
				this.data = res
				this.val2 = this.data.point_code
			},
			async _fullVehicleOutConfirm () {
				this.disabled1 = true
				if (!this.val1  || !this.val2  || !this.val4) {
					this.disabled1 = false
					return
				}
				try {
					let res = await fullVehicleOutConfirm(this.val2, this.val1, this.val4)
					this.disabled1 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			},
			async _vehicleGoBack () {
				this.disabled2 = true
				if (!this.val1  || !this.val2  || !this.val4) {
					this.disabled2 = false
					return
				}
				try {
					let res = await vehicleGoBack(this.val2, this.val1, this.val4)
					this.disabled2 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled2 = false
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
				this.data = {}
				this.disabled1 = false
				this.disabled2 = false
			}
		}
	}
</script>

<style lang="stylus">
</style>
