<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="cn.exlive.mygpsonline.util.Md5"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	String path = request.getContextPath();
	String simCode = request.getParameter("simCode");
	Md5 md = new Md5();
	String key = md.md5String("1"+"ex2sms"+simCode.trim());
%>
<html>
	<head>
		<title>发送短信</title>
	</head>
	<body>
		<div class="top"></div>
		<div class="center" style="width:900px;">
			<h3 id="movePopuWin">
				<a href="javascript:;" title="关闭" class="message_close"
					id="closePopuWin"></a>
				<span>SIM信息</span>
			</h3>
			<div class="popuWinMessage_main">
				<!--常用命令弹层-->
				<div class="mlTc" id="always_cmd_div" style="display:none;">
					<a href="javascript:;" onclick="closeAlCmd();" class="btclose"> <img style="border: none"
							src="gpsonline/image/mlclose.png" /> </a>
					<div class="mltab">
						<table cellpadding="0" cellspacing="0" width="100%"
							style="table-layout: fixed">
							<thead>
								<tr>
									<td width="40%">
										命令名称
									</td>
									<td width="60%">
										命令内容
									</td>
								</tr>
							</thead>
							<tbody id="tby_cmd_id"></tbody>
						</table>
					</div>
				</div>
				<!--常用命令弹层 end-->

				<!--状态-->
				<div class="sim_zongjie">
					<span>运营商：</span><strong id="simsearch_operator">加载中...</strong><i>|</i>
					<span>SIM卡状态：</span><strong id="simsearch_state">加载中...</strong><i>|</i>
					<span>套餐名称：</span><strong id="simsearch_package">加载中...</strong><i>|</i>
					<span>套餐大小：</span><strong id="simsearch_size">加载中...</strong><i>|</i>
					<span>已用流量：</span><strong id="simsearch_used">加载中...</strong>

					<!--常用命令按钮-->
					<a id="alcmd_a" style="display:none;" href="javascript:;"  onclick="openAlCmd();" class="mlBt"><i>|</i><span class="sim_ico"></span> <span>常用命令</span>
					</a>
					<!--常用命令按钮 end-->
				</div>
				<!--状态 end-->
				<div id="simchit">
				<!--查询-->
				<div class="sim_search">
					<div class="row">
						<span>SIM卡号：</span>
						<span> <input type="text" id="simsearch_mobile"
								name="mobile" maxlength="13"
								readonly="readonly" id="sms_mobile" class="txtbox"
								style="width: 100px;" placeholder="输入SIM卡13位" /> </span>
					</div>
					<div class="row">
						<span>短信内容：</span>
						<span class="rowr"> <input type="text" name="content" id="simsearch_input"
								maxlength="200" value="" id="sms_content" class="txtbox"
								style="width: 310px;" placeholder="短信内容" /> </span>
						<div class="sim_fasong_error">
							<label></label>
							<span id="sms_msg" style=""> </span>
						</div>
					</div>
					<div class="row" style="float: right; margin-right: 5px;">
						<input type="button" class="weizhangbtn" id="simsearch_cmd_send" onclick="cmd_send()" value="发送" />
						<input id="simsearch_btn_query" type="button" class="weizhangbtn" onclick="loadSimData();" value="刷新" />
					</div>
				</div>
				<!--查询 end-->
			
				<!--查询结果-->
				<div class="sim_jieguo_all">
					<table class="dlist" cellspacing="0" cellpadding="0" border="0" width="100%">
						<thead>
							<tr>
								<th width="6%">
									序号
								</th>
								<th width="140">
									时间
								</th>
								<th width="100">
									SIM卡
								</th>
								<th width="50">
									类型
								</th>
								<th width="50">
									状态
								</th>
								<th>
									内容
								</th>
							</tr>
						</thead>
						<tbody id="tab_body"></tbody>
					</table>
				</div>
				<!--查询结果 end-->
				</div>
			</div>
		</div>
		<div class="bot"></div>
	</body>
	<script type="text/javascript">
		var sim = "";
		var key = "";
		var isLoad = false;
		function loadalcmd(){
			if(!window.parent.eqVisualPower.simchit)return;
			$.getJSON("http://www.exlive.cn/synthReports/mobile_to_synth/publicAction_attr.action?p=1&wd="+sim+"&m="+Math.random()+"&gcback=?", function (e) {
				if(e.flag){
					var json ="{'tables':['e_common_command'],'serverid':"+e.data[0]+"}";
					$.ajax({
						type : "get",
						url : "http://sim.exlive.cn:8089/etm/public/dict.action",
						data:{json:json},
						dataType : "jsonp",
						success : function(json){
							if(json.flag){
								if(json.data.e_common_command.length>0){$("#alcmd_a").show();}
								var html_ ="";
								cmdlist = json.data.e_common_command;
		     					for(var i =0;i<json.data.e_common_command.length;i++){
		     						html_+="<tr onclick=\"selectTr("+i+")\" ><td><span>"+json.data.e_common_command[i].name+"</span></td><td>"+html_encode(json.data.e_common_command[i].content)+"</td></tr>";
		             			}
		     					$("#tby_cmd_id").html(html_);
							}
						}
					});
				}
			});
		}
		//打开常用命令
		function openAlCmd(){
			$("#always_cmd_div").show();
		}
		var cmdlist = [];
		function selectTr(index){

		     if(cmdlist.length<index){
		     }else{
		    	 $("#simsearch_input").val(cmdlist[index].content);
		    	 closeAlCmd(); 
		     }
		}
		function closeAlCmd(){
			$("#always_cmd_div").hide();
		}
		function cmd_send(){
			var content = $("#simsearch_input").val();
			if(content == ''){
        		$("#sms_msg").html("请输入短信内容");
        		return;
            }
			$("#simsearch_cmd_send").val('发送中...').attr("disabled", "disabled");
			/*$.ajax( {
				type : "get",
				url : "http://sim.exlive.cn:8089/etm/app/sms/send.action",
				data:{key:key,serverid:1,content:content,mobile:sim},
				dataType : "jsonp",
				success : function(json){
					if(json.flag){
						$("#simsearch_input").val("");
						$("#simsearch_cmd_send").val('发送').removeAttr("disabled");
						loadSimData();
					}else{
						//alert(json.code);
					}
				}
			});*/
			$.ajax({
				type : "post",
				url : "http://sim.exlive.cn/sim/card/api/sendmsg.do",
				data:{key:key,serverid:1,context:content,mobiles:sim},
				dataType : "json",
				success : function(json){
					if(json.flag){
						$("#simsearch_input").val("");
						$("#simsearch_cmd_send").val('发送').removeAttr("disabled");
						loadSimData();
					}else{
						//alert(json.code);
					}
				}
			});
		}
		function loadSimData(){
			/*if(!window.parent.eqVisualPower.simchit){
				$("#simchit").hide();
				return;
			}*/
			$("#simsearch_btn_query").attr('disabled',false);
			$("#simsearch_btn_query").val("查询中...");
			$("#tab_body").empty();
			$.ajax({
				type : "get",
				//url : "http://sim.exlive.cn:8089/etm/app/sms/list.action?key=c3ed145eb1068e8f0171b4f0b3dc03c0&mobile="+ sim + "&m=" + Math.random(),
				url : "http://sim.exlive.cn/sim/card/api/querySms.do?mobile="+ sim + "&page=1&size=10",
				dataType : "json",
				success : function(json){
				//console.info(JSON.stringify(json.list));
				$("#simsearch_btn_query").val("刷新").removeAttr("disabled");
					if(json && json.list.length > 0){
						var list = json.list;
						var html = "";
						if(list != null && list.length > 0){
							for ( var i = 0; i < list.length; i++) {
								html += '<tr><td>'+(parseInt(i)+1)+'</td>'+
		                                '<td >' + list[i].createtime + '</td>' +
		                                '<td>' + list[i].mobile + '</td>' +
		                                '<td >' + getPTType(list[i].type) + '</td>' +
		                                '<td >' + getType(list[i].type) + '</td>' +
		                                '<td class="td_l">' + html_encode(list[i].message) + '</td>' +
		                                '</tr>';
							}
						}else{
							html += '<tr><td colspan=7 height="40">查询不到该短信记录</td></tr>';
						}
						$("#tab_body").append(html);
					}	
				}
			});
		}
		//加载sim状态
		function loadSimState(){
			//console.info(sim);
			$.ajax( {
				async: false,
				type : "get",
				//url : "http://sim.exlive.cn:8089/etm/app/sim/ifm.action?mobile="+ sim + "&m=" + Math.random(),
				url:"http://sim.exlive.cn/sim/card/api/weixin/queryCard.do?mobile="+ sim + "&m=" + Math.random(),
				dataType : "json",
				success : function(json){
					//console.info(JSON.stringify(json));
					if (json.flag) {
						if(!json.flag && json.result==null){
							$("#simsearch_operator").html("--");
							$("#simsearch_state").html("--");
							$("#simsearch_package").html("--");
							$("#simsearch_size").html("--");
							$("#simsearch_used").html("--");
							alert(sim+" 非平台支持查询的SIM卡,推荐使用超越物联网流量卡");
							return;
						}
						$("#simsearch_operator").html(json.result.operator);
						/*var gprs_status = json.data.gprsStatus;
						var power_status = json.data.powerStatus;
						var gprs_status_str = "";
						if(gprs_status - 0 == 0){
							gprs_status_str = "开机";
						}
						if (gprs_status - 1 == 0) {
							gprs_status_str = "关机";
						}
						if (gprs_status - 2 == 0) {
							gprs_status_str = "信号不稳定";
						}
						var power_status_str = ""
						if (power_status - 0 == 0) {
							power_status_str = "在线";
						}
						if (power_status - 1 == 0) {
							power_status_str = "离线";
						}
						if (power_status - 2 == 0) {
							power_status_str = "信号不稳定";
						}*/
						$("#simsearch_state").html(json.result.gprsStatusName + "&nbsp;" + json.result.workStatusName);
						$("#simsearch_package").html(json.result.packageName);
						$("#simsearch_size").html((json.result.defaultGprsCount/1024)+"M");
						$("#simsearch_used").html(decimal(json.result.gprs/1024,2)+"M");
					}else{
						$("#simsearch_operator").html("--");
						$("#simsearch_state").html("非本平台卡");
						$("#simsearch_package").html("--");
						$("#simsearch_size").html("--");
						$("#simsearch_used").html("--");
						$("#simsearch_cmd_send").val('发送').attr("disabled", "disabled");
					}
				}
			});
		}
		//保留小数
		function decimal(num,v){
			var vv = Math.pow(10,v);
			return Math.round(num*vv)/vv;
		}
		function getType(type){

			 if(!type) return '已发送';
			 if(type=='inbox') return '已接收';
			 if(type=='report') return '已送达';
			 if(type=='send') return '已发送';
			 return '已发送';
		 }
				
		function getPTType(type){
			 if(!type) return '下行';
			 if(type=='inbox') return '上行';
			 if(type=='report') return '下行';
			 if(type=='send') return '下行';
			 return '下行';
		 }
		function html_encode(str)
		 {
		   var s = "";  
		   if (str.length == 0) return "";  
		   s = str.replace(/&/g, "&gt;");  
		   s = s.replace(/</g, "&lt;");  
		   s = s.replace(/>/g, "&gt;");  
		   s = s.replace(/ /g, "&nbsp;");  
		   s = s.replace(/\'/g, "&#39;");  
		   s = s.replace(/\"/g, "&quot;");  
		   s = s.replace(/\n/g, "<br>");  
		   return s;  
		 }
		//页面初始化
		$(function(){
			sim = '<%=simCode%>';
			key = '<%=key %>';
			$("#simsearch_mobile").val(sim);
			loadSimState();//加载sim状态
			loadSimData();//加载sim短信数据
			loadalcmd();//加载常用命令
		});
</script>
	<style type="text/css">
.row {
	float: left;
	line-height: 29px;
	margin-right: 20px;
}

.row span {
	float: left;
}

.row span input {
	height: 29px;
	line-height: 29px;
	border: 1px solid #ccc;
	padding-left:5px;
}

.weizhangbtn {
	background: #364860;
	width: 75px;
	line-height: 29px;
	height: 29px;
	font-size: 12px;
	border: none;
	color: #fff;
	margin-right: 10px;
}

.block {
	padding: 0px 15px;
}

#query_form {
	padding-top: 10px;
}

.sim_search {
	overflow: hidden;
	font-size: 12px;
	margin: 10px 5px 10px 15px;
}

.sim_zongjie {
	overflow: hidden;
	font-size: 12px;
	padding: 0px 15px;
	margin-top: 15px;
	line-height: 25px;
}

.sim_zongjie span,.sim_zongjie strong,.sim_zongjie i {
	float: left;
}

.sim_zongjie strong {
	font-weight: normal;
	color: #28c3b9
}

.sim_zongjie i {
	font-style: normal;
	padding: 0px 10px;
}
.row label {
	width: auto;
}
.sim_fasong_error {
	position: absolute;
	margin-top: -3px;
	margin-left: 372px;
	color: #c63939;
	width:100px;
}
.mlBt {
	display: block;
	float: left;
	color: #28c3b9;
	cursor: pointer
}
a.mlBt:hover {
	text-decoration: underline;
}
.mlBt span {
	float: left;
}
.mlBt .sim_ico {
	background: url(gpsonline/image/icoml.png) no-repeat;
	width: 13px;
	height: 13px;
	display: block;
	margin-top: 5px;
	margin-right: 7px;
}

.mlTc {
	position: absolute;
	z-index: 10;
	width: 674px;
	height: 359px;
	background: #fff;
	left: 50%;
	top: 50%;
	margin-left: -220px;
	margin-top: -179px;
	border: 1px #c1c1c1 solid;
	box-shadow: 0px 0px 5px #c1c1c1;
	font-size: 12px
}

.btclose {
	display: block;
	width: 21px;
	height: 21px;
	position: absolute;
	right: -8px;
	top: -8px;
}

.mltab {
	position: absolute;
	left: 15px;
	right: 10px;
	top: 20px;
	bottom: 20px;
	overflow: auto;
	font-size: 12px
}

.mltab table {
	font-size: 12px;
}

.mltab table td {
	border-bottom: 1px #e0e0e0 solid;
	word-break: break-all;
	padding: 6px 10px;
}

.mltab table thead {
	background: #f5f5f5;
}

.mltab table thead td {
	border-top: 1px #e0e0e0 solid;
}

.mltab table tbody td {
	text-align: left;
	padding-left: 15px;
	cursor: pointer
}

.mltab table tbody tr:hover {
	background: #dceeff
}

.dlist th,.dlist td {
	font-size: 12px;
	padding: 7px 0;
	border-bottom: solid 1px #e5e5e5;
}

.dlist td {
	cursor: default;
	text-align: center;
}

.dlist th {
	font-weight: normal;
	background-color: #f5f5f5;
	border-top: solid 1px;
	border-color: #e0e0e0;
	text-align: center;
}

.dlist .td_l {
	text-align: left;
	padding-left: 5px;
}

.dlist .td_l {
	word-break: break-all;
	word-wrap: break-word;
}

.sim_jieguo_all {
	display: block;
	height: 290px;
	margin: 15px;
	overflow:auto;
}
strong#simsearch_state{
color:#F00}
</style>
</html>
