<template>
	<view>
		<u-popup v-model="show" mode="bottom" :mask-close-able="false">
			<view class="popup_box">
				<view class="pop_title uni-flex space-between">
					<view class="" style="font-size: 35rpx"> 扫描{{ title }} </view>

					<view class="">
						<image class="fr icons_scan_close" src="/static/icons/icons_scan_close.svg" @click="closeScanPopup()">
						</image>
					</view>
				</view>
				<view class="uni-flex uni-row"
					style="align-items: center; background-color: #fff; margin-left: 20rpx; margin-right: 20rpx; border-radius: 8rpx">
					<view class="uni-center" style="width: 25%; font-size: 32rpx; font-weight: bold"> 优先级 </view>
					<view style="width: 100%">
						<uni-data-select style="padding: 20rpx;"  v-model="priorityCode"  :localdata="priorityList" @change="change"
														:clear="false"></uni-data-select>
						</view>
				</view>
				<view class="">
					<view class="">
						<win-com-scan ref="comscan" :placeholder="title" @getResult="getScanResult" :headerType="headerType"
							:isShowHistory="isShowHistory" :clearResult="true"></win-com-scan>
					</view>
				</view>
			</view>
			</-popup>
			<com-message ref="comMessageRef" />
	</view>
</template>

<script setup lang="ts">
	import { ref, getCurrentInstance, nextTick } from 'vue'
	import { onLoad, onNavigationBarButtonTap, onPullDownRefresh } from '@dcloudio/uni-app'
	import { getLabelInfo } from '@/common/label.js'
	import winComScan from '@/mycomponents/scan/winComScan.vue'

	const props = defineProps({
		title: {
			type: String,
			default: '箱标签'
		},
		isShowHistory: {
			type: Boolean,
			default: true
		},
		headerType: {
			type: String,
			default: 'HPQ'
		}
	})
	const show = ref(false)
	const priorityList = ref([
		{
			value: 0,
			text: '低'
		},
		{
			value: 1,
			text: '中'
		},
		{
			value: 2,
			text: '高'
		}
	])
	const priorityCode = ref(1)
	const comscan = ref()
	const simulateScan = (scanMessage) => {
		getLabelInfo(scanMessage, headerType.value, (callback) => {
			if (callback.success) {
				getScanResult(callback)
			} else {
				showMessage(callback.message)
			}
		})
	}
	const openScanPopup = () => {
		setTimeout((res) => {
			show.value = true
		}, 200)
	}
	const closeScanPopup = () => {
		show.value = false
		emit('close', '')
	}


	const scanClick = () => {
		if (comscan.value) {
			comscan.value.clickScanMsg()
		}
	}


	const cancelClick = () => {
		if (comscan.value) {
			comscan.value.clearScanValue()
		}
	}


	const getScanResult = (result) => {
		if (result.success) {
			result.priorityCode = priorityCode.value
			emit('getResult', result)
		} else {
			showMessage(result.message)
		}
	}


	const getfocus = () => {
		if (comscan.value != undefined) {
			comscan.value.getfocus()
		}
	}


	const losefocus = () => {
		if (comscan.value != undefined) {
			comscan.value.losefocus()
		}
	}
	const showMessage = (message) => {
		comMessageRef.value.showMessage(message)
	}
	const change = (e) => {
		console.log(e)
	}
</script>

<style lang="scss">
	.scroll-view {
		overflow-y: scroll;
		height: auto;
		max-height: 300rpx;
	}
</style>