<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<title>供应商对账</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.">

<link rel="stylesheet" href="/SinoGYS/weixincss/weui.min.css">
<link rel="stylesheet" href="/SinoGYS/weixincss/jquery-weui.css">
<link rel="stylesheet" href="/SinoGYS/weixincss/demos.css">
<script src="/SinoGYS/js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="/SinoGYS/js/jquery-weui.js"></script>

</head>
<style>
	body, html {height:100%;}
	.weui_search_bar{margin-top: 50px;}
	.weui_navbar+.weui_tab_bd {padding-top: 0px;}
</style>

  <body>
   <input type="hidden" id="count" name="count" value="">
    <div class="weui_tab">
      <div class="weui_navbar">
        <div class="weui_navbar_item weui_bar_item_on" id="noAccount">待记账</div>
		<div class="weui_navbar_item" id="waitCheck">待审核</div>
        <div class="weui_navbar_item" id="checked">已通过</div>
        <div class="weui_navbar_item" id="non-checked">未通过</div>
      </div>
      
	   <div class="weui_search_bar" id="search_bar">
	      <div class="weui_search_outer">
	        <div class="weui_search_inner">
	          <i class="weui_icon_search"></i>
	          <input type="search" class="weui_search_input" id="search_input" placeholder="按月或编号搜索（例201701或20171207-0001 ）" required/>
	          <input type="hidden" id="searchFlag" name="searchFlag" value="">
	          <a href="javascript:" class="weui_icon_clear" id="search_clear"></a>
	        </div>
	        <label for="search_input" class="weui_search_text" id="search_text">
	          <i class="weui_icon_search"></i>
	          <span>搜索</span>
	        </label>
	      </div>
	      <a href="javascript:" class="weui_search_cancel" id="search_cancel">取消</a>
    	</div>
    	
	<div class="weui_tab_bd" >
	      <div class="weui-pull-to-refresh-layer">
		      <div class='pull-to-refresh-arrow'></div>
		      <div class='pull-to-refresh-preloader'></div>
		      <div class="down">下拉刷新</div>
		      <div class="up">释放刷新</div>
		      <div class="refresh">正在刷新</div>  
	      </div>
	      <div class="order_panel_bd_noAccount order_panel_bd"></div>
	      <div class="order_panel_bd_waitCheck order_panel_bd"></div>
	      <div class="order_panel_bd_checked order_panel_bd"></div>
	      <div class="order_panel_bd_non-checked order_panel_bd"></div>
      </div>
    </div>
    
    <form action="">
    	<input type="hidden" id="startRow" name="startRow" value=""> 
		<input type="hidden" id="paneltype" name="paneltype" value="noAccount">
		<input type="hidden" id="rescueCode" name="rescueCode" value="${param.rescueCode }">
    </form>
  </body>
  
  <script type="text/javascript">
  	// $("#date").calendar();
  	$(function(){
  	//	findCount("noAccount");
  		initValue("noAccount");
		$("#paneltype").val($(".weui_bar_item_on").attr("id"));
		initPanel("noAccount",true);
		$("#searchFlag").val(1);
		
  	});
  	
  	//上拉刷新js
	$(".weui_tab_bd").pullToRefresh().on("pull-to-refresh", function() {
		var flag=$("#searchFlag").val();
		//alert("标志==="+flag);
		var selectPanel;
		if(flag==1)selectPanel="noAccount";
		if(flag==2)selectPanel="waitCheck";
		if(flag==5)selectPanel="checked";
		if(flag==3)selectPanel="non-checked";
		initValue(selectPanel);
		initPanel(selectPanel,true);
        setTimeout(function() {
			$(".weui_tab_bd").pullToRefreshDone();
		}, 500);
      });
  	
  	$(document).keydown(function(event){
		if(event.keyCode==13){
			searchByCode();
		}
	});
	
	function searchByCode(){     //模糊查询订单
		$("#startRow").val(1);
		var code=$("#search_input").val();
		var flag=$("#searchFlag").val();
		var selectPanel;
		if(flag==1)selectPanel="noAccount";
		if(flag==2)selectPanel="waitCheck";
		if(flag==5)selectPanel="checked";
		if(flag==3)selectPanel="non-checked";
		$(".order_panel_bd_"+selectPanel).empty();
  		$(".order_panel_bd_"+selectPanel).show();
			$.ajax({
			type : "POST",
			url : "/SinoGYS/HistoryOrderAction.do?CMD=queryOrder",
			dataType: "json",
			data :{"code":code,"rescueCode":$("#rescueCode").val(),"searchFlag":flag,"startRow":$("#startRow").val()},
			success : function(data) {
				var count=data.count;
				if (data.orderList.length == 0) {
					loading && $.hideLoading();
					setTimeout(function() {
						$.toast("没有了", "text");
					}, 300);
					return ;
				}
				for ( var i in data.orderList) {
					var orderList=data.orderList;
					setPanel(orderList[i], selectPanel);
				}
				$(".order_panel_bd_" + selectPanel).append('<div class="weui_panel weui_panel_access"><a class="weui_panel_ft" onclick="queryMore()">查看更多(共'+count+'条)</a></div>');
			},
		});
	}
  	
  	//重置数据
  	function initValue(selectPanel){
  		//alert("==="+selectPanel);
  		$(".order_panel_bd").empty();
  		$(".order_panel_bd_"+selectPanel).empty();
  		$(".order_panel_bd_"+selectPanel).show();
  		$("#startRow").val(1);
  		
  		if(selectPanel=="noAccount")$("#searchFlag").val(1);  
  		if(selectPanel=="waitCheck")$("#searchFlag").val(2);
  		if(selectPanel=="checked")$("#searchFlag").val(5);
  		if(selectPanel=="non-checked")$("#searchFlag").val(3);
  	}
  	
  	
  	
  	$(".weui_navbar_item").click(function() {
		if (!$(this).hasClass("weui_bar_item_on")) {
			$(".weui_bar_item_on").removeClass("weui_bar_item_on");
			$(this).addClass("weui_bar_item_on");
			$("#paneltype").val($(this).attr("id"));
			$("#search_input").val("");
			initValue($(this).attr("id"));
			initPanel($(this).attr("id"),true);
		//	findCount($(this).attr("id"));
		}
	});
	
	//初始化
	function initPanel(selectPanel, loading) {
		loading && $.showLoading();
		$.ajax({
			type : "POST",
			dataType:"json",
			url : "/SinoGYS/HistoryOrderAction.do?CMD=findAccountOrder",
			data : $("form").serialize(),
			success : function(data) {
				var count=data.count;				
				if (data.accountList.length == 0) {
					loading && $.hideLoading();
					setTimeout(function() {
						$.toast("没有了", "text");
					}, 200);
					return ;
				}
				for ( var i in data.accountList) {
					var accountList=data.accountList;
				
					setPanel(accountList[i], selectPanel);
				}

					$(".order_panel_bd_" + selectPanel).append('<div class="weui_panel weui_panel_access"><a class="weui_panel_ft" onclick="queryMore()">查看更多(共'+count+'条)</a></div>');
				
				 setTimeout(function() {
					loading && $.hideLoading();
				}, 300);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				loading && $.hideLoading();
				$.toast("加载失败", "forbidden");
			}
		});
	}
	
	function setPanel(order, selectPanel) {
		var checkState;
		var ss='<div class="weui_media_box weui_media_text"><h4 class="weui_media_title">'
				+order.ORDER_CODE
				+'</h4><p class="weui_media_desc">请求地址：'
				+order.ADDRESS
				+'</p><div style="width:375px;height:60px;"><div style="float:left;"><p class="weui_media_desc">车牌号：'
				+order.license
				+'</p><p class="weui_media_desc">服务内容：'
				+order.SERVICE_NAME
				+'</p><p class="weui_media_desc">完成状况：'
				+(order.dispatchFlag==19?"放弃救援":"救援完成")
				+'</p><p class="weui_media_desc">结算方式：'
				+(order.settle_type==1?"月结":order.settle_type==2?"次结":order.settle_type==3?"现金结算":"无")
				+'</p></div>';
		if(selectPanel=="noAccount"){
			checkState=1;   //未记账
			ss=ss+'<div style="float: right;margin-right: 18%;margin-top: 5%;"><a class="weui_btn weui_btn_primary" style="width:64px;height:42px;" onclick="account('+order.ORDER_ID+','+checkState+','+order.checkId+')">记账</a></div></div></div>';
			$(".order_panel_bd_" + selectPanel).append(ss);
		}
		if(selectPanel=="waitCheck"){
			checkState=2;   //待审核
			ss=ss+'<div style="float: right;margin-right: 18%;margin-top: 5%;"><a class="weui_btn weui_btn_primary" style="width:64px;height:42px;" onclick="account('+order.ORDER_ID+','+checkState+','+order.checkId+')">查看</a></div></div></div>';
			$(".order_panel_bd_" + selectPanel).append(ss);
		}
		if(selectPanel=="checked"){
			checkState=5;
			ss=ss+'<div style="float: right;margin-right: 18%;margin-top: 5%;"><a class="weui_btn weui_btn_primary" style="width:64px;height:42px;"  onclick="account('+order.ORDER_ID+','+checkState+','+order.checkId+')">查看</a></div></div></div>';
			$(".order_panel_bd_" + selectPanel).append(ss);
		}
		if(selectPanel=="non-checked"){
			checkState=3;
			ss=ss+'<div style="float: right;margin-right: 18%;margin-top: 5%;"><a class="weui_btn weui_btn_primary" style="width:64px;height:42px;" onclick="account('+order.ORDER_ID+','+checkState+','+order.checkId+')">记账</a></div></div></div>';
			$(".order_panel_bd_" + selectPanel).append(ss);
		}
				
	}
		
		function queryMore(){
		 $("#startRow").val(parseInt($("#startRow").val())+1);
		 $(".weui_panel_access").hide();
		 initPanel($("#paneltype").val(),true);
		
	}
			
		function account(orderId,chargeType,checkId){
			window.location.href="http://www.sinoassistance.com/jsp/clientCustomer/jsp/passAccount.jsp?orderId="+orderId+"&chargeType="+chargeType+"&checkId="+checkId;
		}	
  </script>
</html>
