<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 filter_input_disabled">单据号</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="materialData.check_code" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">点位/载具</span>
					</view>
					<view class="zd-col-17">
						<search-box
						v-model="val1"
						 @handleChange="handleChange"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">点位</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="materialData.struct_code" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">物料编码</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="materialData.material_code" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">物料名称</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="materialData.material_name" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">库存数量</span>
					</view>
					<view class="zd-col-16">
						<input type="number" v-model="materialData.qty1" class="filter_input" disabled>
					</view>
					<view class="zd-col-2"><span class="filter_unit">KG</span></view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">盘点数量</span>
					</view>
					<view class="zd-col-16">
						<input type="number" v-model="materialData.fac_qty" class="filter_input">
					</view>
					<view class="zd-col-2"><span class="filter_unit">KG</span></view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-24 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_materialBoxInventoryConfirm">确认盘点</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getInvInfoQty, materialBoxInventoryConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				materialData: {},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		onShow () {
			if (this.$store.getters.publicObj !== '') {
				this.materialData = this.$store.getters.publicObj
				this.$store.dispatch('setPublicObj', '')
			}
		},
		methods: {
			handleChange (e) {
				if (e) {
					this._getInvInfoQty()
				}
			},
			clearUp () {
				this.val1 = ''
				this.disabled = false
			},
			async _getInvInfoQty () {
				let res = await getInvInfoQty(this.val1)
				this.materialData.qty1 = res.data.base_qty
				this.materialData.fac_qty = res.data.base_qty
			},
			async _materialBoxInventoryConfirm () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await materialBoxInventoryConfirm(this.materialData)
					if (res.code === '200') {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						this.clearUp()
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						this.disabled = false
					}
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
