{{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 class="active"><a href="/admin/versionclear"><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="dataTable" class="table table-bordered table-hover">
		              <thead>
		              <tr>
		                <th>版本号</th>
						<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("versionclear")
$(function () {
	ttable=$('#dataTable').DataTable({
		"paging"      : false,
		"lengthChange": false,
		"searching"   : true,
		"ordering"    : false,
		"info"        : true,
		"autoWidth"   : false,
		"ajax": {
			"url": "/admin/clearversion/data",
			"type": "post",
			"data":{}
		},
		"language": {
            "url": "/res/dist/js/dataTables.chinese.lang"
        },
		"columns": [
            { "data": "clearversion"},
			{ "data": "s_username"},
			{ "data": "s_descript","width":"25%"},
			{ "data": "isuse",render:function(val,a,row){
				tmp=""
				if(val){
					tmp="<a href='#' title='停用' onclick='use(\""+row._id+"\","+false+")'><i class='fa fa-fw fa-circle text-green'></i></a>已启用"
				}else{
					tmp="<a href='#' title='启用' onclick='use(\""+row._id+"\","+true+")'><i class='fa fa-fw fa-circle text-red'></i></a>未启用"
				}
				return tmp
			}},
			{ "data":"_id",render:function(val,a,row){
				return '<div class="btn-group">'+
						'<a class="btn btn-sm btn-success" href="/admin/clearversion/info?vid='+val+'" >属性配置</a>'+
					'</div>';
			}},
			{ "data":"_id","width":"25%",render:function(val,a,row){
				return '<div class="btn-group">'+
						//'<a class="btn btn-sm btn-success" href="/admin/version/info?vid='+val+'" >属性配置</a>'+
						//'<a class="btn btn-sm btn-info" href="/admin/version/pkginfo?vid='+val+'" >分包配置</a>'+
						'<a class="btn btn-sm btn-primary opr" opr="edit">编&nbsp;&nbsp;辑</a>'+
						'<a class="btn btn-sm btn-danger" href="#" onclick="del(\''+val+'\',\''+row["clearversion"]+'\')">删&nbsp;&nbsp;除</a>'
					'</div>';
			}}
       	]
	});
	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:"clearversion",placeholder:"版本名称",must:true},
					{label:"描述",s_label:"s_descript",placeholder:"描述信息",must:true},
					//{label:"城市抽取",s_label:"isextractcity",type:"tpl_list_local",list:[{"s_name":"是","_id":true},{"s_name":"否","_id":false}],default:false},
					{label:"克隆版本",s_label:"s_pversionid",type:"tpl_list_local",url:"/admin/getclearversions"},
					//{label:"克隆属性",s_label:"iscopyfiled",type:"tpl_list_local",list:[{"s_name":"是","_id":true},{"s_name":"否","_id":false}],default:false},
					{s_label:"isuse",type:"tpl_hidden"},
					{s_label:"_id",type:"tpl_hidden"}
				]
				if(n == "new"){
					_tit="新增清理版本";
				}else{
					_tit="编辑版本";
					tag[0]={label:"版本名称",s_label:"clearversion",placeholder:"版本名称",must:true,disabled:true}
				}
				htmlObj={
					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();
									obj[el.id]=$(el).val()
									if(el.id!="_id"&&$(el).attr("must")&&!val){
										bcon=false
										return false
									}
								})
								if (bcon){	
									if(obj.isuse != "true"){
										obj.isuse = false
									}
									$.post("/admin/clearversion/save",obj,function(data){
										if(data&&data.rep){
											window.location.href="/admin/versionclear"			
										}else{
											showTip("已存在！",1000)
										}
									},'json')
								}else{
									alert("红色标签的表单不能为空！")
								}
							}
						}
					]
				}
			OpenDialog(htmlObj,obj)
			break;
			}
		});
	})
})
function use(_id,isuse){
	smg=""
	if(isuse){
		smg="确定启用？"
	}else{
		smg="确定停用？"
	}
	showConfirm(smg, function() {
		$.ajax({
			url:"/admin/clearversion/use",
			type:"post",
			data:{"_id":_id,"isuse":isuse},
			success:function(r){
				if(r.rep){				
					window.location.href="/admin/versionclear"	
				}else{
					showTip("启用失败", 1000, function() {});
				}
			}
		})
	});
}
function del(_id,clearversion){
	showConfirm("确定删除?", function() {
		$.ajax({
			url:"/admin/clearversion/del",
			type:"post",
			data:{"_id":_id,"clearversion":clearversion},
			success:function(r){
				if(r.rep){				
					window.location.href="/admin/versionclear"
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}
</script>
