<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="admin/common/html/head :: head_Normal(~{::title},~{::link},~{::style})">

<title th:text=${title}></title>
<!-- 这儿引用单独的css link -->
<!-- Ladda for Bootstrap 3按钮加载进度插件 -->
<link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">
<!-- bootstrap-table表单样式 -->
<link th:href="@{/static/admin/assets/js/bootstrap/css/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>

<!-- jquery向导插件stepy -->
<link th:href="@{/static/admin/assets/js/wizard/css/jquery.steps.css}" rel="stylesheet"/>

<style type="text/css">
/**
*这里写单独的css样式
*/

</style>

</head>

<body id="listbody">




<!-- ###############################代码编写处############################### -->

<!-- 右边内容 -->
<div class="wrap-fluid">
    <div class="container-fluid paper-wrap bevel tlbr">
        <!-- 内容 -->
        <!--标题 通用-->
        <div th:replace="admin/common/html/title :: title(${title},${parenttitle},${isMsg},${msgHTML})">
        </div>
        <!-- 结束标题 通用-->
        <div class="content-wrap">
            <!-- 结束内容 -->
            <div class="row">
                <div class="row">
                	
                	<!-- 自动代码生成填写 -->
                	<div class="col-sm-6">
                		
                		<div class="nest">
						    <div class="nest" id="basicClose">
						        <div class="title-alt">
						            <h6>单表生成Ⅰ</h6>
						            <div class="titleClose">
						                <a class="gone" href="#basicClose">
						                    <span class="entypo-cancel"></span>
						                </a>
						            </div>
						            <div class="titleToggle">
						                <a class="nav-toggle-alt" href="#basic">
						                    <span class="entypo-up-open"></span>
						                </a>
						            </div>
						
						        </div>
						
						        <div class="body-nest" id="basic">
									<form class="form-horizontal bucket-form">
	                                    <div class="form-group">
	                                        <label class="col-sm-2 control-label">选择表</label>
	                                        <div class="col-sm-4">
	                                            <select  id="typeId" class="form-control" name="typeId">
													 <option value="-1">请选择</option>
												     <option  th:each="table : ${tables}" th:text="${table.tableName}" th:value="${table.tableName}"></option>
												</select>
	                                        </div>
	                                    </div>
	                                    <div class="form-group">
	                                        <label class="col-sm-2 control-label">表注释</label>
	                                        <div class="col-sm-4">
	                                            <input  class="form-control" id="tableComment" value="">
	                                        </div>
		                               </div>
		                               <div class="form-group">
	                                        <label class="col-sm-2 control-label">表model名称</label>
	                                        <div class="col-sm-4">
	                                            <input  class="form-control" id="tableModel" value="">
	                                        </div>
		                               </div>
		                               
	                                </form>
	                             
						        </div>
						    </div>
						</div>
                		
                		
                	</div>
                	<div  class="col-sm-6">
                		
                		
                		<div class="nest" id="basicClose2">
						        <div class="title-alt">
						            <h6>单表生成Ⅱ</h6>
						            <div class="titleClose">
						                <a class="gone" href="#basicClose2">
						                    <span class="entypo-cancel"></span>
						                </a>
						            </div>
						            <div class="titleToggle">
						                <a class="nav-toggle-alt" href="#basic2">
						                    <span class="entypo-up-open"></span>
						                </a>
						            </div>
						
						        </div>
						
						        <div class="body-nest" id="basic2">
									<form method="post" class="form-horizontal bucket-form">
	                                   
		                               <div class="form-group">
	                                        <label class="col-sm-2 control-label">条件查询字段</label>
	                                        <div class="col-sm-8">
		                                        <div class="row">
		                                        	<div class="col-sm-6">
			                                        	 <select  id="conditionQueryField" class="form-control" name="conditionQueryField">
													     	<option value=""></option>
														 </select>
		                                        	</div>
		                                        	<div class="col-sm-6">
		                                        		<div class="alert-warning form-control">
						                                	<button data-dismiss="alert" class="close" type="button">×</button>
						                                    <span class="fa fa-hand-o-left"></span>
						                                  		html页面查询字段
						                                </div>
		                                        	</div>
		                                        </div>
	                                           
	                                        </div>
		                               </div>
		                               <div class="form-group">
	                                        <label class="col-sm-2 control-label">父菜单</label>
	                                        <div class="col-sm-8">
	                                        	<div class="row">
	                                        		<div class="col-sm-6">
	                                        			<select  id="menuid" class="form-control" name="menuid">
			                                             	<option></option>
														</select>
	                                        		</div>
	                                        		
	                                        		<div class="col-sm-6">
	                                        			<div class="alert-warning form-control">
						                                	<button data-dismiss="alert" class="close" type="button">×</button>
						                                    <span class="fa fa-hand-o-left"></span>
						                                  		选择⚪⚪的父菜单
						                                </div>
	                                        		</div>
	                                        	</div>
	                                            
												
	                                        </div>
		                               </div>
		                               <div class="form-group">
	                                        <label class="col-sm-2 control-label">sql自动录入</label>
	                                        <div class="col-sm-8">
	                                        	<div class="row">
	                                        		<div class="col-sm-4">
		                                        	  	<select  id="sql" class="form-control" name="sql">
													    	<option value="-1">不录入</option>
													    	<option value="1">录入</option>
														</select>
		                                        	</div>
		                                        	<div class="col-sm-8">
		                                        		<div class="alert-warning form-control">
						                                    <button data-dismiss="alert" class="close" type="button">×</button>
						                                    <span class="fa fa-hand-o-left"></span>
						                                  		第一次选择录入，第二次不录入防止冲突
						                                </div>
		                                        	</div>
	                                        	</div>
	                                        </div>
		                               </div>
	                                </form>
	                             
						        </div>
						    </div>
						</div>
                		
                		
                		
                		
                	</div>
					
                
                
               	 
                	<!-- END自动代码生成填写 -->
                	
                	
                    <!-- 空白页开始-->
                    <div class="nest" id="Blank_PageClose">
                        <div class="title-alt">
                            <h6>表单</h6>
                            <div class="titleClose">
                                <a class="gone" href="#Blank_PageClose">
                                    <span class="entypo-cancel"></span>
                                </a>
                            </div>
                            <div class="titleToggle">
                                <a class="nav-toggle-alt" href="#Blank_Page_Content">
                                    <span class="entypo-up-open"></span>
                                </a>
                            </div>
                        </div>
                        
                        <div class="body-nest" id="Blank_Page_Content">
                            <!-- 工具条 -->
                            <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                               <button  onclick="divonclick();" type="button" class="btn btn-primary">
                                    <span class="entypo-plus-squared"></span>&nbsp;&nbsp;生成
                                </button>
                               
                           </div>
                            <!-- 工具条 end-->
                           <table id="dataTable" class="table-striped footable-res footable metro-blue" data-page-size="6">
                                   
                                    
                           </table>
                           
                           
                        </div>
                    </div>
                </div>
                <!-- 空白页结束 -->
            </div>
            <!-- 结束内容 -->
        </div>
    </div>
</div>
<!-- 结束右边内容 -->
<!-- ###############################代码编写处end############################### -->







<!-- 右侧隐藏滑块内容 -->
<div th:include="admin/common/html/rightHide :: rightHide">
    
</div>
   <!-- END 右侧隐藏滑块内容-->

<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">
   
</div>
<!-- bootstarp 表格 -->
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/base_list.js}" type="text/javascript"></script>
<!-- 导出 -->
<script th:src="@{/static/admin/assets/js/bootstrap/extensions/export/bootstrap-table-export.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/extensions/export/tableExport.js}" type="text/javascript"></script>

<!-- 弹窗 -->
<script th:src="@{/static/admin/assets/js/layer/layer.js}" type="text/javascript"></script>
<!-- 遮罩层 -->
<script th:src="@{/static/admin/assets/js/blockUI/jquery.blockUI.js}" type="text/javascript"></script>
<!-- jquery向导插件stepy -->
<script type="text/javascript" th:src="@{/static/admin/assets/js/wizard/build/jquery.steps.js}"></script>
<!-- 提示插件  -->
<script type="text/javascript" th:src="@{/static/admin/assets/js/tip/jquery.tooltipster.js}"></script>

<script type="text/javascript">
<!-- jquery-export 表格导出插件 -->

<!-- 导出 -->
var dataUrl11=window.rootPath+"/autoCodeController/queryTableInfo";
var removeUrl=window.rootPath+"/generatorController/remove";
var createUrl=window.rootPath+"/generatorController/add";
var updateUrl=window.rootPath+"/generatorController/edit/{id}";
var exportUrl=window.rootPath+"/generatorController/export";
var createUrl=window.rootPath+"/generatorController/code";


	
	var $dataTableHot = $("#dataTable").bootstrapTable({
            search: false,
            pagination: true,
            toolbar: '#exampleTableEventsToolbar',     
            pageSize: 15,
            pageList: [5, 10, 15, 20],
            showColumns: true,
            showRefresh: false,
            locale: "zh-CN",
            striped: true,
            toggle:true,
            columns:[
    			{
    			    checkbox: true
    			},                   
    			{
    				title: '字段名',
    				field: 'column_name'
    			},
    			{
    				title: '实体名称(可修改)',
    				field: 'beanName'
    			},
    			{
    				title: '数据库类型',
    				field: 'data_type'
    			},
    			{
    				title: '实体名称',
    				field: 'beanType'
    			},
    			{
    				title: '长度',
    				field: 'character_maximum_length'
    			},
    			{
    				title: '主键',
    				field: 'column_key',
    				formatter: function (value, row, index) {
    			        var id = row.column_key;
    			       if("PRI"==id){
    			    	   return "YES";
    			       }
    			       
    			       return "NO";
    				}
    			},
    			{
    				title: '是否自增',
    				field: 'extra',
    				formatter: function (value, row, index) {
    			        var id = row.extra;
    			       if(id.indexOf("auto_increment")!=-1){
    			    	   return "YES";
    			       }
    			       return "NO";
    			    }
    			},
    			{
    				title: '是否可为空',
    				field: 'is_nullable',
    				formatter: function (value, row, index) {
    			        var id = row.is_nullable;
    			       return id;
    			    }
    			},
    			{
    				title: '默认值',
    				field: 'column_default'
    			},
    			{
    				title: '备注(可修改)',
    				field: 'column_comment'
    			}],
    			 onDblClickCell : function(field,value,row,$element){
    				 $element.attr('contenteditable', true);
    		            $element.blur(function() {
    		                let index = $element.parent().data('index');
    		                let tdValue = $element.html();

    		                $dataTableHot.bootstrapTable('updateCell', {
    		                    index: index,       //行索引
    		                    field: field,       //列名
    		                    value: tdValue        //cell值
    		                })
    		            })
    			 }
        });
	
  
  
//列表
/* var oTab=$.table.oTableInit(options);
oTab.Init(); */
$(function(){
	
	$("#typeId").change(function() {
		var selectval= $(this).val();
		//表注释、表model名称
		$.ajax({
	  		type : "POST",
	  		url : rootPath + "/autoCodeController/queryTable",
	  		data :"tableName="+selectval,
	  		async : false,
			success:function(data){
				if(data.code==200){
					$("#tableComment").val(data.data[0].tableComment);
					$("#tableModel").val(data.data[0].tableModel);
				}
				
			}
		})
		
		//重新加载表格
			 $.ajax({
	            url:dataUrl11,
	            type:"post",
	            data:{"tableName":selectval},
	            dataType:"json",
	            success:function(data){
	            	if(data!=""){
	            		var selecthtml="";
	            		for ( var i in data.data) {
	            			if(data.data[i].column_key!="PRI"){
	            				selecthtml+="<option value=\""+data.data[i].beanName_A+"\">"+data.data[i].column_name+" ("+data.data[i].column_comment+")</option>";
	            			}
	            			
						}
	            		$("#conditionQueryField").html(selecthtml);	
	            	}
	                $('#dataTable').bootstrapTable('load', data.data);
	            },
	            error:function(error){
	                console.log(error);
	            }
	        });
	});
	
	
	$.ajax({
  		type : "POST",
  		url : rootPath + "/PermissionController/list2",
  		async : false,
		success:function(data){
			if(data!=""&&data.length>0){
				var selecthtml="";
				var html=selecton(data,"0","");
				$("#menuid").html(html);
			}
			
		}
	})
	
})

function selecton(data,pid,pidstr){
	var selecthtml="";
	for ( var i in data) {
		var menuid = data[i].id;//获取菜单的id
		var parentid = data[i].pid;//获取菜单的父id
		if(parentid!=null){
			if(parentid==pid){
    			var htmla="<span class=\"label label-important\">"+pidstr+data[i].name+"</span>";
				selecthtml+="<option value=\""+data[i].id+"\">"+htmla+"</option>";
				selecthtml+=selecton(data,menuid,pidstr+" ⚪ ");
			}
		}
	}
	
	return selecthtml;
}

function divonclick(){

	    
	    
		var tableName=$("#typeId").val();
	    if(tableName=="-1"){
	    	return $.modal.alertWarning("选择表");
	    }
	    var conditionQueryField=$("#conditionQueryField").val();
		var allColumnss=JSON.stringify($dataTableHot.bootstrapTable('getSelections'));
		var pid=$("#menuid").val();
		var sql=$("#sql").val();
		
		
		if(sql=="1"){
			var sqlflag=true;
			 $.ajax({
					type : "POST",
			  		url : rootPath + "/autoCodeController/queryLikePerms",
			  		data :{"tableName":tableName},
			  		async : false,
					success:function(data){
						if(data.code==500){
							$.modal.alertWarning(data.msg);
							
						}else{
							sqlflag=false;
						}
						
					}
			 });
			 
			 if(sqlflag){
				 return;
			 }
		}
		
		$.ajax({
			type : "POST",
	  		url : rootPath + "/autoCodeController/saveOne",
	  		data :{"tableName":tableName,"conditionQueryField":conditionQueryField,"pid":pid,"sqlcheck":sql,"allColumnss":allColumnss},
	  		async : false,
			success:function(data){
				$.operate.saveSuccess(data);
			}
		});
		
	}

</script>


<script type="text/javascript">



</script>



</body>


</html>
