<%@ page language="java" import="java.util.*"  contentType="text/html;charset=UTF-8"%> 
<%@ page import="com.chengxusheji.po.Customer" %>
<%@ page import="com.chengxusheji.po.Product" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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;">
<jsp:include page="../header.jsp"></jsp:include>
<div class="container">
	<div class="row">
		<div class="col-md-12 wow fadeInUp" data-wow-duration="0.5s">
			<div>
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
			    	<li role="presentation" ><a href="<%=basePath %>Sell/frontlist">销售列表</a></li>
			    	<li role="presentation" class="active"><a href="#sellAdd" aria-controls="sellAdd" role="tab" data-toggle="tab">添加销售</a></li>
				</ul>
				<!-- Tab panes -->
				<div class="tab-content">
				    <div role="tabpanel" class="tab-pane" id="sellList">
				    </div>
				    <div role="tabpanel" class="tab-pane active" id="sellAdd"> 
				      	<form class="form-horizontal" name="sellAddForm" id="sellAddForm" enctype="multipart/form-data" method="post"  class="mar_t15">
						  <div class="form-group">
						  	 <label for="sell_productObj_productId" class="col-md-2 text-right">销售产品:</label>
						  	 <div class="col-md-8">
							    <select id="sell_productObj_productId" name="sell.productObj.productId" class="form-control">
							    </select>
						  	 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_customerObj_customerId" class="col-md-2 text-right">销售客户:</label>
						  	 <div class="col-md-8">
							    <select id="sell_customerObj_customerId" name="sell.customerObj.customerId" class="form-control">
							    </select>
						  	 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_price" class="col-md-2 text-right">销售单价:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="sell_price" name="sell.price" class="form-control" placeholder="请输入销售单价">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_sellCount" class="col-md-2 text-right">销售数量:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="sell_sellCount" name="sell.sellCount" class="form-control" placeholder="请输入销售数量">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_sellDateDiv" class="col-md-2 text-right">销售日期:</label>
						  	 <div class="col-md-8">
				                <div id="sell_sellDateDiv" class="input-group date sell_sellDate col-md-12" data-link-field="sell_sellDate" data-link-format="yyyy-mm-dd">
				                    <input class="form-control" id="sell_sellDate" 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" class="col-md-2 text-right">支付方式:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="sell_payWay" name="sell.payWay" class="form-control" placeholder="请输入支付方式">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_logistics" class="col-md-2 text-right">物流公司:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="sell_logistics" name="sell.logistics" class="form-control" placeholder="请输入物流公司">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_wayNumber" class="col-md-2 text-right">运单号:</label>
						  	 <div class="col-md-8">
							    <input type="text" id="sell_wayNumber" name="sell.wayNumber" class="form-control" placeholder="请输入运单号">
							 </div>
						  </div>
						  <div class="form-group">
						  	 <label for="sell_sellMemo" class="col-md-2 text-right">销售备注:</label>
						  	 <div class="col-md-8">
							    <textarea id="sell_sellMemo" name="sell.sellMemo" rows="8" class="form-control" placeholder="请输入销售备注"></textarea>
							 </div>
						  </div>
				          <div class="form-group">
				             <span class="col-md-2""></span>
				             <span onclick="ajaxSellAdd();" class="btn btn-primary bottom5 top5">添加</span>
				          </div>
						</form> 
				        <style>#sellAddForm .form-group {margin:10px;}  </style>
					</div>
				</div>
			</div>
		</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/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="<%=basePath %>plugins/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="<%=basePath %>plugins/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script>
var basePath = "<%=basePath%>";
	//提交添加销售信息
	function ajaxSellAdd() { 
		//提交之前先验证表单
		$("#sellAddForm").data('bootstrapValidator').validate();
		if(!$("#sellAddForm").data('bootstrapValidator').isValid()){
			return;
		}
		jQuery.ajax({
			type : "post",
			url : basePath + "Sell/add",
			dataType : "json" , 
			data: new FormData($("#sellAddForm")[0]),
			success : function(obj) {
				if(obj.success){ 
					alert("保存成功！");
					$("#sellAddForm").find("input").val("");
					$("#sellAddForm").find("textarea").val("");
				} else {
					alert(obj.message);
				}
			},
			processData: false, 
			contentType: false, 
		});
	} 
$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();
	//验证销售添加表单字段
	$('#sellAddForm').bootstrapValidator({
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields: {
			"sell.price": {
				validators: {
					notEmpty: {
						message: "销售单价不能为空",
					},
					numeric: {
						message: "销售单价不正确"
					}
				}
			},
			"sell.sellCount": {
				validators: {
					notEmpty: {
						message: "销售数量不能为空",
					},
					integer: {
						message: "销售数量不正确"
					}
				}
			},
			"sell.sellDate": {
				validators: {
					notEmpty: {
						message: "销售日期不能为空",
					}
				}
			},
			"sell.payWay": {
				validators: {
					notEmpty: {
						message: "支付方式不能为空",
					}
				}
			},
			"sell.logistics": {
				validators: {
					notEmpty: {
						message: "物流公司不能为空",
					}
				}
			},
			"sell.wayNumber": {
				validators: {
					notEmpty: {
						message: "运单号不能为空",
					}
				}
			},
		}
	}); 
	//初始化销售产品下拉框值 
	$.ajax({
		url: basePath + "Product/listAll",
		type: "get",
		success: function(products,response,status) { 
			$("#sell_productObj_productId").empty();
			var html="";
    		$(products).each(function(i,product){
    			html += "<option value='" + product.productId + "'>" + product.productName + "</option>";
    		});
    		$("#sell_productObj_productId").html(html);
    	}
	});
	//初始化销售客户下拉框值 
	$.ajax({
		url: basePath + "Customer/listAll",
		type: "get",
		success: function(customers,response,status) { 
			$("#sell_customerObj_customerId").empty();
			var html="";
    		$(customers).each(function(i,customer){
    			html += "<option value='" + customer.customerId + "'>" + customer.customerName + "</option>";
    		});
    		$("#sell_customerObj_customerId").html(html);
    	}
	});
	//销售日期组件
	$('#sell_sellDateDiv').datetimepicker({
		language:  'zh-CN',  //显示语言
		format: 'yyyy-mm-dd',
		minView: 2,
		weekStart: 1,
		todayBtn:  1,
		autoclose: 1,
		minuteStep: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0
	}).on('hide',function(e) {
		//下面这行代码解决日期组件改变日期后不验证的问题
		$('#sellAddForm').data('bootstrapValidator').updateStatus('sell.sellDate', 'NOT_VALIDATED',null).validateField('sell.sellDate');
	});
})
</script>
</body>
</html>
