<template>
	<view class="content"></view>
</template>

<script>
	var main1, receiver1, filter1;
	var _codeQueryTag1 = false;
	export default {
		data() {
			return {
				scanCode: ''
			}
		},
		created(option) {
			this.initScan1()
			this.startScan1()
		},
		onHide() {
			this.stopScan1()
		},
		destroyed() {
			this.stopScan1()
		},
		methods: {
			// 新pad
			initScan1() {
				let _this = this;
				//获取Android主Activity
				main1 = plus.android.runtimeMainActivity();
				//获取Android意图过滤类
				var IntentFilter = plus.android.importClass('android.content.IntentFilter');
				//实例化意图过滤
				filter1 = new IntentFilter();
				//获取扫码成功的意图广播--下面的addAction内改为自己的广播动作
				// 之前pda广播动作:com.speedata.showdecodedata=
				filter1.addAction("com.honeywell.scan.broadcast");
				receiver1 = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
					onReceive: function(context, intent) {
						plus.android.importClass(intent);
						//下面的getStringExtra内改为自己的广播标签
						// 之前pda广播标签:message
						let code = intent.getStringExtra("data");
						_this.queryCode1(code);
					}
				});
			},
			startScan1() {
				main1.registerReceiver(receiver1, filter1);
			},
			stopScan1() {
				main1.unregisterReceiver(receiver1);
			},
			queryCode1: function(code) {
				if (_codeQueryTag1) return false;
				_codeQueryTag1 = true;
				setTimeout(function() {
					_codeQueryTag1 = false;
				}, 150);
				var id = code
				console.log('id:', id)
				uni.$emit('scan1', {
					code: id
				})
			}
		}
	}
</script>
