<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8"%> 
<%@ page import="com.chengxusheji.po.Sell" %>
<%@ page import="com.chengxusheji.po.Customer" %>
<%@ page import="com.chengxusheji.po.Product" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    //获取所有的customerObj信息
    List<Customer> customerList = (List<Customer>)request.getAttribute("customerList");
    //获取所有的productObj信息
    List<Product> productList = (List<Product>)request.getAttribute("productList");
    Sell sell = (Sell)request.getAttribute("sell");

%>
<!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="sellEditForm" id="sellEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		  <div class="form-group">
			 <label for="sell_sellId_edit" class="col-md-3 text-right">销售id:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="sell_sellId_edit" name="sell.sellId" class="form-control" placeholder="请输入销售id" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="sell_productObj_productId_edit" class="col-md-3 text-right">销售产品:</label>
		  	 <div class="col-md-9">
			    <select id="sell_productObj_productId_edit" name="sell.productObj.productId" class="form-control">
			    </select>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_customerObj_customerId_edit" class="col-md-3 text-right">销售客户:</label>
		  	 <div class="col-md-9">
			    <select id="sell_customerObj_customerId_edit" name="sell.customerObj.customerId" class="form-control">
			    </select>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_price_edit" class="col-md-3 text-right">销售单价:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="sell_price_edit" name="sell.price" class="form-control" placeholder="请输入销售单价">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_sellCount_edit" class="col-md-3 text-right">销售数量:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="sell_sellCount_edit" name="sell.sellCount" class="form-control" placeholder="请输入销售数量">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_sellDate_edit" class="col-md-3 text-right">销售日期:</label>
		  	 <div class="col-md-9">
                <div class="input-group date sell_sellDate_edit col-md-12" data-link-field="sell_sellDate_edit" data-link-format="yyyy-mm-dd">
                    <input class="form-control" id="sell_sellDate_edit" name="sell.sellDate" size="16" type="text" value="" placeholder="请选择销售日期" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
		  	 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_payWay_edit" class="col-md-3 text-right">支付方式:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="sell_payWay_edit" name="sell.payWay" class="form-control" placeholder="请输入支付方式">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_logistics_edit" class="col-md-3 text-right">物流公司:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="sell_logistics_edit" name="sell.logistics" class="form-control" placeholder="请输入物流公司">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_wayNumber_edit" class="col-md-3 text-right">运单号:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="sell_wayNumber_edit" name="sell.wayNumber" class="form-control" placeholder="请输入运单号">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="sell_sellMemo_edit" class="col-md-3 text-right">销售备注:</label>
		  	 <div class="col-md-9">
			    <textarea id="sell_sellMemo_edit" name="sell.sellMemo" rows="8" class="form-control" placeholder="请输入销售备注"></textarea>
			 </div>
		  </div>
			  <div class="form-group">
			  	<span class="col-md-3""></span>
			  	<span onclick="ajaxSellModify();" class="btn btn-primary bottom5 top5">修改</span>
			  </div>
		</form> 
	    <style>#sellEditForm .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>
var basePath = "<%=basePath%>";
/*弹出修改销售界面并初始化数据*/
function sellEdit(sellId) {
	$.ajax({
		url :  basePath + "Sell/" + sellId + "/update",
		type : "get",
		dataType: "json",
		success : function (sell, response, status) {
			if (sell) {
				$("#sell_sellId_edit").val(sell.sellId);
				$.ajax({
					url: basePath + "Product/listAll",
					type: "get",
					success: function(products,response,status) { 
						$("#sell_productObj_productId_edit").empty();
						var html="";
		        		$(products).each(function(i,product){
		        			html += "<option value='" + product.productId + "'>" + product.productName + "</option>";
		        		});
		        		$("#sell_productObj_productId_edit").html(html);
		        		$("#sell_productObj_productId_edit").val(sell.productObjPri);
					}
				});
				$.ajax({
					url: basePath + "Customer/listAll",
					type: "get",
					success: function(customers,response,status) { 
						$("#sell_customerObj_customerId_edit").empty();
						var html="";
		        		$(customers).each(function(i,customer){
		        			html += "<option value='" + customer.customerId + "'>" + customer.customerName + "</option>";
		        		});
		        		$("#sell_customerObj_customerId_edit").html(html);
		        		$("#sell_customerObj_customerId_edit").val(sell.customerObjPri);
					}
				});
				$("#sell_price_edit").val(sell.price);
				$("#sell_sellCount_edit").val(sell.sellCount);
				$("#sell_sellDate_edit").val(sell.sellDate);
				$("#sell_payWay_edit").val(sell.payWay);
				$("#sell_logistics_edit").val(sell.logistics);
				$("#sell_wayNumber_edit").val(sell.wayNumber);
				$("#sell_sellMemo_edit").val(sell.sellMemo);
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*ajax方式提交销售信息表单给服务器端修改*/
function ajaxSellModify() {
	$.ajax({
		url :  basePath + "Sell/" + $("#sell_sellId_edit").val() + "/update",
		type : "post",
		dataType: "json",
		data: new FormData($("#sellEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                location.reload(true);
                $("#sellQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
        /*小屏幕导航点击关闭菜单*/
        $('.navbar-collapse a').click(function(){
            $('.navbar-collapse').collapse('hide');
        });
        new WOW().init();
    /*销售日期组件*/
    $('.sell_sellDate_edit').datetimepicker({
    	language:  'zh-CN',  //语言
    	format: 'yyyy-mm-dd',
    	minView: 2,
    	weekStart: 1,
    	todayBtn:  1,
    	autoclose: 1,
    	minuteStep: 1,
    	todayHighlight: 1,
    	startView: 2,
    	forceParse: 0
    });
    sellEdit("<%=request.getParameter("sellId")%>");
 })
 </script> 
</body>
</html>

