<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
		 <%@include file="../../../frame/assets/header-all.jsp"%>
		
		 <style type="text/css">
		html, body{    height: 508px !important;
    overflow: hidden;}
		 li{margin: 0 30px;font-size: 13px;}
		 table{border:1px solid #e6e6e6;width:100%;}
		 tr{height:30px;}
		 tr,td{border:1px solid #e6e6e6;text-align:center;}
		 tr td:nth-child(odd){background-color:#eeeeee;text-align:center;width:16%;color:black;}
		 tr td:nth-child(even){color:black;}
		 .textbox {margin:0 !important;}
		 span.textbox:hover, span.combo:hover{border:0 !important;text-align: center;}
		  span.textbox{border:0 !important;}
		  .textbox-text{text-align:center !important;}
		  *{box-shadow:0px 0px 0px rgba(0, 0, 0, 0.075) !important;}
		  
			
			#pic{
				width: auto;
			    height: auto;
			    position: absolute;
			    top: 10%;
			    left: 20%;
			    z-index: 1;
			}
		 </style>
	</head>
	<body>
	
	<div style="padding:0px 15px;">
		<div style="line-height:24px;height:24px;border-bottom:1px solid  #e6e6e6;">
			<ul style="display:flex;justify-content:space-between;">
				<li style="margin-left:0 !important;">工单编号：<span style="color:#008000;" id="jobnum"></span></li>
				<!-- <li>故障类型：<span style="color:#a0d6a1;" id="faulttype"></span></li> -->
				<li>告警等级：<span style="color:#008000;" id="faultgradeMc"></span></li>
				<li>处理状态：<span style="color:#008000;" id="jobprocessstateMc">工单上报</span></li>
			</ul>
		</div>
		
		<div id="pic" style="display:none;">
			<img alt="" src="" style="width: 600px">
		</div>
		
		
		<div style="padding-top:0px;">
		   <form id="order" method="post">
		    	<table cellpadding="0"  cellspacing="0">
		    		<tr>
		    			<td colspan="6" style="background-color:#dcdcdc;">故障信息描述</td>
		    		</tr>
		    		
		    		<tr>
		    			<td>故障设备类型</td>
		    			<td><span id="faultdevicetypeMc"></span></td>
		    			<td>故障设备名称</td>
		    			<td><span id="faultdevicename"></span></td>
		    			<td>故障设备编号</td>
		    			<td><span id="faultdeviceid"></span></td>
		    		</tr>
		    		<tr>
		    			<td>故障发生时间</td>
		    			<td><span id="faultoccurtime"></span></td>
		    			<td>故障类型</td>
		    			<td>
		    				<span id="faulttypeMc"></span>
		    			</td>
		    			<td>工单上报单位</td>
		    			<td>
		    				<span id="jobreportcompanyMc"></span>
		    				<input id="jobreportcompany" type="text" style="display:none" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>工单上报人</td>
		    			<td><span id="jobreportpeople"></span></td>
		    			<td>上报人电话</td>
		    			<td><span id="jobreportphone"></span></td>
		    			<td>上报时间</td>
		    			<td><span id="jobreporttime"></span></td>
		    		</tr>
		    		<tr>
		    			<td >故障描述</td>
		    			<td colspan="5">
		    				<span id="faultdescription"></span>
						</td>		    		
		    		</tr>
		    		<tr>
		    			<td >故障图片</td>
		    			<td colspan="5"><a><span id="faultpictureurl"></span></a></td>
		    		</tr>
		    		<tr>
		    			<td colspan="6"  style="background-color:#dcdcdc;">工单进度信息</td>
		    		</tr>
		    		<tr>
		    			<td>处理阶段:</td>
		    			<td colspan="5">
		    			<ul style="display:flex;'" id="chuliState">
			                <li style="position:relative;padding-left:22px;"><span style="background-color:green;height:14px;width:14px;border-radius:14px;display:block;position:absolute;top:0;left:0;line-height:15px;text-align:center;color:white;">1</span><span style="color:green;">工单上报</span><span  class="qiantou"  style="height: 26px;width: 39px;border-radius: 12px; display: block;position: absolute;top: -8px;right: -53px; line-height: 12px;text-align: center;color: green;font-weight: bolder;font-size: 16px;background: url(../../common/images/jt-green.png) no-repeat;"></span></li>
		    				<li style="position:relative;padding-left:22px;"><span style="background-color:green;height:14px;width:14px;border-radius:14px;display:block;position:absolute;top:0;left:0;line-height:15px;text-align:center;color:white;">2</span><span style="color:green;">工单受理</span><span  class="qiantou"  style="height: 26px;width: 39px;border-radius: 12px; display: block;position: absolute;top: -8px;right: -53px; line-height: 12px;text-align: center;color: green;font-weight: bolder;font-size: 16px;background: url(../../common/images/jt-green.png) no-repeat;"></span></li>
		    				<li style="position:relative;padding-left:22px;"><span style="background-color:green;height:14px;width:14px;border-radius:14px;display:block;position:absolute;top:0;left:0;line-height:15px;text-align:center;color:white;">3</span><span style="color:green;">工单反馈</span><span  class="qiantou"  style="height: 26px;width: 39px;border-radius: 12px; display: block;position: absolute;top: -5px;right: -53px; line-height: 12px;text-align: center;color: green;font-weight: bolder;font-size: 16px;background: url(../../common/images/jt-gray.png) no-repeat;"></span></li>
		    				<li style="position:relative;padding-left:22px;"><span style="background-color:gray;height:14px;width:14px;border-radius:14px;display:block;position:absolute;top:0;left:0;line-height:15px;text-align:center;color:white;">4</span><span style="color:gray;">工单维保确认</span></li>		    			</ul>
		    			</ul>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>工单受理单位</td>
		    			<td><span id="jobacceptcompany"></span></td>		    			
		    			<td>工单受理人</td>
		    			<td><span id="jobacceptpeople"></span></td>
		    			<td>受理人电话</td>
		    			<td><span id="jobacceptphone"></span></td>
		    		</tr>
		    		<tr>
		    			<td>受理时间</td>
		    			<td><span id="jobaccepttime"></span></td>		    			
		    			<td>要求完成时间</td>
		    			<td><span id="requirefinishtime"></span></td>
		    			<td>工单受理信息</td>
		    			<td><span id="faultacceptinfo"></span></td>
		    		</tr>
		    		<tr>
		    			<td colspan="6"  style="background-color:#dcdcdc;">工单反馈</td>
		    		</tr>
		    		<tr>
		    			<td>是否申请延期</td>
		    			<td>
		    				<select  class="easyui-combobox" id='isdelay' name="isdelay" style="width:130px;margin:0;">
							    <option value="0">否</option>
							    <option value="1">是</option>							   
							</select>
						</td>		    			
		    			<td id="delay1" style="display:none">申请延期完成时间</td>
		    			<td id="delay2" style="display:none" >
		    				<input class="easyui-datetimebox" id="delaytime">				
		    			</span></td>
		    			<td id="delay3">维修状态</td>
		    			<td id="delay4">
		    				<select  class="easyui-combobox" id='repairstate' name="repairstate" style="width:130px;margin:0;">
							    <option value="1">已修复</option>
							    <option value="2">已更换</option>	
							    <option value="3">已废弃</option>							   
							</select>
						</td>	
						<td id="cause1" style="display:none">延期原因</td>
		    			<td colspan="5" id="cause2" style="display:none">
		    				<input id="delaycause" style="width:100%; font-size:12px;border: 0;text-align:center;">
						</td>		    			
		    		</tr>
		    		
		    		<tr id="delaydept" style="display:none">
		    			<td>延期审批单位</td>
		    			<td>
		    				<select  class="easyui-combobox" id="delayforcompany" name="delayforcompany" style="width:130px;margin:0;">
							</select>
		    			</td>
		    			<td>延期审批人</td>
		    			<td>
							<select  class="easyui-combobox" id="delayforpeople" name="delayforpeople" style="width:130px;margin:0;">
							</select>
						</td>		    			
		    			<td>审批人电话</td>
		    			<td><input id="delayforphone" style="font-size: 12px;border: 0;text-align: center;"></td>
		    		</tr>
		    		<tr id="delaydept1" style="display:none">
		    			<td>延期审批时间</td>
		    			<td>
		    				<input id="delayfortime" style="font-size: 12px;border: 0;text-align: center;">
		    			</td>
		    			<td>延期审批状态</td>
		    			<td>
		    				<input id="delayforstate" style="font-size: 12px;border: 0;text-align: center;">
						</td>		    			
		    			<td>延期审批信息</td>
		    			<td><input id="delayfordescription" style="font-size: 12px;border: 0;text-align: center;"></td>
		    		</tr>
		    		<tr id="fkqr">
		    			<td>反馈确认单位</td>
		    			<td>
							<select  class="easyui-combobox" id="confirmcompany" name="feedbackcompany" style="width:130px;margin:0;">
							</select>
						</td>		    			
		    			<td>反馈确认人</td>
		    			<td>
			    			<select  class="easyui-combobox" id="confirmpeople" name="feedbackpeople" style="width:130px;margin:0;">				  
							</select>
		    			</td>
		    			<td>反馈确认人电话</td>
		    			<td><input id="confirmphone" style="font-size: 12px;border: 0;text-align: center;"></td>
		    		</tr>
		    		<tr>
		    			<td >工单反馈描述</td>
		    			<td colspan="5">
		    				<input id="feedbackinfo" style="font-size:12px;border: 0;text-align:center;">
						</td>		    		
		    		</tr>
		    	</table>
		    </form>
		</div>
	</div>
	</body>
</html>	
 <script type="text/javascript">
    var sel = {};
 	var winId	= $.getUrlParam("winId");
	var jobid = $.getUrlParam("jobid");
	var isdelayatbefor = false;
 	$(function(){	
 		$('#faultpictureurl').click(function(){
 			$('#pic').show();
 		})
 		$('img').click(function(){
 			$('#pic').hide();
 		})
 		$('#isdelay').combobox({				// 是否延期
 			onChange: function (n,o) {
				if(n==1){			// 延期
					$('#delay1').show();
					$('#delay2').show();
					$('#delay3').hide();
					$('#delay4').hide();
					$('#cause1').show();
					$('#cause2').show();
					$('#delaydept').show();
					$('#fkqr').hide();
				}else if(n==0){		// 不延期
					$('#delay1').hide();
					$('#delay2').hide();
					$('#delay3').show();
					$('#delay4').show();
					$('#cause1').hide();
					$('#cause2').hide();
					$('#delaydept').hide();
					$('#fkqr').show();
				}
			}
 		})	
 		// 根据工单 id 查询 工单详情     并填充数据
 		$.ajax({
 			type :  'post',
 			dataType : 'json',
 			url : 'ywrepairjobinfoAction!get_Ywrepairjobinfo.do',
 			data: {'jobid':jobid},
 			success : function(res){
 				if(res){
 					sel = res;						// 赋值
 					$('#jobnum').html(res.jobnum);
 					$('#faultgradeMc').html(res.faultgradename);
 					$('#faultdevicetypeMc').html(res.faultdevicetypename);
 					$('#faultdevicename').html(res.faultdevicename);
 					$('#faultdeviceid').html(res.faultdeviceid);
 					$('#faultoccurtime').html(res.faultoccurtime);
 					$('#faulttypeMc').html(res.faulttypename);
 					$('#faultdescription').html(res.faultdescription);
 					$('#faultpictureurl').html(res.faultpictureurl);
 					$('#jobreportcompany').html(res.jobreportcompany);
 					$('#jobreportpeople').html(res.jobreportpeople);
 					if (res.jobreportphone == null || res.jobreportphone == "null") {
 						$('#jobreportphone').html("-");
 					} else {
 						$('#jobreportphone').html(res.jobreportphone);
 					}
 					$('#jobreporttime').html(res.jobreporttime);
 					$('#jobacceptcompany').html(res.feedbackcompanyname);
 					$('#jobacceptpeople').html(res.feedbackpeople);
 					$('#jobacceptphone').html(res.feedbackphone);
 					$('#jobaccepttime').html(res.jobaccepttime);
 					$('#requirefinishtime').html(res.requirefinishtime);
 					$('#faultacceptinfo').html(res.faultacceptinfo);
					if(res.isdelay == 1){ //判断是否申请延期数据 是否有填充，若填充显示延期申请审批情况
 						$('#isdelay').combobox('select', res.isdelay);
 						$('#isdelay').combobox('readonly', true);
 						$('#delay1').show();
 						$('#delay2').show();
 						$('#cause').show();
 						$('#delaydept').show();
 						$('#delaydept1').show();
 						$('#delaytime').datetimebox('setValue',res.delaytime);
 						$('#delaytime').datetimebox('readonly', true);
 						$('#delaycause').val(res.delaycause);
 						$('#delaycause').attr("readonly",true);
 						$('#delayforcompany').combobox('select', res.delayforcompany);
 						$('#delayforcompany').combobox('readonly', true);
 						$('#delayforpeople').combobox('select', res.delayforpeople);
 						$('#delayforpeople').combobox('readonly', true);
 						$('#delayforphone').val(res.delayforphone);
 						$('#delayforphone').attr('readonly', true);
 						$('#delayfortime').val(res.delayfortime);
 						$('#delayfortime').attr('readonly', true);
 						//判断 延期审批状态代码 显示文本
 						if(res.delayforstate == '908'){ // 908：延期申请待审核
 							$('#delayforstate').val('延期申请待审核');
 						}else if(res.delayforstate == '909'){	//909：延期申请审核通过
 							isdelayatbefor = true;
 							$('#delayforstate').val('延期申请审核通过');
 						}else if(res.delayforstate == '910'){	//910：延期申请审核不通过
 							isdelayatbefor = true;
 							$('#delayforstate').val('延期申请审核不通过');
 						}else{
 							$('#delayforstate').val('');
 						}
  						$('#delayfordescription').val(res.delayfordescription);
  						$('#delayfordescription').attr('readonly', true);
 						$('#fkqr').show();
 					}
 					var picUrl = res.faultpictureurl;
 					if(picUrl != null){
 						var proName = window.location.pathname.split("/")[1];
 						var sysUrl = "http://"+window.location.host+"/"+proName;
 					 	var picProxyGetUrl = sysUrl+"/sourceProxy?fileType=picUrlProxy&picUrl="+picUrl;
 					 	$('#pic img').attr("src",picProxyGetUrl);
 					}
 					
 				}
 			}
 		})
 		// 确认  反馈人相关信息
		$('#confirmcompany').combobox({				// 确认反馈单位
			 url:'ywrepairjobinfoAction!getReportBm.do',    // 查询有审批工单权限的部门
			 textField:"bmmc",  
			 valueField:"bmbh",
			 panelWidth:148,
			 value:"" 
		});
		$("#confirmcompany").combobox({			
			onChange: function (n,o) {
				$('#confirmpeople').combobox({				// 选取确认反馈人
					 url:'ywrepairjobinfoAction!getReportUser.do?bmbh='+n,    // 查询部门下有审批工单权限的人
					 textField:"yhmc",  
					 valueField:"yhzh",
					 value:"" 
				});
			}
		})
		$("#confirmpeople").combobox({			
			onChange: function (n,o) {
				$.ajax({
					type : 'post',
					dataType : 'json',
					url : 'ywrepairjobinfoAction!getReportUser.do',
					data : {'yhzh': n},
					success : function(res){
						if(res && res.length > 0){
							$('#confirmphone').val(res[0].sjhm)
						}else{
							$('#confirmphone').val("");
						}
					}
				})
			}
		})
		// 延期  反馈人相关信息
		$('#delayforcompany').combobox({				// 延期反馈单位
			 url:'ywrepairjobinfoAction!getReportBm.do',    // 查询有审批工单权限的部门
			 textField:"bmmc",  
			 valueField:"bmbh",
			 panelWidth:148,
			 value:"" 
		});
		$("#delayforcompany").combobox({			
			onChange: function (n,o) {
				$('#delayforpeople').combobox({				// 选取延期反馈人
					 url:'ywrepairjobinfoAction!getReportUser.do?bmbh='+n,    // 查询部门下有审批工单权限的人
					 textField:"yhmc",  
					 valueField:"yhzh",
					 value:"" 
				});
			}
		})
		$("#delayforpeople").combobox({			
			onChange: function (n,o) {
				$.ajax({
					type : 'post',
					dataType : 'json',
					url : 'ywrepairjobinfoAction!getReportUser.do',
					data : {'yhzh': n},
					success : function(res){
						if(res && res.length > 0){
							$('#delayforphone').val(res[0].sjhm)
						}else{
							$('#delayforphone').val("");
						}
					}
				})
			}
		})
		// 点击确认提交数据
		parent.parent.$(".l-btn-text").on("click",function(){
			if($(this).text()=="确定"){
				saveInfo();
			}
		})
 	});
 	function saveInfo(){								// 数据入库
 		var params = {};
 		var jobid = sel.jobid;
 		var isdelay = $('#isdelay').combobox("getValue");
 		var delayforcompany = null;			// 延期
 		var delayforpeople = null;
 		var delaytime = null;
 		var delaycause = null;
 		var delayforphone = null;
 		var jobprocessstate = null;			// 状态
 		var confirmcompany = null;			//  确认反馈
 		var confirmpeople = null;
 		var feedbackinfo = null;
 		var confirmphone = null;
 		var repairstate = null;
 		var feedbackphone = $('#jobacceptphone').text();
 		if(isdelay == 1 && isdelayatbefor != true){		//延期	
 			delayforcompany = $('#delayforcompany').combobox("getValue");
 			if(isNull(delayforcompany)){
 				top.$.dlg.alertError('延期审批单位不能为空! ');
 				return false;
 			} 
 			delayforpeople = $('#delayforpeople').combobox("getValue");
 			if(isNull(delayforpeople)){
 				top.$.dlg.alertError('延期审批人不能为空! ');
 				return false;
 			} 
 			delayforphone = $('#delayforphone').val();
 			if(isNull(delayforphone)){
 				top.$.dlg.alertError('延期审批人电话不能为空! ');
 				return false;
 			}
 			var reg = /^[0-9]{11}$/;
 			if (!reg.test(delayforphone)) {
 				$.showMsg('请修改为有效11位延期审批人电话! ');
 				return false;
 			}
 			delaytime = $('#delaytime').datetimebox("getValue");
 			delaycause = $('#delaycause').val(); 
 			if(isNull(delaycause)){
 				top.$.dlg.alertError('延期原因不可为空! ');
 				return false;
 			}
 			jobprocessstate = '908';						
 		}else{		// 不延期 即 确认反馈 	
 			confirmcompany = $('#confirmcompany').combobox("getValue");
 			if(isNull(confirmcompany)){
 				top.$.dlg.alertError('反馈确认单位不能为空! ');
 				return false;
 			}
 			confirmpeople = $('#confirmpeople').combobox("getValue");
 			if(isNull(confirmpeople)){
 				top.$.dlg.alertError('反馈确认人不能为空! ');
 				return false;
 			} 
 			confirmphone = $('#confirmphone').val();
 			if(isNull(confirmphone)){
 				top.$.dlg.alertError('反馈确认人电话不能为空! ');
 				return false;
 			}
 			var reg = /^[0-9]{11}$/;
 			if (!reg.test(confirmphone)) {
 				top.$.dlg.alertError('反馈确认人电话错误');
 				return;
 			}
 			feedbackinfo = $('#feedbackinfo').val(); 	
 			repairstate = $('#repairstate').combobox("getValue");
 			jobprocessstate = '906';
 		}
 		
 		params.XGTJjobid = jobid;
 		params.alarmeventid =  sel.alarmeventid;
 		params.faultdeviceid = sel.faultdeviceid;
 		if (sel.channelnum != null) {
 			params.channelnum = sel.channelnum;
		}
 		params.feedbacktime = getNowTime("-");
 		// 延期
 		params.isdelay = isdelay;	
 		if(isdelay == "1" && isdelayatbefor != true){			// 延期
 			params.delayforcompany = delayforcompany;
 	 		params.delayforpeople = delayforpeople;
 	 		params.delaytime = delaytime;
 	 		params.delaycause = delaycause;
 	 		params.extend1 = delayforpeople;
 		}else{
 			// 不延期
 			params.confirmcompany = confirmcompany;
 			params.confirmpeople = confirmpeople;
 			params.feedbackinfo = feedbackinfo;
 			params.confirmphone = confirmphone;
 			params.repairstate = repairstate;
 			params.extend1 = confirmpeople;
 		}
		params.jobprocessstate = jobprocessstate;
		params.flag = "feedback";
		params.feedbackphone = feedbackphone;
		$.ajax({
			url : "ywrepairjobinfoAction!edit_confirmOrder.do",
			type : "POST",
			dataType : "JSON",
			data : params,
			success : function(res){
				if(res == 'success'){
					$.showMsg("操作成功");
					top.$("#"+winId).dialog('close');
				}				
			}			
		})
 	}
 	function isNull(str){
 		if(str==null || str=='' || str==" " || str=="null" || str == undefined){
 			return true;
 		}else{
 			return false;
 		}
 	}
 	function getNowTime(flag){
		var date = new Date();
	    var year = date.getFullYear();
	    var month = date.getMonth() + 1;
	    var day = date.getDate();
	    var hour = date.getHours();
		var minute = date.getMinutes();
		var second = date.getSeconds();
		var minsec = date.getMilliseconds(); //获取当前毫秒数(0-999)
	    month = month < 10 ? '0' + month : month;
	    day = day < 10 ? '0' + day : day;
	    hour = hour < 10 ? '0' + hour : hour;
	    second = second < 10 ? '0' + second : second;
	    if(flag == "-"){
	    	return year +"-"+ month +"-"+ day +" "+ hour +":"+ minute +":"+ second;
	    }else{
	    	return "" + year + month + day + hour + minute + second + minsec;
	    }
	    
	}
</script>