<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  	
  </head>
  <body>
			<div class="top"></div>
			<div class="center">
		  		<h3 id="movePopuWin">
		        	<a href="javascript:;" title="关闭" class="message_close" id="closePopuWin"></a>
		        	<span>电子锁设置[<span id="cmd_vhc_name"></span>]</span>
		        </h3>
		        <div class="popuWinMessage_main">
		        		<ul>
		        			<li style="text-align:center;">
		        				<span id="cmdMsg" style="color:red;">&nbsp;</span>
		        			</li>
		        		</ul>		     
			        	<table width="100%" border="0" style="line-height:35px;">			        		
								<tr>
									<td>电子锁ID</td>
									<td>
										<input type="text" name="cp.vhcID" style="width: 100px;"/>
									</td>
									<td rowspan="4">
										<fieldset style="border: 1px #CCC solid; width: 100px;padding-left: 10px;  margin-left: 30px;line-height: 25px;border-radius:5px;">
											<legend>操作类型</legend>
											<input type="radio" value="0" name="cp.operationType" checked="checked"/>检查锁状态<br/>
											<input type="radio" value="1" name="cp.operationType"/>施封<br/>
											<input type="radio" value="2" name="cp.operationType"/>解封<br/>
											<input type="radio" value="3" name="cp.operationType"/>解除报警<br/>
											<input type="radio" value="4" name="cp.operationType"/>读取数据<br/>
										</fieldset>
									</td>
								</tr>
								<tr>
									<td>操作密码</td>
									<td>
										<input type="text" name="cp.operationPwd" style="width: 100px;" value="1234567890"/>
									</td>
								</tr>
								<tr>
									<td>线路代码</td>
									<td>
										<input type="text" name="cp.addressCode" style="width: 100px;" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" 
											onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" 
											onfocus="this.value='';" value="1234"/>
									</td>
								</tr>
								<tr>
									<td>载货单号</td>
									<td>
										<input type="text" name="cp.ticketNum" style="width: 100px;" value="1234567890123"/>
									</td>
								</tr>
								<tr>
				        			<td style="width: 70px;text-align: center;" colspan="3">
				        			    <input id="cmd_submitBtn" type="button" value="提交" style="width:80px; height:30px;  margin-top: 15px;"/>					    		
				        			</td>
				        		</tr>			        	
			        	</table>		     
		        </div>
			</div>
			<div class="bot"></div>	
			<script>
			
				$(function(){
					
					
					$("#cmd_submitBtn").unbind().click(function(){					
						
						if(!formValidate()){
							return false;
						}
						
						submitForm();
					});
					
					function submitForm(){
						
						$("#cmdMsg").html("&nbsp;");
						$("#cmd_submitBtn").attr("disable","disable");
						$("#cmd_submitBtn").val("提交..");
								   
						$.ajax({
						        type: "POST",
						        dataType: "json",
						        url: "json/cmdAction_send.action",
						        data: getFormData(),
						        success: function(json) {
							         if (json.flag) {
								         
								         $("#closePopuWin").click();								         
								         $('#cmdsgpanel tr').eq(0).after("<tr class='alarmrow" + ( getCmdTableSize() % 2) + "'><td width='100px' style='text-align: left;padding-left:30px;'>"+curSendCmdEq.name+"</td><td width='200px' style='text-align: center;'>"+getNowFormatDate()+"</td><td tyle='text-align: left;'>发送了电子锁设置命令</td><td width='80px' style='text-align: center;'><a style='cursor:pointer;color:#069;' href='javascript:;' onclick='openCarOwnerInfo(" + curSendCmdEq.eqId + ");'>" + language.chezhuxiangqing + "</a></td></tr>");	          
							         
							         }else{
							         
								         $("#cmdMsg").html(json.msg);
		                        		 $("#cmd_submitBtn").attr("disable","");
										 $("#cmd_submitBtn").val("提交");   								               	
							         }
						        },
						        error: function() {	             
						            $("#cmdMsg").html("*提交失败请稍后重试");
									$("#cmd_submitBtn").attr("disable","");
									$("#cmd_submitBtn").val("提交");
						        }
						  });
					}
					
					function formValidate(){
					
						var operationPwd = $("input[name='cp.operationPwd']").val();
						if(operationPwd.length != 10){
							$("#cmdMsg").html("请输入10位有效操作密码");
							return false;
						}else{
							$("#cmdMsg").html("&nbsp;");							
						}
						
						var ticketNum = $("input[name='cp.ticketNum']").val();
						if(ticketNum.length != 13){
							$("#cmdMsg").html("请输入13位有效载货单号");
							return false;
						}else{
							$("#cmdMsg").html("&nbsp;");							
						}
						
						var addressCode = $("input[name='cp.addressCode']").val();
						if(addressCode.length != 4){
							$("#cmdMsg").html("请输入4位有效线路代码");
							return false;
						}else{
							$("#cmdMsg").html("&nbsp;");							
						}
						
						return true;
						
					}
					
					function getFormData(){
						
						var data = "vid=" + curSendCmdEq.gprsCode +
								   "&mtid=" + curSendCmdEq.mtid +
								   "&cmdid=" + curSendCmdEq.cmdid +
								   "&cp=" + $("input[name='cp.operationType']:checked").val() + 
								   "&cp=" + $("input[name='cp.vhcID']").val() + " " + $("input[name='cp.ticketNum']").val() +
								   "&cp=" + $("input[name='cp.operationPwd']").val() +
								   "&cp=" + $("input[name='cp.addressCode']").val() +
								   "&cp=";//最后一个cp表示密码
								   
						return data;
					}

					
					if(curSendCmdEq){
						$("#cmd_vhc_name").html(curSendCmdEq.name);
					}

				});
				
			</script>	
  </body>
</html>
