<template>
	<view>
		<u-navbar back-text="返回" title="立库空托盘入库" :background="background"></u-navbar>
		<u-form ref="testForm">
			<u-form-item :border-bottom="false">
				<p>扫描托盘标签:</p>
				<u-input :focus="focusShipRequest" :border="true" v-model="PalletLabel" placeholder="请扫描栈板标签" />
				<!-- @blur="pointblur"-->
			</u-form-item>
			<u-form-item :border-bottom="false">
				<p>请输入托盘量:</p>
				<u-input :border="true" v-model="PalletQuantity" placeholder="输入托盘数量" :focus="focusBarCode" />
			</u-form-item>
		</u-form>
		<u-button @click="searchMaterialStockIn" type="primary">确定</u-button>
	</view>
</template>

<script>
	import { removeZeros } from "@/utils/utils"
	export default {
		data() {
			return {
				focusBarCode:'',
				focusShipRequest: false,
				PalletLabel: "", //托盘标签
				PalletQuantity: '', //托盘数量				
				items: ['入库清单'], //分栏器的选项卡 应发，实发，待发，物料描述，行号
				tabH: 800, //表格的宽度
				ischecked: true, //默认出库
				background: {
					backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
				}, //返回按钮的样式
				//style:{color: '#2979FF'},
				colors: ['#007aff', '#4cd964', '#dd524d'],
				styleType: 'button',
				current: 0,
				matData: [], //后端传回来的绑定表格的数据
				colorIndex: 0,
				activeColor: '#007aff',
				styleType: 'text',
				loading: false,
				//-----------------上方是template标签中的分栏器等需要的样式，下方是双向绑定需要使用到的数据
			}
		},
		onUnload() {   
		   uni.$off('rifdscan')
		},
		onShow() {
			let that = this
			// uni.$off('rifdscan')
			uni.$on('rifdscan', (res)=> {
				console.log('扫码结果：', res);
				that.PalletLabel = res.rifd
			})
		},
		mounted() {
			this.tabH = this.$GetRemainingHeight(4, 0); //定义表格的高度
			let that = this
			uni.getStorage({
				key: "sitename",
				success(res) {
					that.siteName = res.data
				}
			})
			uni.getStorage({
				key: "userid",
				success(res) {
					that.userId = res.data
				}
			})
		},
		//焦点初始化，让页面所有的焦点同时只能存在一个
		initfocus() {
			this.focusBarCode = false
			this.focusShipRequest = false
		},
		//获取焦点的公共方法
		getfocus(nextfocus) {
			this.initfocus()
			this[nextfocus]
			this.$nextTick(() => { //vue是数据全部修改后才进行的视图更新，哪nextTick函数就是为了拿到最新的数据，还不懂的可以去百度
				this[nextfocus] = true
			})
		},
		methods: {
			searchMaterialStockIn() {
				if (this.PalletLabel == '' || this.PalletQuantity == '') {
					this.$showMessage("请按照规范操作");
				} else {
					this.$MyRequest('/bpel/event', {
						header: {
							MESSAGENAME: 'TransportCommandRequest',
							LANGUAGE: 'Chinese',
							Flag: 'TP' //托盘标志
						},
						body: {
							TRAYNAME: this.PalletLabel,
							Quantity: this.PalletQuantity,
							SITENAME: 'SDK',
							TRANSPORTCOMMANDTYPE: 'IN',
							FLAG: 'TP', //托盘标志
							pallet: ''
						}

					}, 'POST', true).then(res => {
						if (res.data.code == '0') {
							this.$showMessage("搬送下发成功");
						} else {
							this.$showMessage(res.data.msg);
						}
					}).catch(err => {
						this.$showMessage(err)
					})
				}

			},
		}

	}
</script>

<style lang="scss">
	switch {
		color: #FFCC33;
	}
</style>
