<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + path2+"/";
	request.setAttribute("contextPath", basePath);
	
	String redirectUrl= request.getParameter("redirectUrl");
	request.setAttribute("redirectUrl", redirectUrl);
%> 
<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>添加客户</title>
    <script src="${contextPath }res/js/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="${contextPath }res/js/layer/layer.min.js"></script>
    <script src="${contextPath }app/lib/flexible.js"></script>
    <link rel="stylesheet" href="${contextPath }app/lib/flexible.css">
	<link rel="stylesheet" href="${contextPath }app/css/basem.css">
	<link rel="stylesheet" href="${contextPath }app/css/logome.css">
		<link rel="stylesheet" href="<%=basePath %>app/css/index.css">
	<script type="text/javascript">
	<%-- $(function(){
		$('#button').click(function(){ 
			var name=$("input[name='name']").val();
			var phone=$("input[name='phone']").val();
			var company=$("input[name='company']").val(); 
			var attributionArea=$("input[name='attributionArea']").val();
			var address=$("#address").val();
			
			if(name=="" && phone=="" && company=="" && attributionArea==""&&address==""){
				window.location.href = '${contextPath }web/mgmUserCtl/index.cs';
			}else{
				var pram='{"name":"'+name+'","phone":"'+phone+'","company":"'+company+'","attributionArea":"'+attributionArea+'","address":"'+address+'"}';
				$.post('${contextPath}web/mgmProduct/addCustomer.cs', {
					"data" : pram
				}, function(data) {
					var datas=eval(data.data);
					if (data.ret == 1) {
						/* window.history.go(-1);  */
						window.location.href="<%=basePath%>web/mgmProduct/recommend.cs?productids=${pids}" ;
					}else{  
						layer.msg(data.msg);
					}
				}, "json"); 
			}
		});
	}) --%>
	</script>
</head>
<body>
<div id="tj_client">
	<div class="titbox blubg">
		<a class="titreturn left" href="javascript:void(0)" onclick="back()"><img src="${contextPath }app/img/fanhui16@2x.png" alt=""></a>
		<h1>添加客户</h1>
		 <script type="text/javascript">
			function back(){
				window.history.go(-1);
			}
			</script>
	</div>
	<form action="#" name="loginForm" id="loginForm" method="post">
	<div class="whbg top50">
		<div class="safe">
			<ul>
				<li class="merecli">
					<p class="meaddle left">客户姓名：</p>
					<input class="meaddinpu left" type="text" name="name" placeholder="请输入客户姓名">
				</li>
				<li class="merecli">
					<p class="meaddle left">联系电话：</p>
					<input class="meaddinpu left blutxt" type="text"  name="phone" placeholder="请输入客户联系电话">
				</li>
				<li class="merecli">
					<p class="meaddle left">工作单位：</p>
					<input class="meaddinpu left" type="text"  name="company" placeholder="请输入客户工作单位">
				</li>
				
				<li class="merecli">
					<p class="meaddle left">所在区域：</p>
					<input id="pcarea" name="attributionArea" class="meaddinpu left" readonly="readonly" type="text"  placeholder="请选择客户所在区域">
					<input id="province" name="province" class="meaddinpu left" type="hidden">
					<input id="city" name="city" class="meaddinpu left" type="hidden">
					<input id="area" name="area" class="meaddinpu left" type="hidden">
				</li> 
				<li class="merecli meaddlila">
					<p class="meaddle left">详细地址：</p>
					<textarea class="meaddinpu left"  name="address" id="address"  placeholder="请输入客户详细地址"></textarea>
				</li>
				<li class="merecli meaddlila">
					<p class="meaddle left">客户备注：</p>
					<textarea class="meaddinpu left"  name="remarks" id="remarks"  placeholder="请输入客户备注"></textarea>
				</li>
			</ul> 
		</div>
	</div>
	<a class="redbtn" href="javascript:void(0);" id="button">完成</a>
	</form>
</div>	
	<!-- 城市弹窗 -->
        <div class="cityMask hide">
            <div class="titbox blubg"> 
                <a class="titreturn left" href="javascript:void(0)" onclick="backper()"><img src="<%=basePath %>app/img/fanhui16@2x.png" alt=""></a>
                <h1>选择城市</h1>
            </div>
            <div class="top50">
                <ul class="cityul">
                    <li>
                        <a href="#">
                                                                                  北京
                            <img src="<%=basePath %>app/img/fanh3@2x.png" alt="">
                        </a>
                    </li>
                   
                </ul>
                
            </div>

        </div>
</body>
 <script type="text/javascript" src="<%=basePath %>app/js/public.js"></script>
 <script type="text/javascript">
   $(function(){
		$('#button').click(function(){ 
			var recommendId="${USER_ID}";
			var name=$("input[name='name']").val();
			var phone=$("input[name='phone']").val();
			var company=$("input[name='company']").val(); 
			var attributionArea=$("input[name='attributionArea']").val();
			var address=$("#address").val();
			var province=$("input[name='province']").val();
			var city=$("input[name='city']").val();
			var area=$("input[name='area']").val();
			var remarks=$("textarea[name='remarks']").val();
			if(name=="" && phone=="" && company=="" && attributionArea==""&&address==""){
				layer.msg("请完善客户信息");
			}else{ 
				var pram='{"recommendId":"'+recommendId+'","name":"'+name+'","phone":"'+phone+'","company":"'+company+'","attributionArea":"'+attributionArea+'","address":"'+address+'","province":"'+province+'","city":"'+city+'","area":"'+area+'","remarks":"'+remarks+'"}';
				$.post('${contextPath}web/mgmCustomerWebCtl/addCustomer.cs', {
					"data" : pram
				}, function(data) {
					var datas=eval(data.data);
					if (data.ret == 1) {
						layer.msg('添加成功！', {
							  time: 20000,
							  btn: ['确定'] //按钮
							}, function(){
								window.location.href="<%=basePath%>web/mgmProduct/recommend.cs?productids=${pids}" ; 
							});
					}else{  
						layer.msg(data.msg);
					}
				}, "json"); 
			}
		});
	})  
 
 
		$("#pcarea").click(function(){
        	$(".cityul").html('');
        	$.get('<%=basePath%>area/getProvice.cs',function(data){
        		var html = "";
        		for(var i in data){
        			html += "<li onclick='proclick(\""+data[i].code+"\",\""+data[i].name+"\")'>";
        			html += "<a href='javascript:void(0)'>";
        			html += data[i].name;
        			html += " <img src='<%=basePath %>app/img/fanh3@2x.png' alt=''>";
        			html += "</a>";    
        			html += "</li>";    
        		}
        		$(".cityul").html(html);
        	}); 
            $("#tj_client").hide();
            $(".cityMask").show();
        })
        
        function proclick(code, name){
        	var html = "";
        	$.get('<%=basePath%>area/getByParentCode.cs',{'param': code}, function(data){
        		for(var i in data){
        			html += "<li onclick='cityclick(\""+data[i].code+"\",\""+data[i].name+"\")'>";
        			html += "<a href='javascript:void(0)'>";
        			html += data[i].name;
        			html += " <img src='<%=basePath %>app/img/fanh3@2x.png' alt=''>";
        			html += "</a>";    
        			html += "</li>"; 
        		}
        		$(".cityul").html(html);
        	}); 
        	$('#province').val(name);
        }
        
		function cityclick(code, name){
        	var html = "";
        	$.get('<%=basePath%>area/getByParentCode.cs',{'param': code}, function(data){
        		for(var i in data){
        			html += "<li onclick='countyclick(\""+data[i].code+"\",\""+data[i].name+"\")'>";
        			html += "<a href='javascript:void(0)'>";
        			html += data[i].name;
        			html += " <img src='<%=basePath %>app/img/fanh3@2x.png' alt=''>";
        			html += "</a>";    
        			html += "</li>"; 
        		}
        		$(".cityul").html(html);
        	}); 
        	$('#city').val(name);
        }
		
        function countyclick(code, name){
        	$("#tj_client").show();
            $(".cityMask").hide();
            
            $('#area').val(name);
            $('#pcarea').val($('#province').val()+" " + $('#city').val()+" " + $('#area').val());
            
            replace(categoryid, num, type, twotype, '2', '1');
        }
        
        function backper(){
        	$("#tj_client").show();
            $(".cityMask").hide();
        }
		</script>
</html>