{{template "inc"}}
<!-- Main Header -->
{{template "header"}}
<!-- Left side column. 权限菜单 -->
{{template "memu"}}

<div class="content-wrapper" id="showbtn">
	<section class="content-header">
		<h1>
			<small><a class="btn btn-primary opr" opr="new">新增识别字段</a></small>
		</h1>
		<ol class="breadcrumb">
		  <li><a href="/admin/audit/recogfield"><i class="fa fa-dashboard"></i> 识别字段</a></li>		  
		</ol>
    </section>
  <!-- Main content -->
  <section class="content">
      <div class="row">
	      <div class="col-xs-12">
	        <div class="box">
		        <div class="box-body">
		            <table id="recogfieldTable" class="table table-bordered table-hover">
		              <thead>
		              <tr>
		                <th>名称</th>
						<th>识别字段</th>
						<th>时间</th>
						<th>创建人</th>
						<th>操作</th>
		              </tr>
		              </thead>
		            </table>
		        </div>
	          <!-- /.box-body -->
	        </div>
        <!-- /.box -->
		</div>
	</div>
  </section>
</div>

{{template "dialog"}}
{{template "footer"}}
<script>
menuActive("recogfield")
$(function () {
	ttablerecogfield=$('#recogfieldTable').DataTable({
		"paging"      : true,
		"lengthChange": false,
		"searching"   : true,
		"ordering"    : false,
		"info"        : true,
		"autoWidth"   : false,
		"ajax": {
			"url": "/admin/rulemanager/getrecogfield",
			"type": "post",
			"data":{}
		},
		"language": {
            "url": "/res/dist/js/dataTables.chinese.lang"
        },
		"columns": [
            { "data": "s_name"},
			{ "data": "s_recogfield"},
			{ "data": "l_createtime"},
			{ "data": "s_user"},
			{ "data": "_id",render:function(val,a,row){
				return '<a class="btn btn-sm btn-info opr" opr="edit">编辑</a>'+
					'&nbsp;&nbsp;<a class="btn btn-sm btn-warning" href="/admin/rulemanager/getclasslist?id='+val+'&fname='+row["s_recogfield"]+'">编辑分类</a>'+
					'&nbsp;&nbsp;<a class="btn btn-sm btn-success" href="/admin/audit/dataaudit?name='+row["s_recogfield"]+'">数据审核</a>'+
					'&nbsp;&nbsp;<a class="btn btn-sm btn-danger" onclick="del(\''+val+'\')">删除</a>'
			}}
       	]
	});
	ttablerecogfield.on('init.dt', function () {
		$("#showbtn").on('click','a.opr',function(){
			var n=$(this).attr("opr");
			var _tit="",htmlObj={},obj,tag=[];
			//var delid=$(this).attr("value");
			switch(n){
			case "edit":
				obj=ttablerecogfield.row($(this).closest("tr")).data();
			case "new":
				tag=[
					{label:"名称",s_label:"s_name",must:true},
					{label:"识别字段",s_label:"s_recogfield",must:true},
					{label:"前置过滤",s_label:"s_recogfield_prerule",type:"tpl_text"},
					{s_label:"_id",type:"tpl_hidden"},
				]
				if(n == "new"){
					_tit="新增识别字段";
				}else{
					_tit="编辑_"+obj.s_recogfield+"字段";
					//tag[1]= {label:"识别字段",s_label:"s_recogfield",must:true,disabled:true}
				}
				htmlObj={
					mutilfield:"s_pid",
					title:_tit,
					tag:tag,
					bts:[
						{label:"保存",class:"btn-primary",
							fun:function(){
								var obj={}
								var bcon=true
								$("#_con").find("input[id!=s_show],textarea").each(function(i,el){
									var val=$(el).val();
									if(el.id!="_id"&&$(el).attr("must")&&!val){
										bcon=false
										return false
									}
									obj[el.id]=$(el).val();
								})
								if (bcon){								
									$.post("/admin/rulemanager/saverecogfield",obj,function(data){
										if(data&&data.rep){
											window.location.href="/admin/audit/recogfield"	
										}else{
											showTip(data.msg,1000)
										}
									},'json')
								}else{
									alert("红色标签的表单不能为空！")
								}
							}
						}
					]
				}
				OpenDialog(htmlObj,obj)
				break;
			}
			
			//var multiclass = $("#_con >div:nth-child(3) input").val();
			//if(multiclass == "是"){//多分类 显示覆盖追加
			//	$("#_con >div:nth-child(4)").removeClass("hide");
			//	//$("#con >div:nth-child(10) input").addAttr("must",true);
			//}else{//不是多分类 隐藏覆盖追加
			//	$("#_con >div:nth-child(4)").addClass("hide");
			//}
			
			//$("#_con [id=u_list]:eq(0) li").click(function(){
			//	var content = $(this).text();
			//	if(content == "是"){
			//		$("#_con >div:nth-child(4)").removeClass("hide");
			//	}else if(content == "否"){
			//		$("#_con >div:nth-child(4)").addClass("hide");
			//	}
			//})
		});
	})
})

function del(_id){
	showConfirm("确定删除？", function() {
		$.ajax({
			url:"/admin/rulemanager/delrecogfield",
			type:"post",
			data:{"_id":_id},
			success:function(r){
				if(r.rep){				
					window.location.href="/admin/audit/recogfield";
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}

</script>
