{{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>
						<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_info_list",
			"type": "post",
			"data":{"pid":{{.pid}}}
		},
		"columns": [
			{"width":"10%",render:function(val,a,row){
				return '';
			}},
			{"data": "name","width":"30%",render:function(val,a,row){
				return '<a href="/admin/version/blockclassify_tag?pid='+row["_id"]+'&vid={{.vid}}">'+val+'</a>';
			}},
			{"data": "code","width":"25%"},
			{"data": "l_updatetime","width":"15%"},
			{"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 "edit":	
                obj=ttable.row($(this).closest("tr")).data();
			case "new":
                tag=[
						{label:"分类名称",s_label:"name",type:"tpl_input",placeholder:"分类名称",must:true},
						{label:"分类代码",s_label:"code",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 code = $.trim($("#code").val());
								var bcon=true;
								if(name==""||code==""){
									bcon=false;
								}
								if (bcon){
									var obj={
										_id:$("#_id").val(),
										name:name,
										code:code,
										vid:{{.vid}},
										pid:{{.pid}}
									}
                                    //console.log(obj)							
									$.post("/admin/version/blockclassify_info_save",obj,function(data){
										if(data.status==1){
											window.location.reload();
										}else if (data.status==-1){
											showTip("已存在！",1000)
										}else{
											showTip("保存失败！",1000)
										}
									},'json')
								}else{
									alert("红色标签的表单不能为空！")
								}
							}
						}
					]
				}
			OpenDialog(htmlObj,obj)
			break;
			}
		});
		ttable.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
	});
})
function del(_id){
	showConfirm("确定删除?", function() {
		$.ajax({
			url:"/admin/version/blockclassify_info_delete",
			type:"post",
			data:{"_id":_id},
			success:function(r){
				if(r.status){				
					window.location.reload();
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}
</script>