<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; 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" />
<!--[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]-->
<!--[if IE 6]>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<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/icheck/icheck.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/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<title>添加返利节点</title>
</head>
<body>
	<div class="pd-20">
  		<form action="${pageContext.request.contextPath }/admin/templateFlow/addTemplateFlowInfo" method="post" class="form form-horizontal" id="form-member-add">
  			<input type="hidden" id="count" name="count" value="${templateInfo.count}"/>
  			<input type="hidden" id="templateId" name="templateId" value="${templateInfo.templateId}"/>
  			<input type="hidden" id="templateName" value="${templateInfo.templateName }" />
  			<!-- 产品返利类型 -->
  			<c:forEach items="${typeList }" var="type">
			<div class="row cl">
				${type.typeName }-<input type="checkbox" name="productType" class="type-class" id="checkbox-pinglun" value="${type.typeId }">
			</div>
			</c:forEach>
  			<div id="createTable" class="mt-20">
			</div>
  			<div class="col-9" style="padding-top: 10px;margin-left: 50%">
        		<input class="btn btn-primary radius"  type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
      		</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/Validform/5.3.2/Validform.min.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">
	var count = 0;
	var templateName = '';
	var nameArray = new Array();
	
  	$(function($) {
  		count = $('#count').val();
  		templateName = $('#templateName').val();
  		nameArray = templateName.split('+');
  		createTable(count,5);
  	});
  	
  	function checkPruductType() {
		var typeClass = $(".type-class");
		for (var i = 0; i < typeClass.length; i=i+1) {
			// 对象转换
			var $type = typeClass[i];
			if ($type.checked) {
				return true;
			}
		}
		return false;
  	}
  	
  	$(function(){
  		$("#form-member-add").Validform({
  			tiptype:2,
  			callback:function(form){
  				var isTrue = true;
  				$('input[type="text"]').each(function() {
  					var vdefault = this.value;
  					if ($(this).attr('readonly') != "readonly") {
  						if (!(/^[0-9]*$/.test(vdefault))) {
  	  						isTrue = false;
  	  					}
  					}
  				});
  				if (isTrue) {
  					if (!checkPruductType()) {
  						alert("请选择产品类型!");
  						return false;
  					}
  					form[0].submit();
  				} else {
					alert('返利金额必须为数字!');
					return false;
  				}
  			}
  		});
  	});
  	
  	//动态创建table
  	function createTable(rowCount,cellCount) { 
       var table=$('<table class="table table-border table-bordered table-hover table-bg table-sort">');
       table.appendTo($('#createTable'));
       for(var i=0;i < rowCount;i++)
       {
          var tr=$('<tr></tr>');
          tr.appendTo(table);
          for(var j=0;j < cellCount;j++)
          {
        	  createTd(tr,i,j);
          }
       }
       tr.appendTo(table);
       $("#createTable").append('</table>');
    }
  	
  	//创建table中的td
  	function createTd(tr,i,j) {
  		var td = null;
  		var str = '';
  		if (j == 0) {
  			switch (i) {
			case 0:str = '<td style="width:100px;text-align:center">一层</td>';break;
			case 1:str = '<td style="width:100px;text-align:center">二层</td>';break;
			case 2:str = '<td style="width:100px;text-align:center">三层</td>';break;
			case 3:str = '<td style="width:100px;text-align:center">四层</td>';break;
			case 4:str = '<td style="width:100px;text-align:center">五层</td>';break;
			case 5:str = '<td style="width:100px;text-align:center">六层</td>';break;
			case 6:str = '<td style="width:100px;text-align:center">七层</td>';break;
			case 7:str = '<td style="width:100px;text-align:center">八层</td>';break;
			}
  			td = $(str);
  			td.appendTo(tr);
  		} else if (j == 1) {
  			td=$('<td style="width:100px;text-align:center"><select id="templateName'+i+j+'" name="templateName'+i+j+'"></select></td>');
  			td.appendTo(tr);
  	  		for (var m = 0;m < nameArray.length;m++) {
  	  			if (nameArray[m] != null && nameArray[m] != '') {
	  	  			var roleId = nameArray[m].split(':')[0];
	  	  			var roleName = nameArray[m].split(':')[1];
	  	  			$('<option value="'+ roleId +'">'+ roleName +'</option>').appendTo($('#templateName'+i+j));
  	  			}
  	  		}
  		} else {
  			if (((parseInt(count) + parseInt(2)) - (parseInt(i) + parseInt(j))) > 0) {
  				td=$('<td style="width:100px;text-align:center"><input style="width:50px;text-align:center" type="text" name="flow'+ i+j +'" value="" datatype="*"  /></td>');
  			} else {
  				td=$('<td style="width:100px;text-align:center"><input style="width:50px;text-align:center" type="text" value="0" readonly="readonly" name="flow'+ i+j +'" /></td>');
  			}
            td.appendTo(tr);
  		}
  	}
</script>
</body>
</html>