<template>
	<view class="content">
		<nav-bar title="半成品出库"></nav-bar>
		<view class="search-confirm-wrap">
			<view class="search-wrap">
				<view class="search-item">
					<label class="search-label">仓库</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">单据类型</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">物料</label>
					<view class="filter_input_wraper">
						<input type="number" class="search-input-l" v-model="val1">
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">规格</label>
					<view class="filter_input_wraper">
						<input type="number" class="search-input-l" v-model="val2">
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">数量(个)</label>
					<view class="filter_input_wraper">
						<input type="number" class="search-input-l" v-model="val3">
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">单重(g)</label>
					<view class="filter_input_wraper">
						<input type="number" class="search-input-l" v-model="val4">
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">入库点</label>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index3" :localdata="options3" @change="selectChange3"></uni-data-select>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">载具号</label>
					<view class="filter_input_wraper">
						<search-box
						v-model="val5"
						/>
					</view>
				</view>
				<view class="search-item">
					<label class="search-label">备注</label>
					<view class="filter_input_wraper">
						<input type="text" class="search-input-l" v-model="val6">
					</view>
				</view>
			</view>
			<view class="confirm-button-wrap">
				<button class="confirm-button" @tap="toDelect">呼叫空载具</button>
				<button class="confirm-button" @tap="toSelect">作业查询</button>
				<button class="confirm-button" :class="{'confirm-button_disabled': !index1 || !val1}" :disabled="disabled" @tap="toSure">确认入库</button>
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {finishproductPoint, InstoreOrder} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				options1: [],
				index1: 'A1',
				options2: [],
				index2: 'A1',
				options3: [],
				index3: 'A1',
				val1: '',
				val2: '',
				val3: '',
				val4: '',
				val5: '',
				val6: '',
				disabled: false
			};
		},
		destroyed () {
			this.$store.dispatch('setPublicArr', '')
		},
		created () {
			// this._finishproductPoint()
		},
		methods: {
			/** 选择器1 */
			selectChange1(e) {
				this.index1 = e
			},
			/** 选择器2 */
			selectChange2(e) {
				this.index2 = e
			},
			/** 选择器3 */
			selectChange3(e) {
				this.index3 = e
			},
			toDelect () {
			  this.$store.dispatch('setPublicArr', '')
			},
			async _finishproductPoint () {
				let res = await finishproductPoint('1')
				this.options1 = [...res]
			},
			async toSure () {
			  this.disabled = true
			  if (!this.index1) {
				uni.showToast({
					title: '请选择入库点',
					icon: 'none'
				})
				this.disabled = false
				return
			  }
			  if (!this.val1) {
				uni.showToast({
					title: '请输入载具号',
					icon: 'none'
				})
				this.disabled = false
				return  
			  }
			  try {
				let res = await InstoreOrder(this.index1, this.val1) 
				this.disabled = false
				this.index1 = ''
				this.val1 = ''
				this.toDelect()
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled = false
			  }
			},
			toSelect () {
				uni.navigateTo({
					url: '/pages/management/MaterList'
				})
			}
		}
	}
</script>
