<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="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'">
						<span class="filter_label">{{$t('filter.ck')}}</span>
					</view>
					<view class="filter_select" :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'">
						<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="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.kwbm')}}</span></view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'"><span class="filter_input">{{currentData.struct_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.zjbm')}}</span></view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'"><span class="filter_input">{{currentData.vehicle_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.wlbm')}}</span></view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'"><span class="filter_input">{{currentData.material_code}}</span></view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.pcsn')}}</span></view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'"><span class="filter_input">{{currentData.pcsn}}</span></view>
				</view>
				<view class="zd-row">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.cj')}}</span></view>
					<view class="zd-col-17 filter_select">
						<uni-data-select v-model="currentData.product_area" :placeholder="$t('uni.dataSelect.placeholder')" :emptyTips="$t('uni.dataSelect.emptyTips')" :localdata="options1"></uni-data-select>
					</view>
				</view>
				<view class="zd-row">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'"><span class="filter_label">{{$t('filter.ckkc')}}</span></view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : '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">{{$t('btn.cancle')}}</button>
			<button class="zd-col-16 button-primary" :class="{'button-info': JSON.stringify(currentData) === '{}'}" :disabled="disabled" @tap="_outStorageMaterConfirm">{{$t('btn.ckqr')}}</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' + this.$t('text.cj')}, {value: 'A2', text: 'A2' + this.$t('text.cj')}, {value: 'A3', text: 'A3' + this.$t('text.cj')}],
				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 = this.$t('text.tpk')
				} else if (this.currentData.stor_code === 'FStockId') {
					this.val1 = this.$t('text.lxk')
				}
				this.$store.dispatch('setPublicObj', '')
			}
		},
		methods: {
			toJump () {
				uni.navigateTo({
					url: '/pages/outbound/stock-list?title=' + this.$t('nav.kclb')
				})
			},
			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';
</style>
