<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8"%> 
<%@ page import="com.chengxusheji.po.Customer" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    List<Customer> customerList = (List<Customer>)request.getAttribute("customerList");
    int currentPage =  (Integer)request.getAttribute("currentPage"); //当前页
    int totalPage =   (Integer)request.getAttribute("totalPage");  //一共多少页
    int recordNumber =   (Integer)request.getAttribute("recordNumber");  //一共多少记录
    String customerName = (String)request.getAttribute("customerName"); //客户名称查询关键字
    String customerType = (String)request.getAttribute("customerType"); //客户类型查询关键字
    String telephone = (String)request.getAttribute("telephone"); //客户电话查询关键字
%>
<!DOCTYPE html>
<html>
<head>
<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">
<title>客户查询</title>
<link href="<%=basePath %>plugins/bootstrap.css" rel="stylesheet">
<link href="<%=basePath %>plugins/bootstrap-dashen.css" rel="stylesheet">
<link href="<%=basePath %>plugins/font-awesome.css" rel="stylesheet">
<link href="<%=basePath %>plugins/animate.css" rel="stylesheet">
<link href="<%=basePath %>plugins/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
<jsp:include page="../header.jsp"></jsp:include>
	<div class="row"> 
		<div class="col-md-9 wow fadeInDown" data-wow-duration="0.5s">
			<div>
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
			    	<li><a href="<%=basePath %>index.jsp">首页</a></li>
			    	<li role="presentation" class="active"><a href="#customerListPanel" aria-controls="customerListPanel" role="tab" data-toggle="tab">客户列表</a></li>
			    	<li role="presentation" ><a href="<%=basePath %>Customer/customer_frontAdd.jsp" style="display:none;">添加客户</a></li>
				</ul>
			  	<!-- Tab panes -->
			  	<div class="tab-content">
				    <div role="tabpanel" class="tab-pane active" id="customerListPanel">
				    		<div class="row">
				    			<div class="col-md-12 top5">
				    				<div class="table-responsive">
				    				<table class="table table-condensed table-hover">
				    					<tr class="success bold"><td>序号</td><td>记录id</td><td>客户名称</td><td>客户类型</td><td>客户电话</td><td>客户地址</td><td>操作</td></tr>
				    					<% 
				    						/*计算起始序号*/
				    	            		int startIndex = (currentPage -1) * 5;
				    	            		/*遍历记录*/
				    	            		for(int i=0;i<customerList.size();i++) {
					    	            		int currentIndex = startIndex + i + 1; //当前记录的序号
					    	            		Customer customer = customerList.get(i); //获取到客户对象
 										%>
 										<tr>
 											<td><%=currentIndex %></td>
 											<td><%=customer.getCustomerId() %></td>
 											<td><%=customer.getCustomerName() %></td>
 											<td><%=customer.getCustomerType() %></td>
 											<td><%=customer.getTelephone() %></td>
 											<td><%=customer.getCustomerAddress() %></td>
 											<td>
 												<a href="<%=basePath  %>Customer/<%=customer.getCustomerId() %>/frontshow"><i class="fa fa-info"></i>&nbsp;查看</a>&nbsp;
 												<a href="#" onclick="customerEdit('<%=customer.getCustomerId() %>');" style="display:none;"><i class="fa fa-pencil fa-fw"></i>编辑</a>&nbsp;
 												<a href="#" onclick="customerDelete('<%=customer.getCustomerId() %>');" style="display:none;"><i class="fa fa-trash-o fa-fw"></i>删除</a>
 											</td> 
 										</tr>
 										<%}%>
				    				</table>
				    				</div>
				    			</div>
				    		</div>

				    		<div class="row">
					            <div class="col-md-12">
						            <nav class="pull-left">
						                <ul class="pagination">
						                    <li><a href="#" onclick="GoToPage(<%=currentPage-1 %>,<%=totalPage %>);" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
						                     <%
						                    	int startPage = currentPage - 5;
						                    	int endPage = currentPage + 5;
						                    	if(startPage < 1) startPage=1;
						                    	if(endPage > totalPage) endPage = totalPage;
						                    	for(int i=startPage;i<=endPage;i++) {
						                    %>
						                    <li class="<%= currentPage==i?"active":"" %>"><a href="#"  onclick="GoToPage(<%=i %>,<%=totalPage %>);"><%=i %></a></li>
						                    <%  } %> 
						                    <li><a href="#" onclick="GoToPage(<%=currentPage+1 %>,<%=totalPage %>);"><span aria-hidden="true">&raquo;</span></a></li>
						                </ul>
						            </nav>
						            <div class="pull-right" style="line-height:75px;" >共有<%=recordNumber %>条记录，当前第 <%=currentPage %>/<%=totalPage %> 页</div>
					            </div>
				            </div> 
				    </div>
				</div>
			</div>
		</div>
	<div class="col-md-3 wow fadeInRight">
		<div class="page-header">
    		<h1>客户查询</h1>
		</div>
		<form name="customerQueryForm" id="customerQueryForm" action="<%=basePath %>Customer/frontlist" class="mar_t15">
			<div class="form-group">
				<label for="customerName">客户名称:</label>
				<input type="text" id="customerName" name="customerName" value="<%=customerName %>" class="form-control" placeholder="请输入客户名称">
			</div>






			<div class="form-group">
				<label for="customerType">客户类型:</label>
				<input type="text" id="customerType" name="customerType" value="<%=customerType %>" class="form-control" placeholder="请输入客户类型">
			</div>






			<div class="form-group">
				<label for="telephone">客户电话:</label>
				<input type="text" id="telephone" name="telephone" value="<%=telephone %>" class="form-control" placeholder="请输入客户电话">
			</div>






            <input type=hidden name=currentPage value="<%=currentPage %>" />
            <button type="submit" class="btn btn-primary">查询</button>
        </form>
	</div>

		</div>
	</div> 
<div id="customerEditDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" style="width:900px;" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><i class="fa fa-edit"></i>&nbsp;客户信息编辑</h4>
      </div>
      <div class="modal-body" style="height:450px; overflow: scroll;">
      	<form class="form-horizontal" name="customerEditForm" id="customerEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		  <div class="form-group">
			 <label for="customer_customerId_edit" class="col-md-3 text-right">记录id:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="customer_customerId_edit" name="customer.customerId" class="form-control" placeholder="请输入记录id" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="customer_customerName_edit" class="col-md-3 text-right">客户名称:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="customer_customerName_edit" name="customer.customerName" class="form-control" placeholder="请输入客户名称">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="customer_customerType_edit" class="col-md-3 text-right">客户类型:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="customer_customerType_edit" name="customer.customerType" class="form-control" placeholder="请输入客户类型">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="customer_telephone_edit" class="col-md-3 text-right">客户电话:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="customer_telephone_edit" name="customer.telephone" class="form-control" placeholder="请输入客户电话">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="customer_customerAddress_edit" class="col-md-3 text-right">客户地址:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="customer_customerAddress_edit" name="customer.customerAddress" class="form-control" placeholder="请输入客户地址">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="customer_memo_edit" class="col-md-3 text-right">客户备注:</label>
		  	 <div class="col-md-9">
			 	<textarea name="customer.memo" id="customer_memo_edit" style="width:100%;height:500px;"></textarea>
			 </div>
		  </div>
		</form> 
	    <style>#customerEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
      <div class="modal-footer"> 
      	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      	<button type="button" class="btn btn-primary" onclick="ajaxCustomerModify();">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<jsp:include page="../footer.jsp"></jsp:include> 
<script src="<%=basePath %>plugins/jquery.min.js"></script>
<script src="<%=basePath %>plugins/bootstrap.js"></script>
<script src="<%=basePath %>plugins/wow.min.js"></script>
<script src="<%=basePath %>plugins/bootstrap-datetimepicker.min.js"></script>
<script src="<%=basePath %>plugins/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="<%=basePath %>js/jsdate.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor1_4_3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor1_4_3/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
<script>
//实例化编辑器
var customer_memo_edit = UE.getEditor('customer_memo_edit'); //客户备注编辑器
var basePath = "<%=basePath%>";
/*跳转到查询结果的某页*/
function GoToPage(currentPage,totalPage) {
    if(currentPage==0) return;
    if(currentPage>totalPage) return;
    document.customerQueryForm.currentPage.value = currentPage;
    document.customerQueryForm.submit();
}

/*可以直接跳转到某页*/
function changepage(totalPage)
{
    var pageValue=document.customerQueryForm.pageValue.value;
    if(pageValue>totalPage) {
        alert('你输入的页码超出了总页数!');
        return ;
    }
    document.customerQueryForm.currentPage.value = pageValue;
    documentcustomerQueryForm.submit();
}

/*弹出修改客户界面并初始化数据*/
function customerEdit(customerId) {
	$.ajax({
		url :  basePath + "Customer/" + customerId + "/update",
		type : "get",
		dataType: "json",
		success : function (customer, response, status) {
			if (customer) {
				$("#customer_customerId_edit").val(customer.customerId);
				$("#customer_customerName_edit").val(customer.customerName);
				$("#customer_customerType_edit").val(customer.customerType);
				$("#customer_telephone_edit").val(customer.telephone);
				$("#customer_customerAddress_edit").val(customer.customerAddress);
				customer_memo_edit.setContent(customer.memo, false);
				$('#customerEditDialog').modal('show');
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*删除客户信息*/
function customerDelete(customerId) {
	if(confirm("确认删除这个记录")) {
		$.ajax({
			type : "POST",
			url : basePath + "Customer/deletes",
			data : {
				customerIds : customerId,
			},
			success : function (obj) {
				if (obj.success) {
					alert("删除成功");
					$("#customerQueryForm").submit();
					//location.href= basePath + "Customer/frontlist";
				}
				else 
					alert(obj.message);
			},
		});
	}
}

/*ajax方式提交客户信息表单给服务器端修改*/
function ajaxCustomerModify() {
	$.ajax({
		url :  basePath + "Customer/" + $("#customer_customerId_edit").val() + "/update",
		type : "post",
		dataType: "json",
		data: new FormData($("#customerEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                $("#customerQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();

})
</script>
</body>
</html>

