var focusId;
$(function(){
	
	$("input").focus(function(){
		//记住焦点位置
		focusId = this.id;
		//this.scrollIntoView(true);//回到顶部
		//window.setTimeout("myScrollIntoView()",100);  
	});	
	
	setTimeout(function() {
		$('#orderNo1').focus();
	}, 1000);
	
	//当失去焦点按回车时,焦点回到之前焦点位置
	$(window).keydown(function(event){
	 	if((event.keyCode==13)) {
	 		$(".messager-body").window('close');
	 		if(document.activeElement.id == null || document.activeElement.id ==''){
	 			//回到上次焦点地方
		 		//$("#"+focusId).focus();
	 		}
	 	}  
	});	

	//提交出库单号
    $('#orderNo1').keyup(function (event) {
        if (event.keyCode != "13") {return false;}
        $("#orderNo1").val(trimStr($("#orderNo1").val()));
        //播放扫描声音
    	playSound('../raw/scan.wav');
		
		$("#orderNo2").focus();
		
    });
    
    $('#orderNo2').keyup(function (event) {
        if (event.keyCode != "13") {return false;}
        $("#orderNo2").val(trimStr($("#orderNo2").val()));
        //播放扫描声音
    	playSound('../raw/scan.wav');
		
		submitLabelValidate();
    });
	 
});
 
var isSubmintIng = false;//是否正在提交
function submitLabelValidate(){
	if(isSubmintIng){return;}
	isSubmintIng = true;
	
	
	var orderNo1 = $('#orderNo1').val();
	var orderNo2=$('#orderNo2').val();
 
	if(orderNo1 == '' || orderNo2 == ''){
		mui.alert("出库单号,跟踪单号为必填项", '警告'); 
		
		isSubmintIng = false;
		return;
	}
		
	var formData={};
	formData.orderNo1=orderNo1;
	formData.orderNo2=orderNo2;
		
	var appRequest = $appRequest;//复制请求封装对象
   	appRequest.opType = OP_TYPE_MENU.VALIDATE_LABEL;
   	appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
		
	var nwaiting = plus.nativeUI.showWaiting('正在提交中...');
	$.ajax({
        type: 'POST',
        url: $appRequestUrl,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(appRequest),
        success: function (appResponse) {
        	isSubmintIng = false;
        	nwaiting.close(); 
        	
        	if(!appResponse.success){
        		playSound('../raw/error.wav');
        		mui.alert(appResponse.msg, '警告', function() {  setFocus('orderNo1');  }); 
    			return;
    		}
        	
        	mui.toast(appResponse.msg);
        	
        	//播放成功声音
        	playSound('../raw/ok.wav');
        	
        	cleanAll();
        },
        error: function () {
        	isSubmintIng = false;
        	nwaiting.close(); 
        	
        	playSound('../raw/error.wav');
        	mui.toast('网络断开或服务器发生异常'); 
        }
	});
}


//下一个订单
function cleanAll(){
	isSubmintIng = false;
	$("#orderNo1").val("");
	$("#orderNo2").val("");
	$('#orderNo1').focus();
}
 
function nextOrder(){
	$("#orderNo1").val("");
	$("#orderNo2").val("");
	$('#orderNo1').focus();
}

