<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page isELIgnored="false"%>
<html lang="en">
<%
	String weixinUserId = (String)request.getAttribute("weixinUserId");
	String rescueCode=request.getParameter("rescueCode");
    String rescueVehicleId = request.getParameter("rescueVehicleId");
 %>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no" />
<title>我的历史案件</title>

<link rel="stylesheet" href="/SinoGYS/weixincss/weui.min.css">
<link rel="stylesheet" href="/SinoGYS/weixincss/jquery-weui.css">
<link rel="stylesheet" href="/SinoGYS/css/newCss/reset.css" />
<link rel="stylesheet" href="/SinoGYS/css/newCss/currentOrder.css" />
<script src="/SinoGYS/js/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript" src="/SinoGYS/layer/skin/layer.css"></script>
<script type="text/javascript" src="/SinoGYS/layer/layer.js"></script>
<script type="text/javascript" src="/SinoGYS/js/jquery-weui.js"></script>
<script src="/SinoGYS/js/ajaxHelper.js" type="text/javascript"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

<script type="text/javascript">
        var ohtml=document.documentElement;
        function getWidth(){
            var screenWidth=ohtml.clientWidth;
            if(screenWidth<320){
                ohtml.style.fontSize="13.3333px";
            }else if(screenWidth>1080){
                ohtml.style.fontSize="45px";
            }else{
                ohtml.style.fontSize=screenWidth/(1080/45)+"px";
            }
        }
        getWidth();
        window.onresize=function(){
            getWidth();
        };
</script>
</head>

<body >
	<input type="hidden" id="paneltype" name="paneltype" value="">
	<div class="currentOrderWrapper">
		<div class="currentOrderTitle">
			<div class="currentOrderTitleList text-left" id="todayOrder">
				<span class="currentOrderTitleItem">当日订单</span>
			</div>
			<div class="currentOrderTitleList text-center" id="weekOrder">
				<span class="currentOrderTitleItemNon">本周订单</span>
			</div>
			<div class="currentOrderTitleList text-right" id="monthOrder">
				<span class="currentOrderTitleItemNon">当月订单</span>
			</div>
		</div>
		<div class="historyOrderTab"></div>
	</div>

	<form action="">
		<input type="hidden" id="startRow" name="startRow" value=""> 
		<input type="hidden" id="rescueVehicleId" name="rescueVehicleId" value="<%=rescueVehicleId%>">
		<input type="hidden" id="beginTime" name="beginTime" value="">
	</form>
</body>

<script type="text/javascript">
	$(function() {
		$("#paneltype").val("todayOrder");
		initValue("todayOrder");
		orderList();
	});
	
	$(".currentOrderTitleList").on('click',function(){
		$.showLoading();
		$(".currentOrderTitleList").children("span").removeClass('currentOrderTitleItem').addClass('currentOrderTitleItemNon');
		$(this).children("span").removeClass('currentOrderTitleItemNon').addClass('currentOrderTitleItem');
		$("#paneltype").val($(this).attr("id"));
		initValue($(this).attr("id"));
		orderList();
	});
	 
	 //重置数据
	function initValue(selectPanel){
		$("#startRow").val(1);
		$(".historyOrderTab").empty();
		if(selectPanel=="todayOrder"){
			$("#beginTime").val(getFirstTimeOfDay());
		}
		if(selectPanel=="weekOrder"){
			$("#beginTime").val(getFirstDayOfWeek());
		}
		if(selectPanel=="monthOrder"){
			$("#beginTime").val(getFirstDayOfMonth());
		}
	}
	
	function orderList(){  //查看订单
		$.showLoading();
		$.ajax({
			type : "POST",
			url : "/SinoGYS/HistoryOrderAction.do?CMD=vehicleHistoryOrder",
			dataType: "json",
			data : $("form").serialize(),
			
			success : function(data) {
				$.hideLoading();
				var count=data.count;
				if (data.historyOrderList.length == 0) {
					$.hideLoading();
					setTimeout($.toast("没有了","text"),300);
					return;
				}
					for ( var i in data.historyOrderList) {
					var orderList=data.historyOrderList;
					
					$(".historyOrderTab").append('<div class="currentOrderList"><div class="currentOrderListTitle">'+
													'<span class="line"></span>'+orderList[i].SERVICE_NAME+'/'+(orderList[i].dispatchFlag==19?"取消救援服务":"完成救援服务")+
													'<div class="fileBtnWrapper"><a class="fileBtn currentFile" onclick=supply('+orderList[i].ORDER_ID+','+<%=rescueCode%>+','+(orderList[i].flowId==1?"11":"111")+
													')>现场资料 </a><a class="fileBtn otherFile" onclick=supply('+orderList[i].ORDER_ID+','+<%=rescueCode%>+','+15+')>其他资料 </a>'+
													'</div></div><div class="currentOrderCon"><div><span>订单编号:</span> <span>'+orderList[i].ORDER_CODE+'</span></div>'+
													'<div><span>救援地点:</span> <span>'+orderList[i].ADDRESS+'</span></div><div><span>完成时间:</span> <span>'+orderList[i].FINISHTIME.substring(0, 19)+'</span></div>'+
													'</div></div>');
					}
						
				$(".orderMain").append('<div class="weui_panel weui_panel_access" style="margin-top:0px;"><a class="weui_panel_ft" href="javascript:void(0);" onclick="queryMore()">查看更多(共'+count+'条)</a></div>');
			},
		});
	}
	
	function supply(orderId,rescueCode,state){
		window.location.href="/SinoGYS/supplier/connectionImg.jsp?orderId="+orderId+"&rescueCode="+rescueCode+"&state="+state;
	}
	
	function queryMore(){
		 $("#startRow").val(parseInt($("#startRow").val())+1);
		 $(".weui_panel_access").hide();
		 orderList();
	}
	
	//时间格式化
	function timeFormate(date){
		if(!date||typeof(date)=="String"){
			this.error("参数异常");
		}
		var y=date.getFullYear();  //年
		var m=date.getMonth()+1;  //月
		m = m < 10 ? "0"+m : m ;
		var d=date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y+"-"+m+"-"+d;
	}
	
	//获取本月第一天
	function getFirstDayOfMonth(){
		var date=new Date();
		date.setDate(1);
		return this.timeFormate(date)+" 00:00:00";
	}
	
	//获取本星期第一天
	function getFirstDayOfWeek(){
		var date=new Date();
		var weekday=date.getDay()||7;  //获取星期几
		date.setDate(date.getDate()-weekday+1);
		return this.timeFormate(date)+" 00:00:00";
	}
	
	//获取当天时间
	function getFirstTimeOfDay(){
		var date=new Date();
		return this.timeFormate(date)+" 00:00:00";
	}
	
	 $(".weui_tab_bd").pullToRefresh().on("pull-to-refresh", function() {
	 	alert($("#paneltype").val());
	 	initValue($("#paneltype").val());
		orderList();
        setTimeout(function() {
          $(".weui_tab_bd").pullToRefreshDone();
        }, 2000);
      });
      
</script>
</html>


