{{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/versionclear"><i class="fa fa-dashboard"></i>清理版本</a></li>
		  <li class="active"><a href="/admin/clearversion/info?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-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,
		"language": {
            "url": "/res/dist/js/dataTables.chinese.lang"
        },
		"ajax": {
			"url": "/admin/clearversion/infodata",
			"type": "post",
			"data":{"vid":{{ .vid}} }
		 },
		"columns": [
			{ "data": "s_field"},
			{ "data": "s_descrip"},
			{ "data": "s_username"},
			{ "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 '<a class="btn btn-sm btn-success" href="/admin/clearulelogic?vid={{.vid}}&pid='+val+'">配置逻辑</a>'
			}},
			{"data":"_id",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:"s_field",type:"tpl_list_local",url:"/admin/getfields",must:true},
						{label:"描述",s_label:"s_descrip",placeholder:"描述信息"},
						//{label:"是否审核",s_label:"isaudit",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"},
                        {s_label:"_id",type:"tpl_hidden"},
						{s_label:"vid",type:"tpl_hidden"},
						{s_label:"isuse",type:"tpl_hidden"},
					]
				if(n=="edit"){
					_tit="编辑-"+obj.s_field
                    tag[0]={label:"属性名称",s_label:"s_field",type:"tpl_list_local",url:"/admin/getfields",must:true,disabled:true}
                    tag[2]={label:"克隆版本",s_label:"s_pversionid",type:"tpl_list_local",url:"/admin/getclearversions",disabled:true}
				}else{
					_tit="新增清理字段"
					obj={"vid":"{{.vid}}","isuse":false}
				}
				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){	
                                    //console.log(obj)							
									$.post("/admin/clearversion/infosave",obj,function(data){
										if(data&&data.rep){
											window.location.href="/admin/clearversion/info?vid={{.vid}}"			
										}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/infouse",
			type:"post",
			data:{"_id":_id,"isuse":isuse},
			success:function(r){
				if(r.rep){				
					window.location.href="/admin/clearversion/info?vid={{.vid}}"
				}else{
					showTip("启用失败", 1000, function() {});
				}
			}
		})
	});
}
function del(_id){
	showConfirm("确定删除?", function() {
		$.ajax({
			url:"/admin/clearversion/infodel",
			type:"post",
			data:{"_id":_id},
			success:function(r){
				if(r.rep){				
					ttable.ajax.reload();
				}else{
					showTip("删除失败", 1000, function() {});
				}
			}
		})
	});
}
</script>
