<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!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,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="/favicon.ico">
<LINK rel="Shortcut Icon" href="/favicon.ico" />
<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/skin/default/skin.css" rel="stylesheet" type="text/css" id="skin" />
<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" />
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<style>
.text-center{text-align:center !important;}
.text-center input{border:1px solid transparent;padding:6px 3px;}
.text-center input:hover{border:1px solid rgba(0,0,0,.1)}
.text-blue {color:blue;}
.text-red {color:red;}

.spinner {
  margin: 1px auto;
  width: 50px;
  height: 30px;
  text-align: center;
  font-size: 10px;
}
 
.spinner > div {
  background-color: #67CF22;
  height: 100%;
  width: 6px;
  display: inline-block;
   
  -webkit-animation: stretchdelay 1.2s infinite ease-in-out;
  animation: stretchdelay 1.2s infinite ease-in-out;
}
 
.spinner .rect2 {
  -webkit-animation-delay: -1.1s;
  animation-delay: -1.1s;
}
 
.spinner .rect3 {
  -webkit-animation-delay: -1.0s;
  animation-delay: -1.0s;
}
 
.spinner .rect4 {
  -webkit-animation-delay: -0.9s;
  animation-delay: -0.9s;
}
 
.spinner .rect5 {
  -webkit-animation-delay: -0.8s;
  animation-delay: -0.8s;
}
 
@-webkit-keyframes stretchdelay {
  0%, 40%, 100% { -webkit-transform: scaleY(0.4) } 
  20% { -webkit-transform: scaleY(1.0) }
}
 
@keyframes stretchdelay {
  0%, 40%, 100% {
    transform: scaleY(0.4);
    -webkit-transform: scaleY(0.4);
  }  20% {
    transform: scaleY(1.0);
    -webkit-transform: scaleY(1.0);
  }
}
</style>
<title>提现记录</title>
</head>
<body>
	<!-- <nav class="breadcrumb">
		<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
		提现记录 <span class="c-gray en">&gt;</span>提现记录列表 <a
			class="btn btn-success radius r mr-20"
			style="line-height: 1.6em; margin-top: 3px"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="Hui-iconfont">&#xe68f;</i></a>
	</nav> -->
	<div class="pd-20">
	<iframe name="ajaxifr" runat="server" style="display:none;"></iframe>
	<form action="${pageContext.request.contextPath }/admin/withdraw/seachInfo" method="post" id="form-admin-add" name="form1" enctype="multipart/form-data">
		<div class="text-l"> 
			所属角色：
			<select  size="1" id="roleId" name="roleId">
							<c:forEach items="${roles}" var="role">
							   <option value="${role.roleId}" selected>${role.roleName}</option>
							</c:forEach>
						</select>
			二维码：
			<select  size="1" id="hasQrcode" name="hasQrcode">
							<option value=1 selected>没有</option>
							<option value=2>是</option>
						</select>
			选择父级：
			<select  style="width:120px" id="getPid"  name="PlacePid">
				<option value=0 selected>省代</option>
			</select>
			选择模版：
			<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>
			
			<button type="button" class="btn btn-success radius" id="add_tr_btn" name="">增加</button>
		</div>
		
		<div class="text-l"> 
		   <input type="text" style="width:160px;height:28px;" placeholder="请输入生成数量（小于500）"  name="num" id="num">
		   <button type="button" class="btn btn-success radius" id="authAdd" name="">增加</button>
		   <button type="button" class="btn btn-success radius hidden" id="authDownLoad" beginNum=0 >下载</button>
		   <div id="loadDeal" class="hidden" style="float:right;margin-right:500px;">
				<div class="spinner">
				  <div class="rect1"></div>
				  <div class="rect2"></div>
				  <div class="rect3"></div>
				  <div class="rect4"></div>
				  <div class="rect5"></div>
				</div>
		    </div>
		     <span class="btn-upload">
			  <a href="${pageContext.request.contextPath }/admin/drp/upLoadExcel" class="btn btn-primary radius"><i class="iconfont">&#xf0020;</i> 浏览文件</a>
			  <input type="file" multiple name="file_0" class="input-file">
			 </span> 
			
			<div style="padding:10px 0">
				<%-- <form id="UploadForm" action="${pageContext.request.contextPath }/admin/drp/upLoadExcel" method="post" enctype="multipart/form-data"> 
			　　　	<input type="file" class="file-uploader" name="uploadDataField" id="FileUploader"/> 
			　　　　　　<div class="file-uploader-wrap-fake"> 
			　　　　　　　　<input type="text" id="PathDisplayer" class="input-text" disabled /> 
			　　　　　　　　<a href="javascript:void(0)" class="link-btn" >选择文件</a> 
			　　　　　　</div> 
					<button type="button" id="uploadFile" class="btn btn-success radius">提交</button>
			　　</form> --%>
			    选择要上传的文件：<input type="file" class="fileInput" name="file"  id="file"/> 
			    <input type="button" class="btn btn-success radius" value="上传" onclick="uploadExcel();" />  
			</div>
			
			
			<div style="padding:10px 0">
			    批量添加分销商：<input type="file" class="fileInput" name="file2"  id="file2"/> 
			    <input type="button" class="btn btn-success radius" value="上传" onclick="addloadExcel2();" />  
			</div>
		</div>
		
		<table class="table table-border table-bordered table-bg">
			<thead>
				<tr class="text-c">
					<th width="180">公司名称</th>
					<th width="150">姓名</th>
					<th width="150">联系方式</th>
					<th width="250">代理商地址</th>
					<th width="130">备注</th>
					<th width="130">操作</th>
				</tr>
			</thead>
			<tbody>
				<tr role="row" class="odd tr_0">
				<td class="text-center"><input type="text" placeholder="请填写公司名称"/></td>
				<td class="text-center"><input type="text" placeholder="请填写姓名"/></td>
				<td class=" text-center"><input type="text" placeholder="请填写手机号码"/></td>
				<td class=" text-center"><input type="text" placeholder="请填写代理商地址"/></td>
				<td class=" text-center"><input type="text" placeholder="请填写备注"/></td>
				<td class=" text-center"><a class="text-danger saveInfo" href="javascript:void(0)" title="保存" saveid="tr_0">保存 </a>
				&nbsp;<a class="text-warning updateInfo" href="javascript:void(0)" title="编辑" saveid="tr_0" infoId="0">编辑</a></td></tr>
			</tbody>
		</table>
  		</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/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/js/tips.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/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript">
	
	function uploadExcel() {
		document.form1.target = 'ajaxifr';
		document.form1.action='${pageContext.request.contextPath }/admin/drp/upLoadExcel';
		document.form1.submit();
	}
	function addloadExcel2() {
		document.form1.target = 'ajaxifr';
		document.form1.action='${pageContext.request.contextPath }/admin/drp/addLoadExcel';
		document.form1.submit();
	}
	
	function msg(message)
	{
		alert(message);
	}
	
	
	function dataValidation(){
		if($("#withdrawUsername").val()!=null){
			 //收款人姓名数据验证
			if(!commonLengthJdg('withdrawUsername',1,30,null,true)){
				layer.msg("收款人姓名长度为1-30位",{icon: 2,time:2000});
				return false;
			}
		}
	}
	var count=0;
	$('body').on('click',"#add_tr_btn",function(){
		++count;
		$("tbody").append('<tr role="row" class="odd tr_'+count+'"><td class="text-center"><input type="text" placeholder="请填写公司名称"/></td><td class="text-center"><input type="text" placeholder="请填写姓名"/></td><td class=" text-center"><input type="text" placeholder="请填写手机号码"/></td><td class=" text-center"><input type="text" placeholder="请填写代理商地址"/></td><td class=" text-center"><input type="text" placeholder="请填写备注"/></td><td class=" text-center"><a class="text-danger saveInfo" href="javascript:void(0)" title="保存" saveid="tr_'+count+'">保存 </a>&nbsp;<a class="text-warning updateInfo" href="javascript:void(0)" title="编辑" saveid="tr_'+count+'" infoId="0" >编辑</a></td></tr>')
	});
	$("body").on('click',".saveInfo",function(){
		//获取 saveid
		var saveid=$(this).attr("saveid");
		console.log(saveid);
		//获取当前点击的tr内的td
		console.log($("."+saveid+" td"));
		var $tr=$("."+saveid+" td");
		
		var company=$tr.eq(0).children().val();
		//alert($tr.eq(0).children().val());
		var name=$tr.eq(1).children().val();
		var contact=$tr.eq(2).children().val();
		var address=$tr.eq(3).children().val();
		var beizhu=$tr.eq(4).children().val();

		$.ajax({
			url : '${pageContext.request.contextPath }/admin/drp/addPlaceInfoDeal',
			type : "POST",
			dataType : "json",
			data: {
				"name":company,
				"userName":name,
				"remark":beizhu,
				"tel":contact,
				"addr":address,
				"roleId":$("#roleId").val(),
				"templateId":$("#templateId").val(),
				"placePid":$("#getPid").val(),
				"hasQrcode":$("#hasQrcode").val()
				},
			success : function(data) {
				alert("添加成功！");
				$tr.eq(5).children().eq(0).addClass("text-blue");
				//alert(data.data.id);
				$tr.eq(5).children().eq(1).attr("infoId",data.data.id);
			},
			error : function(data) {
				alert(data.message);
				$tr.eq(5).children().eq(0).addClass("text-red");
				layer.msg(data.status,{icon: 5,time:1000});
			}
		});
	});
	
	$("body").on('click',".updateInfo",function(){
		//获取 saveid
		var saveid=$(this).attr("saveid");
		console.log(saveid);
		//获取当前点击的tr内的td
		console.log($("."+saveid+" td"));
		var $tr=$("."+saveid+" td");
		
		var company=$tr.eq(0).children().val();
		var name=$tr.eq(1).children().val();
		var contact=$tr.eq(2).children().val();
		var address=$tr.eq(3).children().val();
		var beizhu=$tr.eq(4).children().val();
		var infoId=$tr.eq(5).children().eq(1).attr("infoId");
		alert(infoId);
 
		$.ajax({
			url : '${pageContext.request.contextPath }/admin/drp/EditPlaceInfoSubmit',
			type : "POST",
			dataType : "json",
			data: {
				"name":company,
				"userName":name,
				"remark":beizhu,
				"tel":contact,
				"addr":address,
				"roleId":$("#roleId").val(),
				"templateId":$("#templateId").val(),
				"placePid":$("#getPid").val(),
				"hasQrcode":$("#hasQrcode").val(),
				"id":infoId
				},
			success : function(data) {
				alert("修改成功！");
				$tr.eq(5).children().eq(1).addClass("text-blue");
			},
			error : function(data) {
				alert(data.message);
				$tr.eq(5).children().eq(1).addClass("text-red");
				layer.msg(data.status,{icon: 5,time:1000});
			}
		});
	});
	
	$("body").on('click',"#authAdd",function(){
		
		if(!confirm("确定要批量生成数据吗？")){
			return ;
		}
		
		var num=$("#num").val();
		if(num==""){
			alert("生成数不能为空！");
			return ;
		}
		if($("#getPid").val()==""){
			alert("父级数不能为空！");
			return ;
		}
		if($("#templateId").val()==""){
			alert("模板不能为空！");
			return ;
		}
		
		$("#loadDeal").removeClass("hidden");
		num=parseInt(num);
		$.ajax({
			url : '${pageContext.request.contextPath }/admin/drp/addPlaceInfoAutoBattle',
			type : "POST",
			dataType : "json",
			data: {
				"num":num,
				"roleId":parseInt($("#roleId").val()),
				"templateId":parseInt($("#templateId").val()),
				"placePid":parseInt($("#getPid").val()),
				"hasQrcode":parseInt($("#hasQrcode").val())
				},
			success : function(data) {
				alert(JSON.stringify(data));
				$("#loadDeal").addClass("hidden");
				//alert(data.id);
				$("#authDownLoad").removeClass("hidden");
				$("#authDownLoad").attr("beginNum",parseInt(data.id));
				alert("生成成功！");
			},
			error : function(data) {
				alert(data.message);
				layer.msg(data.status,{icon: 5,time:1000});
			}
		});
		
	});
	
	$("body").on('click',"#authDownLoad",function(){
		var beginNum=parseInt($("#authDownLoad").attr("beginNum"));
		var num=parseInt($("#num").val());
		window.location.href = "/watero/admin/drp/advanceDownLoadPlaceInfos?beginNum="+beginNum+"&num="+num;
	});
	
	var pageNo=1;
	//下拉搜索框
	$("#getPid").select2({
	  language: "zh-CN",
	  ajax: {
	    url: "/watero/admin/drp/searchPlaceInfoParent",
	    dataType: 'json',
	    delay: 250,
	    data: function (params) {
	      return {
	        search: params.term, // search term
	        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){ //下拉框渲染选择后的格式
		    //alert(item.supperId);
	        //$("#supperId").val(item.supperId);
			var itemStr="<option value='"+item.id+"' selected>"+item.name+"</option>";
			return itemStr;
		} 
	});
	
	$("#uploadFile").click(function(){
		alert(233);
		$("#UploadForm").submit();
	});
	
</script>
</body>
</html>