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

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<section class="content-header">
		<h1>
			<small><a class="btn btn-primary opr" opr="new">新增分类</a></small>
		</h1>
		<ol class="breadcrumb">
		  <li><a href="/admin/version"><i class="fa fa-dashboard"></i>抽取版本</a></li>
		  <li class="active"><a href="/admin/version/blockinfo?vid={{.vid}}">分块配置</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="dataTable" class="table table-striped table-bordered table-hover">
		              <thead>
		              <tr>
						<th>信息类型（二级分类）</th>
						<th>时间</th>
						<th>操作</th>
		              </tr>
		              </thead>
		            </table>
		        </div>
	          <!-- /.box-body -->
	        </div>
        <!-- /.box -->
		</div>
	</div>
  </section>
</div>
	
<!-- footer -->
{{template "dialog"}}
{{template "footer"}}
<script>
menuActive("version")
$(function () {
	ttable=$('#dataTable').DataTable({
		"ordering"    : false,
		"paging"      : false,
		"lengthChange": false,
		"searching"   : false,
		"info"        : true,
		"autoWidth"   : false,
		"language": {
            "url": "/res/dist/js/dataTables.chinese.lang"
        },
		"ajax": {
			"url": "/admin/version/blockclassify_list",
			"type": "post",
			"data":{"vid":{{.vid}}}
		},
		"columns": [
			{"data": "name","width":"50%",render:function(val,a,row){
				return '<a href="/admin/version/blockclassify_info?pid='+row["_id"]+'&vid={{.vid}}">'+val+'</a>';
			}},
			{"data": "l_updatetime","width":"25%"},
			{"data":"_id","width":"20%",render:function(val,a,row){
				return '<a class="btn btn-sm btn-primary opr" opr="edit">编辑</a>&nbsp;<a class="btn btn-sm btn-danger" href="#" onclick="del(\''+val+'\')">删除</a>';
			}}
       	]
	});
	ttable.on('init.dt', function () {
		$(".opr").click(function(){
			var n=$(this).attr("opr")
			var _tit="",htmlObj={},obj,tag=[]
			switch(n){
			case "classify":
				window.location.href = "/admin/version/blockclassify?vid={{.vid}}";
				break
			case "edit":	
                obj=ttable.row($(this).closest("tr")).data();
			case "new":
                tag=[
						{label:"名称",s_label:"name",type:"tpl_input",placeholder:"分类名称，多个逗号隔开",must:true},
                        {s_label:"_id",type:"tpl_hidden"},
					]
				
				if(n=="new"){
					_tit="新增分类"
					obj={}
				}else{
					_tit="编辑分类"
				}
				htmlObj={
					title:_tit,
					tag:tag,
					bts:[
						{label:"保存",class:"btn-primary",
							fun:function(){
								var name = $.trim($("#name").val());
								var bcon=true;
								if(name==""){
									bcon=false;
								}
								if (bcon){
									var obj={
										_id:$("#_id").val(),
										name:name,
										vid:{{.vid}}
									}
                                    //console.log(obj)							
									$.post("/admin/version/blockclassify_save",obj,function(data){
										if(data.status){
											window.location.href="/admin/version/blockclassify?vid={{.vid}}";	
										}else{
											showTip("保存失败！",1000)
										}
									},'json')
								}else{
									alert("红色标签的表单不能为空！")
								}
							}
						}
					]
				}
			OpenDialog(htmlObj,obj)
			break;
			}
		});
	});
})
function del(_id){
	showConfirm("确定删除?", function() {
		$.ajax({
			url:"/admin/version/blockclassify_delete",
			type:"post",
			data:{"_id":_id},
			success:function(r){
				if(r.status){				
					ttable.ajax.reload();
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}
</script>