<template>
	<view class="content">
		<nav-bar title="半成品入库"></nav-bar>
		<view class="filter-confirm-wrap">
			<view class="filter-confirm-wrap-inner">
				<view class="filter-wrap">
					<view class="search-item filter-item">
						<label class="search-label">订单号</label>
						<view class="filter_input_wraper">
							<input type="text" class="search-input-l" v-model="val1">
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">物料</label>
						<view class="filter_input_wraper" @tap="toSearch">
							<input type="text" class="search-input-l" v-model="val2">
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">名称</label>
						<view class="filter_input_wraper" @tap="toSearch">
							<input type="text" class="search-input-l" v-model="val3">
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">规格</label>
						<view class="filter_input_wraper" @tap="toSearch">
							<input type="text" class="search-input-l" v-model="val4">
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">数量</label>
						<view class="filter_input_wraper">
							<input type="number" class="search-input-l" v-model="val5">
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">载具号</label>
						<view class="filter_input_wraper">
							<search-box
							v-model="val6"
							/>
						</view>
					</view>
				</view>
				<view class="confirm-button-wrap confirm-button-wrap-c">
					<button class="confirm-button" @tap="toCancle">清空</button>
					<button class="confirm-button" :class="{'confirm-button_disabled': !val1 || !val2 || !val5 || !val6 }" :disabled="disabled" @tap="toSure">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {semiProductInFromPda} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				val2: '',
				val3: '',
				val4: '',
				val5: '',
				val6: '',
				val7: '',
				disabled: false
			};
		},
		onShow () {
			if (this.$store.getters.publicObj !== '') {
				this.val2 = this.$store.getters.publicObj.material_code
				this.val3 = this.$store.getters.publicObj.material_name
				this.val4 = this.$store.getters.publicObj.material_spec
				this.val7 = this.$store.getters.publicObj.material_id
			}
		},
		destroyed () {
			this.$store.dispatch('setPublicObj', '')
		},
		methods: {
			toCancle () {
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
				this.val4 = ''
				this.val5 = ''
				this.val6 = ''
				this.val7 = ''
				this.$store.dispatch('setPublicObj', '')
			},
			toSearch () {
				uni.navigateTo({
					url: '/pages/management/searchMater?page=p2'
				})
			},
			toSure () {
				this.disabled = true
				if (!this.val1) {
					uni.showToast({
						title: '订单号不能为空',
						icon: 'none'
					})
					this.disabled = false
					return
				}
				if (!this.val2) {
					uni.showToast({
						title: '物料不能为空',
						icon: 'none'
					})
					this.disabled = false
					return
				}
				if (!this.val5) {
					uni.showToast({
						title: '数量不能为空',
						icon: 'none'
					})
					this.disabled = false
					return
				}
				if (Number(this.val5) < 0) {
					uni.showToast({
						title: '数量不能小于零',
						icon: 'none'
					})
					this.disabled = false
					return
				}
				if (!this.val6) {
					uni.showToast({
						title: '载具号不能为空',
						icon: 'none'
					})
					this.disabled = false
					return
				}
				this._semiProductInFromPda()
			},
			async _semiProductInFromPda () {
			  try {
				let res = await semiProductInFromPda(this.val1, this.val7, this.val5, this.val6) 
				this.disabled = false
				this.toCancle()
				this.$store.dispatch('setPublicObj', '')
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled = false
			  }
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.filter-confirm-wrap
	_wh(calc(100% - 30px), calc(100% - 72px))
	background-color #fff
	border-radius 12px
	margin 15px auto
	_fj()
.filter-confirm-wrap-inner
	width 50%
	background-color #fff
	border-radius 12px
	padding-bottom 15px
	margin 0 auto
.filter-wrap
	width 100%
	padding 0 15px
	_fj(center,,column,)
.filter-item
	width 100%
.confirm-button-wrap-c
	justify-content center
	margin-top 50px
</style>