/**
 * 工单受理
 */
var winId	= $.getUrlParam("winId");
var jobid	= $.getUrlParam("jobid");
var record = {};
$(function(){
	initOrder();
	$('#faultpictureurl').click(function(){
		$('#pic').show();
	})
	$('img').click(function(){
		$('#pic').hide();
	})


	//监听是否驳回
	$('#isreject').combobox({
		onChange: function (newValue, oldValue) {
			if(newValue=="1"){
				$("[name='confirmTd']").hide();
				$("[name='rejectTd']").show();
				$("[name='rejectTd1']").show();
			}else{
				$("[name='rejectTd']").hide();
				$("[name='confirmTd']").show();
				$("[name='rejectTd1']").hide();
			}

		}
	});

	//初始化
	$("#isreject").combobox("setValue","0");
	parent.parent.$(".l-btn-text").on("click",function(){
		if($(this).text()=="确定"){
			getData();
		}
	})
});



//获取工单数据
function getData(){
	var param = {};
	param.jobreporttime = record.jobreporttime;
	//告警设备类型
	param.faultdevicetype = record.faultdevicetype;
	param.XGTJfaultdeviceid = record.faultdeviceid;
	param.XGTJchannelnum = record.channelnum;
	param.XGTJvideonum = record.faultdeviceid;
	//告警参数
	param.XGTJalarmeventid = record.alarmeventid;
	param.processstatus = 915;//已验收已确认
	param.processdescription = "";
	//工单参数
	param.XGTJjobid = jobid;
	param.jobid = jobid;
	param.jobprocessstate = 915;//待反馈
	var isreject = $("#isreject").combobox("getValue");//是否驳回
	param.isreject = isreject;
	if(isreject=="1"){//驳回
		var rejectcause = $("#rejectcause").val();
		if(rejectcause==undefined || rejectcause=="" || rejectcause == null){
			$.showMsg("驳回原因不可为空");
			return;
		}
		param.rejectcause = rejectcause;
		param.processstatus = 916;   //验收确认不通过
		param.jobprocessstate = 916; //验收确认不通过
		param.processdescription = rejectcause;
		param.receiverdata =$("#receiverdata").val();
		operationTable(param);
	}else{//确认
		// var confirmtime =$('#receivertime').datetimebox("getValue");//确认时间
		// var confirmdescription = $("#confirmdescription").val();//受理人
		// var confirmfaulttype = $("#confirmfaulttype").combobox("getValue");//受理人
		// param.confirmtime = confirmtime;
		// param.processtime = confirmtime;
		// param.maintenanceResult=$("#maintenanceResult").val()
		// if(confirmdescription==undefined || confirmdescription=="" ){
		// 	$.showMsg("确认信息不能为空");
		// 	return;
		// }
		param.maintenanceResult=$('#maintenanceResult').val();
		if(param.maintenanceResult==undefined || param.maintenanceResult=="" ){
			$.showMsg("确认维护结果状况不能为空");
			return;
		}

		param.confirmMaintenance=$('#confirmMaintenance').val();
		param.completionTime=$('#completionTime').datebox('getValue');
		param.receivertime=$('#receivertime').datebox('getValue');

		param.accuracyOfInfo=$('#accuracyOfInfo').numberbox('getValue');
		param.construction=$('#construction').val();




		operationTable(param);
	}
}
//入库
function operationTable(obj){
	if(obj){
		$.ajax({
			url : "ywrepairjobinfoAction!updateWorkOrderInfo.do",
			type : "POST",
			dataType : "JSON",
			data : obj,
			success : function(res){
				$.showMsg("操作成功");
				top.$("#"+winId).dialog("close");
			}
		})
	}
}
//tr联动展示
function displayTR(){
	if(newValue=="1"){
		$("#isreject").combobox("setValue","0");
		$("#hangupTR").css("display","block");
		$("#rejectTR").css("display","none");
		$("#feedbackTR").css("display","none");
		$("#infoTR").css("display","none");
	}else{
		if($("#isreject").combobox("getValue")=="1"){
			$("#hangupTR").css("display","none");
			$("#rejectTR").css("display","block");
			$("#feedbackTR").css("display","none");
			$("#infoTR").css("display","none");
		}else{

		}
	}
}

//初始化工单
function initOrder(){
	$.ajax({
		url : "ywrepairjobinfoAction!get_Ywrepairjobinfo.do",
		type : "POST",
		dataType : "JSON",
		data : {jobid:jobid},
		success : function(res){
			if(res){
				record = res;
				renderOrder(res);//渲染工单
			}else{
				$.showMsg("未关联到工单！")
			}
		},
		error : function(res){ }
	});

	var isrejectArr = [{"id":"0","text":"否","selected":true},{"id":"1","text":"是"}];
	$("#isreject").combobox("loadData",isrejectArr);




}
function renderOrder(res){
	//初始化页面数据
//	console.log("工单反馈：",res);
	$("#jobid").text(transEmptyObj(res.jobnum));
	$("#alarmgradename").text(transEmptyObj(res.faultgradename));
	$("#faultdevicetypename").text(transEmptyObj(res.faultdevicetypename));
	$("#faultdevicename").text(transEmptyObj(res.faultdevicename));
	$("#faultdeviceid").text(transEmptyObj(res.faultdeviceid));
	$("#faultoccurtime").text(transEmptyObj(res.faultoccurtime));
	$("#faulttype").text(transEmptyObj(res.faulttypename));
	$("#jobreportcompanyname").text(transEmptyObj(res.jobreportcompanyname));
	$("#jobreportpeoplename").text(transEmptyObj(res.jobreportpeople));
	if (res.jobreportphone == null || res.jobreportphone == "null") {
		$('#jobreportphone').html("-");
	} else {
		$('#jobreportphone').html(res.jobreportphone);
	}
	$("#jobreporttime").text(transEmptyObj(res.jobreporttime));
	$("#faultdescription").text(transEmptyObj(res.faultdescription));
	$("#faultpictureurl").html(transEmptyObj(res.faultpictureurl));//todo
	$("#confirmtime").text(res.confirmtime );
	$("#confirmdescription").text(res.confirmdescription );
	$("#confirmdescription").text(res.confirmdescription );
	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);
	}


	$("#jobacceptcompanyname").text(transEmptyObj(res.feedbackcompanyname));
	$("#jobacceptpeople").text(transEmptyObj(res.feedbackpeople));
	$("#jobacceptphone").text(transEmptyObj(res.feedbackphone));
	$("#jobaccepttime").text(transEmptyObj(res.jobaccepttime));
	$("#requirefinishtime").text(transEmptyObj(res.requirefinishtime));
	$("#faultacceptinfo").text(transEmptyObj(res.faultacceptinfo));
	$("#isdelay").text(transEmptyObj(res.isdelay)=="1"?"是":"否");
	$("#delaytime").text(transEmptyObj(res.delaytime));
	$("#delayfordescription").text(transEmptyObj(res.delayfordescription));
	$("#feedbackcompanyname").text(transEmptyObj(res.confirmcompanyname));
	$("#feedbackpeople").text(transEmptyObj(res.confirmpeople));
	$("#feedbackphone").text(transEmptyObj(res.confirmphone));
	$("#feedbacktime").text(transEmptyObj(res.feedbacktime));
	$("#feedbackinfo").text(transEmptyObj(res.feedbackinfo));

	$("#confirmfaulttype").text(res.confirmfaulttype=='1'?'监控告警':res.confirmfaulttype=='2'?'服务器告警':res.confirmfaulttype=='3'?'应用系统告警':'存储告警');
	$("#faultdevicename1").text(transEmptyObj(res.faultdevicename));


//	$("#xx7").combobox("setValue",records.xx7);
}
function transEmptyObj(data){
	var result = "";
	if(data){
		result = data;
	}else{
		result = "-";
	}
	return result;
}
function getCurrentTime(){
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var day = date.getDate();
	var hours = date.getHours();
	var minute = date.getMinutes();
	var second = date.getSeconds();
	if(month<10){
		month = "0"+month;
	}
	if(day<10){
		day = "0"+day;
	}
	if(hours<10){
		hours = "0"+hours;
	}
	if(minute<10){
		minute = "0"+minute;
	}
	if(second<10){
		second = "0"+second;
	}
	return year + "-" + month + "-" + day + " " + hours + ":" + minute + ":" +second;
}