<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-7">
						<span class="filter_label">仓库</span>
					</view>
					<view class="zd-col-24 filter_select">
						<input type="text" class="filter_input" v-model="val1" @tap="toJump">
					</view>
				</view>
			</view>
			<view v-if="JSON.stringify(currentData) !== '{}'" class="zd_wrapper">
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-7"><span class="filter_label">库位</span></view>
					<view class="zd-col-17"><span class="filter_input">{{currentData.struct_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-7"><span class="filter_label">载具编码</span></view>
					<view class="zd-col-17"><span class="filter_input">{{currentData.vehicle_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-7"><span class="filter_label">物料编码</span></view>
					<view class="zd-col-17"><span class="filter_input">{{currentData.material_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-7"><span class="filter_label">批号</span></view>
					<view class="zd-col-17"><span class="filter_input">{{currentData.pcsn}}</span></view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7"><span class="filter_label">车间</span></view>
					<view class="zd-col-17 filter_select">
						<uni-data-select v-model="currentData.product_area" :localdata="options1"></uni-data-select>
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7"><span class="filter_label">出库库存</span></view>
					<view class="zd-col-17">
						<input type="number" v-model="currentData.qty" class="filter_input">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="toEmpty">清空</button>
			<button class="zd-col-16 button-primary" :class="{'button-info': JSON.stringify(currentData) === '{}'}" :disabled="disabled" @tap="_outStorageMaterConfirm">确认出库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {outStorageMaterConfirm} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				currentData: {},
				options1: [{value: 'A1', text: 'A1车间'}, {value: 'A2', text: 'A2车间'}, {value: 'A3', text: 'A3车间'}],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		onShow () {
			if (this.$store.getters.publicObj !== '') {
				this.currentData = this.$store.getters.publicObj
				if (this.currentData.stor_code === 'FStockPallet') {
					this.val1 = '托盘库'
				} else if (this.currentData.stor_code === 'FStockId') {
					this.val1 = '料箱库'
				}
				if (!this.currentData.product_area) {
					this.currentData.product_area = 'A1'
				}
				this.$store.dispatch('setPublicObj', '')
			}
		},
		methods: {
			toJump () {
				uni.navigateTo({
					url: '/pages/outbound/stock-list?title=库存列表'
				})
			},
			async _outStorageMaterConfirm () {
				this.disabled = true
				if (JSON.stringify(this.currentData) === '{}') {
					this.disabled = false
					return
				}
				let obj = Object.assign(this.currentData, {now_assign_qty: this.currentData.qty})
				try {
					let res = await outStorageMaterConfirm(obj)
					if (res.code === '200') {
						this.toEmpty()
					}
					this.disabled = false
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			toEmpty () {
				this.val1 = ''
				this.currentData = {}
				this.disabled = false
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.button-primary, .button-default
	_fj(center)
	font-size 26rpx
	height 88rpx
	line-height 30rpx
</style>
