<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<!-- 入库组盘 -->
		<view class="zd_content">
			<view class="zd_wrapper">
				<search-box
				placeholder="请扫码"
				v-model="code"
				@handleChange="handleChange"
				/>
			</view>
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">载具编码</span>
					</view>
					<view class="zd-col-18 filter_select">
						<search-box
						v-model="vcode"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">物料编码</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.material_code" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">物料名称</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.material_name" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">物料规格</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.material_spec" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">批次</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.pcsn" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">数量</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.qty" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom filter_input_disabled">
					<view class="zd-col-6">
						<span class="filter_label">单位</span>
					</view>
					<view class="zd-col-18 filter_select">
						<input type="text" class="filter_input" v-model="initData.qty_unit_name" disabled>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="clearUp1">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !vcode || JSON.stringify(initData) === '{}'}" :disabled="disabled1" @tap="_groupPlate">组盘确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {sweepCode, groupPlate} from '@/utils/getData.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				code: '',
				vcode: '',
				initData: {},
				disabled1: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				if (e) {
					this._sweepCode(e)
				}
			},
			async _sweepCode (e) {
				try {
					let res = await sweepCode(e)
					if (res && res.data) {
						this.initData = res.data
						this.vcode = res.data.storagevehicle_code
					} else {
						this.initData = {}
					}
				} catch (e) {
					this.initData = {}
				}
			},
			clearUp1 () {
				this.code = ''
				this.vcode = ''
				this.initData = {}
				this.disabled1 = false
			},
			// 组盘确认
			async _groupPlate () {
				this.disabled1 = true
				if (!this.vcode || JSON.stringify(this.initData) === '{}') {
					this.disabled1 = false
					return
				}
				try {
					const obj = Object.assign({}, this.initData, {storagevehicle_code: this.vcode})
					let res = await groupPlate(obj)
					this.disabled1 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.code = ''
					this.initData = {}
				} catch (e) {
					this.disabled1 = false
				}
			}
		}
	}
</script>