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

	//提交出库单号
    $('#orderNoOrTrackingNo').keyup(function (event) {
        if (event.keyCode != "13") {return false;}
        $("#orderNoOrTrackingNo").val(trimStr($("#orderNoOrTrackingNo").val()));
        //播放扫描声音
    	playSound('../raw/scan.wav');
    	
        submitShipped();
    });
	  
});
 
var isSubmintIng = false;//是否正在提交
function submitShipped(){
	if(isSubmintIng){return;}
	isSubmintIng = true;
	
	var orderNoOrTrackingNo = $('#orderNoOrTrackingNo').val();
	if(orderNoOrTrackingNo == ''){
		mui.alert("出库单号不能为空", '警告'); 
		
		isSubmintIng = false;
		return;
	}
		
	var formData={};
	formData.orderNoOrTrackingNo=orderNoOrTrackingNo;
		
	var appRequest = $appRequest;//复制请求封装对象
   	appRequest.opType = OP_TYPE_MENU.SINGLE_SHIPPED;
   	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('locationCode');  }); 
    			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;
	
	$("#outOrderId").val("");
	$("#orderNoOrTrackingNo").val("");
		
	$('#orderNoOrTrackingNo').focus();
}
 