<template>
	<view class="">
		<u-popup v-model="showOne"  mode="bottom" border-radius="14" z-index='12'>
			<view class="title">
				<view class="title-txt">
						需求信息
				</view>
				<u-icon name="close" color="#4f4f4f" size="28"  @click="showOne = false"></u-icon>
			</view>
			<view class="item">
				<view class="label">来源库位：</view>
				<view class="value"><u-input v-model="fromLocationCode"  @confirm="fromLocationScanMsg" clearable></u-input></view>
				<view class="searchIcon">
					<image src="/static/search.svg" mode=""  @click="fromLocationClick"/>
				</view>
			</view>
			<view class="item">
				<view class="label">零件：</view>
				<view class="value"><u-input v-model="itemCode"  @confirm="itemCodeScanMsg" clearable></u-input></view>
				<view class="searchIcon">
					<image src="/static/search.svg" mode=""  @click="itemCodeClick"/>
				</view>
			</view>
			<view class="item">
				<view class="label">批次：</view>
				<view class="value">
					<u-input v-model='batch'></u-input>
				</view>
				<view class="searchIcon"></view>
			</view>
			<view class="item">
				<view class="label">数量：</view>
				<view class="value1">
					<u-number-box v-model="handleQty" @change="valChange"></u-number-box>
					<view class="uom">EA</view>
				</view>
			</view>
			<view class="uni-flex uni-row hide_border">
				<button class="btn_edit_big_cancle" hover-class="btn_edit_big_after" @click="showOne = false">取消</button>
				<button class="btn_edit_big_confirm" hover-class="btn_edit_big_after" @click="confirm()">确认</button>
			</view>
		</u-popup>
		
		<!-- <win-scan-location ref="scanLocationCode" title="来源库位" @getLocation='getFromLocation'
			:locationAreaTypeList="fromLocationAreaTypeList"></win-scan-location> -->
		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	import {
		getBusinessType
	} from '@/common/record.js';
	
	import {
		getLabelInfo
	} from '../../../common/label.js';
	

	export default {
		components: {
			winScanLocation
		},
		emits: ["showFromLocationPopup",'itemCodeClick','confirm','getInputMsgResult'],
		data() {
			return {
				handleQty:0,
				fromLocationCode:'',
				itemCode:'',
				batch:'',
				showOne:false
			}
		},
		props: {
			fromLocationCodeProps:{
				type: String,
				default: ''
			},
			// 是否显示第一层弹窗
			showOnePop: {
				type: Boolean,
				default: false
			},
			itemCodeProps:{
				type: String,
				default: ''
			},
			batchProps:{
				type: String,
				default: ''
			},
			isClearFromLocationCode:{
				type: Boolean,
				default: false
			},
			isClearItemCode:{
				type: Boolean,
				default: false
			},
		},
		mounted() {
		},
		methods: {
			// 打开扫描来源库位组件
			fromLocationClick(){
				// this.$refs.scanLocationCode.openScanPopup()
				this.$emit("showFromLocationPopup");
			},
			// 显示箱码
			itemCodeClick(){
				// this.$refs.scanLocationCode.openScanPopup()
				if(!this.fromLocationCode){
					this.$refs.comMessage.showMessage("请先扫描来源库位")
					return
				}
				this.$emit("itemCodeClick");
			},
			confirm(){
				// this.$refs.scanLocationCode.openScanPopup()
				
				let obj = {
					fromLocationCode:this.fromLocationCode,
					itemCode:this.itemCode,
					batch:this.batch,
					handleQty:this.handleQty,
				}
				this.$emit("confirm",obj);
			},
			fromLocationScanMsg(){
				console.log(111,this.fromLocationCode)
				this.scanMsg = this.fromLocationCode
				this.fromWitch = 'fromLocationScanMsg'
				this.handelScanMsg()
			},
			itemCodeScanMsg(){
				if(!this.fromLocationCode){
					this.$refs.comMessage.showMessage("请先扫描来源库位")
					return
				}
				this.fromWitch = 'itemCodeScanMsg'
				this.scanMsg = this.itemCode
				this.handelScanMsg()
			},
			handelScanMsg() {
				//点击了回车
				// uni.showLoading({
				// 	title: '解析中...',
				// 	mask: true
				// })
				let that = this;
				console.log(777,that.scanMsg)
				// if(index==-1){
				// 	that.scanMsg =that.scanMsg + "\n";
				// }
				console.log(that.scanMsg.includes('\n'))
				// if (that.scanMsg.includes('\n')) {
					// that.scanMsg = 'HPQ;V1.0;ICE115F11161AG;PP20230427000027;B20230427002;Q50';
					setTimeout(() => {
						that.losefocus();
						let content = uni.$u.trim(that.scanMsg)
						if (content == "") {
							// that.getfocus();
							this.$refs.comMessage.showErrorMessage("扫描内容为空,请重新扫描", res => {
								if (res) {
									that.scanMsg = ""
									that.getfocus();
								}
							})
							return;
						}
			
						if (that.isShowHistory) {
							that.scanList.unshift(content);
						}
					
						getLabelInfo(content, this.headerType, callback => {
							// uni.hideLoading();
							let scanResult = callback;
							scanResult.scanMessage = content
							if (scanResult.success) {
								// that.getfocus();//不能自动获取焦点
								console.log(scanResult)
								that.$emit("getInputMsgResult", scanResult,this.fromWitch);
							} else {
								that.losefocus();
								this.$refs.comMessage.showErrorMessage(scanResult.message, res => {
									if (res) {
										that.getfocus();
									}
								})
							}
						});
					}, 200);
				// }
			},
			losefocus() {
				let that = this;
				this.$nextTick(r => {
					that.boxfocus = false;
				});
			},
			onClear(){
				console.log(111)
			}
		},
		watch: {
			fromLocationCodeProps:{
				handler(newVal, oldVal) {
					if(this.isClearFromLocationCode){
						this.fromLocationCode=''
					}else{
					this.fromLocationCode  = newVal
					}
				},
				// deep: true,
				// immediate: true
			},
			itemCodeProps: {
				handler(newVal, oldVal) {
					if(this.isClearItemCode){
						this.itemCode=''
					}else{
						this.itemCode  = newVal
					}
				},
			},
			batchProps(newVal) {
				if(this.isClearItemCode){
					this.batch=''
				}else{
					this.batch  = newVal
				}
			},
		}
	}
</script>

<style lang="scss">
	.title{
		padding:30rpx 20rpx;
		display: flex;
		border-bottom:1px solid rgba(230, 230, 230, 1);
		.title-txt{
			flex:1;
			font-weight: bold;
			font-size: 32rpx;
		}
		
	}
	.select{
		display: flex;
	}
	.border{
		border:1px  solid rgba(230, 230, 230, 1)
	}
	::v-deep .u-input__right-icon__clear{
		display: flex;
		align-items: center;
		justify-content: center;
		color: #a7a7a7;
	}
	.item{
		display: flex;
		align-items: center;
		padding: 20rpx;
		border-bottom: 1px solid #dedede;
		.value{
			flex:1;
			width: 0px;
			height: 80rpx;
			border: 1px solid #dedede;
			display: flex;
			align-items: center;
			font-size: 32rpx;
			padding: 0px 20rpx;
		}
		.value1{
			flex:1;
			width: 0px;
			height: 80rpx;
			display: flex;
			align-items: center;
			font-size: 32rpx;
		}
		.searchIcon{
			width: 40rpx;
			margin-left: 20rpx;
			image{
				width: 40rpx;
				height:40rpx
			}
		}
		.uom{
			margin-left: 10rpx;
		}
		
	}
</style>