$(function(){
	$(".tagModListThis ul>li h3").click(function(){
		$t=$(this).parent();
		if($t.hasClass('on')){
			$t.removeClass('on');
		}else{
			$t.addClass('on');
		}
	});
	$("#close").click(function() {
		$("#keyword").val('');
		$(".first-tagMod").css("display","block");
		$(".searchList").css("display","none");
		$("#close").css("display","none");
		$("#search").css("display","block");
		$(".searchList ul").html('');
	});
});
function add_right(obj,id,pid){
	var check_ids = $("input[name='check_ids[]']");
	var bian = 0;
	for(var i=0;i<check_ids.length;i++){
		var new_id = $(check_ids[i]).val();
		if(id == new_id){
			$(".layui-layer-content").show();
			//定时器
	        setTimeout(function(){
				$(".layui-layer-content").css("display","none");
			},3000);
			bian = 1;return false;
		}
	}
	if(bian == 0){
		$(".second-tagMod ul").append('<li>' + $(obj).html() + '<a class="pull_close" onclick="pull_close(this);"><img src="{$Think.THEME_PATH}common/images/close.png"/></a><input type="hidden" name="check_ids[]" value="'+id+'"/><input type="hidden" name="check_pids[]" value="'+pid+'"/>'+ '</li>');
		$(".tagModListThis ol li").removeClass('on');
		$(obj).addClass('active on').siblings().removeClass('on');
		$(".layui-layer-content").css("display","none");
		var have_count = $("#have_count").val();
		var count = parseInt(have_count) + 1;
		$("#have_count").val(count);
		$("#add_count").html("共"+count+"个字段");
	}
}
function pull_close(obj){
	$(obj).parent().remove();
	var have_count = $("#have_count").val();
	var count = parseInt(have_count) - 1;
	$("#have_count").val(count);
	$("#add_count").html("共"+count+"个字段");
	var html=$(obj).siblings().first().html();
	$(".tagModListThis ol li span").each(function(){
		var left_html=$(this).html();
		if (html==left_html){
			$(this).parent().removeClass('active on');
		}
	});
	$(".searchList ul li span").each(function(){
		var left_html=$(this).html();
		if (html==left_html){
			$(this).parent().removeClass('active on');
		}
	});
}
function add_config(){
	var query=$("form[name='myform']").serialize();
	var url = APP + "Member/update_attribute.html"
	$.ajax({
		url: url,
		data: query,
		type: "post",
		dataType: "json",
		success: function (data) {
			if (data.status==1) {
				$.showSuccess(data.msg);
				return;
			}else{
				$.showError(data.msg);
			}
		}
	});
}
function search(){
	var query = new Object();
	query.keyword = $("#keyword").val();
	if(query.keyword){
		$(".first-tagMod").css("display","none");
		$(".searchList").css("display","block");
		$("#close").css("display","block");
		$("#search").css("display","none");
		var url = APP + "Member/attribute.html"
		$.ajax({
			url: url,
			data: query,
			type: "post",
			dataType: "json",
			success: function (data) {
				if (data.count) {
					var html = '';
					for(var i=0;i<data.count;i++){
						html = html+"<li onclick='add_right(this,"+data.list[i].id+","+data.list[i].pid+")'><span>"+data.list[i].name+"</span></li>";
					}
					$(".searchList ul").append(html);
					$(".errorTip").css("display","none");
				}else{
					$(".errorTip").css("display","block");
				}
			}
		});
	}else{
		$(".first-tagMod").css("display","block");
		$(".searchList").css("display","none");
		$("#close").css("display","none");
		$("#search").css("display","block");
		$(".searchList ul").html('');
	}
}