<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8"%> 
<%@ page import="com.chengxusheji.po.Customer" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    Customer customer = (Customer)request.getAttribute("customer");

%>
<!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"> 
</head>
<body style="margin-top:70px;"> 
<div class="container">
<jsp:include page="../header.jsp"></jsp:include>
	<div class="col-md-9 wow fadeInLeft">
	<ul class="breadcrumb">
  		<li><a href="<%=basePath %>index.jsp">首页</a></li>
  		<li class="active">客户信息修改</li>
	</ul>
		<div class="row"> 
      	<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">
			    <script name="customer.memo" id="customer_memo_edit" type="text/plain"   style="width:100%;height:500px;"></script>
			 </div>
		  </div>
			  <div class="form-group">
			  	<span class="col-md-3""></span>
			  	<span onclick="ajaxCustomerModify();" class="btn btn-primary bottom5 top5">修改</span>
			  </div>
		</form> 
	    <style>#customerEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
   </div>
</div>


<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_editor = UE.getEditor('customer_memo_edit'); //客户备注编辑框
var basePath = "<%=basePath%>";
/*弹出修改客户界面并初始化数据*/
function customerEdit(customerId) {
  customer_memo_editor.addListener("ready", function () {
    // editor准备好之后才可以使用 
    ajaxModifyQuery(customerId);
  });
}
 function ajaxModifyQuery(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_editor.setContent(customer.memo, false);
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*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("信息修改成功！");
                location.reload(true);
                $("#customerQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
        /*小屏幕导航点击关闭菜单*/
        $('.navbar-collapse a').click(function(){
            $('.navbar-collapse').collapse('hide');
        });
        new WOW().init();
    customerEdit("<%=request.getParameter("customerId")%>");
 })
 </script> 
</body>
</html>

