<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!-- <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,member-scalable=no" /> -->
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/html5.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="${pageContext.request.contextPath }/common/css/bootstrap.min-3.3.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/select2/select2.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->

<style>
#datainit{
 margin-left:5px;
}

</style>
<title>分销商管理操作</title>
</head>
<body>
<div class="codeView">
			<form action="/tooth/admin/drp/addPlaceInfoDeal" method="post" class="form form-horizontal" id="form-Validform" novalidate="novalidate">
				<input type="hidden" id="topRoleId" value="${topRoleId}"> <%--最高级别的角色id - 逗号分割--%>

				<!-- <input type="hidden" name="supperId" value=0 id="supperId"/> -->
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商户名称：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" datatype="*2-30" nullmsg="商户名称不能为空" placeholder="4~16个字符，字母/中文/数字/下划线" nullmsg="用户名不能为空" name="name" id="name">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>商户姓名：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" placeholder="2~16个字符，字母/中文/数字/下划线" datatype="*2-16" nullmsg="商户姓名不能为空" name="userName" id="userName">
					</div>
				</div>
				<!-- <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">openid：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" placeholder="4~16个字符，字母/中文/数字/下划线" nullmsg="微信号不能为空！" name="openid" id="openid">
					</div>
				</div> -->
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所属角色：</label>
					<div class="formControls col-xs-6 col-sm-6"> <span class="select-box">
						<select class="select" size="1" id="roleId" name="roleId">
							<c:forEach items="${roles}" var="role">
								<c:if test="${role.roleName != '微代理'}">
							   <option value="${role.roleId}" selected>${role.roleName}</option>
								</c:if>
							</c:forEach>
						</select>
						</span> 
					</div>
				</div>
				<div class="row cl"  id="isHide">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>区域：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" placeholder="请输入城市，多个城市用逗号隔开"  name="areaName" id="areaName">
					</div>
				</div>
			
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否需要二维码:</label>
					<div class="formControls col-xs-6 col-sm-6"> <span class="select-box">
						<select class="select" size="1" id="hasQrcode" name="hasQrcode">
							<option value=1 selected>不需要</option>
							<option value=2>需要</option>
						</select>
						</span> </div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">选择模板：</label>
					<div class="formControls col-xs-6 col-sm-6"> 
						<select class="select"  id="templateId"  name="templateId">
						 <option value=0 selected>无模板</option>
						<c:forEach items="${templates}" var="template">
							   <option value="${template.templateId}">${template.templateName}</option>
						</c:forEach>
							<!-- <option value=1 selected>省代+代理+门店</option>
							<option value=2 >省代+母婴店</option> -->
						</select>
					</div>
				</div>
				<div class="row cl" id="parentMerchant">
					<label class="form-label col-xs-4 col-sm-3">选择父级(商户名称)：</label>
					<div class="formControls col-xs-6 col-sm-6"> 
						<select class="select"  id="getPid"  name="PlacePid">
							<option value=0 selected>省代</option>
						</select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系方式：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" autocomplete="off" dataType="m" placeholder="手机/电话" nullmsg="联系方式不能为空" name="tel" id="tel">
					</div>
				</div>

				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>代理商地址：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<input type="text" class="input-text" placeholder="分销联系地址" datatype="*" name="addr" nullmsg="联系地址不能为空" id="addr">
						<input type="hidden" name="placeInfoStus" value="2">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">备注：</label>
					<div class="formControls col-xs-6 col-sm-6">
						<textarea class="textarea" placeholder="说点什么...最少输入10个字符" name="remark" onkeyup="textarealength(this,500)"></textarea>
						<p class="textarea-numberbar"><em class="textarea-length">0</em>/500</p>
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					    
						 <input class="btn btn-primary" type="submit"  value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					     <input class="btn btn-primary" type="button" onclick="closeWindow()"  value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
					</div>
				</div>
			</form>
		</div>



<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/select2/select2.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/select2/zh-CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript"> 

$("#supperId").val(0);
$(function(){ 
	
	
  $("#form-Validform").Validform({ 
    tiptype:4, 
    ajaxPost:true, 
    beforeCheck:function(curform){
    	var placeRole = $('#placeRole').val();
    },
    callback:function(data){
      if(data.result == "200"){
        layer.msg(data.message, {icon:data.message,time: 1000}, function(){ 
        	 var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			 parent.tableRefresh();//刷新母页面
       	     parent.layer.close(index);
          });  
      } 
      else{ 
        layer.msg(data.message, {icon: data.message,time: 3000}); 
      } 
    } 
  });  
  
  roleHide();
}); 

 //提交表单
 function submitpage(){
	 return $("#form-Validform").submitForm(false);
 }

//关闭窗口
function closeWindow(){
	  var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	  parent.layer.close(index);
}
var pageNo=1;
//下拉搜索框
$("#getPid").select2({
	language: "zh-CN",
	ajax: {
		type:'post',
	    url: "/tooth/admin/drp/searchPlaceInfoParent",
	    dataType: 'json',
	    delay: 250,
	    data: function (params) {
			return {
	        	search: params.term, // search term
	        	roleId: $("#roleId").val(),
	        	templateId: $("#templateId").val()
	       		//pageNo: pageNo
	        //type:$("#placeType").val()=='1'?0:parseInt($("#placeType").val())-1
	      	};
	    },
	    processResults: function (data, params) {
	      	// parse the results into the format expected by Select2
	      	// since we are using custom formatting functions we do not need to
	     	// alter the remote JSON data, except to indicate that infinite
	      	// scrolling can be used
			params.page = params.page || 1;
	      	//pageNo=pageNo+1;
	     	console.info(JSON.stringify(data));
	     	return {
		  		results: data.data,
		        pagination: {
		         	more: (params.page * 15) < data.totalNumber
		        }
			};
	    },
	    cache: true
  	},
  	escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
  	minimumInputLength: 1,
  	templateResult:function(item){ //下拉框渲染拉下列表的格式
		var itemStr="<option value='"+item.id+"' selected>"+item.name+"</option>";
		return itemStr;
	}, 
 	templateSelection:function(item){ //下拉框渲染选择后的格式
        var itemStr = "";
	    if (item.name != undefined && item.name != null) {
            itemStr="<option value='"+item.id+"' selected>"+item.name+"</option>";
		} else {
	        itemStr = "<option value='' selected>请输入父级名称</option>";
		}
        //$("#supperId").val(item.supperId);
		return itemStr;
	} 
});

$("#roleId").change(function(){
	debugger;
	var textstr=$("#roleId").find("option:selected").text();
	if(textstr=='省代'){
		$("#isHide").removeClass("hide");
	}else{
		$("#isHide").addClass("hide");
	}

	// 当角色id为最高级的角色Id，就会屏蔽选择父级商户   -- start
	var roleId = $("#roleId").find("option:selected").val();
	var topRoleId = $("#topRoleId").val();
	var topRoleIds = topRoleId.split(",");
	var flag = true;
	for(var i=0;i<topRoleIds.length;i++){
		if(roleId == topRoleIds[i]){
			flag = false;
		}
	}
	if(flag){
		$("#parentMerchant").show();
	}else{
		$("#parentMerchant").hide();
		$("#getPid").html('<option value="0" selected="">省代</option>');
		$("#select2-getPid-container").html('<option value="" selected="">请输入父级名称</option>');
	}
	// 当角色id为最高级的角色Id，就会屏蔽选择父级商户   -- end
});

function roleHide() {
	var textstr=$("#roleId").find("option:selected").text();
	if(textstr=='省代'){
		$("#isHide").removeClass("hide");
	}else{
		$("#isHide").addClass("hide");
	}
}

</script> 

</body>
</html>