<template>
	<view>
		<uni-popup ref="popup" :mask-click="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>
		</uni-popup>
		<comMessage ref="comMessage" @afterClose="getfocus"></comMessage>
	</view>
</template>

<script>
	import {
		getLabelInfo
	} from '@/common/label.js';
	import winComScan from '@/mycomponents/scan/winComScan.vue'

	export default {
		components: {
			winComScan,
		},
		props: {
			title: {
				type: String,
				default: '箱标签'
			},
			isShowHistory: {
				type: Boolean,
				default: true
			},
			headerType: {
				type: String,
				default: 'HPQ'
			}
		},
		data() {
			return {
				show: false,
				priorityList: [{
						value: 0,
						text: "低"
					},
					{
						value: 1,
						text: "中"
					},
					{
						value: 2,
						text: "高"
					},
				],
				priorityCode: 1
			}
		},
		created() {

		},
		methods: {
			simulateScan(scanMessage) {
				getLabelInfo(scanMessage, this.headerType, callback => {
					if (callback.success) {
						this.getScanResult(callback);
					} else {
						this.showMessage(callback.message)
					}

				})
			},
			openScanPopup() {
				setTimeout(res => {
					this.$refs.popup.open('bottom')
				}, 200)
			},

			closeScanPopup() {
				this.losefocus()
				this.$refs.popup.close();
				this.$emit("close", '');
			},

			scanClick() {
				if (this.$refs.comscan) {
					this.$refs.comscan.clickScanMsg();
				}

			},

			cancelClick() {
				if (this.$refs.comscan) {
					this.$refs.comscan.clearScanValue();
				}
			},

			getScanResult(result) {
				if (result.success) {
					result.priorityCode =this.priorityCode
					this.$emit("getResult", result);
				} else {
					this.showMessage(result.message)
				}
			},

			getfocus() {
				if (this.$refs.comscan != undefined) {
					this.$refs.comscan.getfocus();
				}
			},

			losefocus() {
				if (this.$refs.comscan != undefined) {
					this.$refs.comscan.losefocus();
				}
			},
			showMessage(message) {
				this.$refs.comMessage.showMessage(message);
			},
			change(e) {
				console.log(e);
			},

		}
	}
</script>

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