<template>  
    <view class="content"></view>  
</template>  
<script>  
var main,receiver,filter;    
var _codeQueryTag = false;    
export default {  
    data() {  
        return {  
            scanCode:''  
        }  
    },  
    created: function (option) {  
        this.initScan()  
        this.startScan();    
    },    
    onHide:function(){    
        this.stopScan();    
    },  
    destroyed:function(){    
        /*页面退出时一定要卸载监听,否则下次进来时会重复，造成扫一次出2个以上的结果*/    
        this.stopScan();    
    },    
    methods: {  
        initScan() {
            let that = this;
            main = plus.android.runtimeMainActivity(); //获取activity
            var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
              onReceive: that.pdaReceive
            });
            var IntentFilter = plus.android.importClass('android.content.IntentFilter');
            var filter = new IntentFilter();
            filter.addAction("nlscan.action.SCANNER_RESULT"); //监听扫描
            main.registerReceiver(receiver, filter); //注册监听
            console.log('!!!!!!!!!!!!!!!!!!!!!!!!PDA发起监听!!!!!!!!!!!!!!!!!!!!!!!!!')

        },   
		//接收pda扫码
		pdaReceive(context, intent) {
			//通过intent实例引入intent类，方便以后的'.'操作
			plus.android.importClass(intent)
			var productIdCode = intent.getStringExtra("SCAN_BARCODE1")
			this.queryCode(productIdCode)
		}, 
        startScan(){    
            main.registerReceiver(receiver,filter);  
        },    
        stopScan(){  
            main.unregisterReceiver(receiver);    
        },    
        queryCode: function(code){  
            //防重复  
            if(_codeQueryTag){
                return false
            }    
            _codeQueryTag = true;    
            setTimeout(function(){    
                _codeQueryTag = false;    
            },150)
            uni.$emit('scancodedate',{code:code})  
        }  
    }  
}
</script>  

<style>  
    page {  
        background-color: #efeff4;  
    }  
    .content {  
        text-align: center;  
    }  
</style>