	var token = $.cookie("token");
	var id = ''; //当前节点id
	var name; //当前节点name
	var pid; //当前节点父ID
	var pidName; //当前节点父name
	var Level; //判断父节点
	var id; //一级ID
	//数据字典树形图
	trees();
	var tree;

	function trees() {
		$.get(huayi.config.callcenter_url + 'Dictionary/GetZTreeList', {
			"token": $.cookie("token"),
			//		"pid": pid
		}, function(result) {
			result = $.parseJSON(result);
			tree = $.fn.zTree.init($("#treeDemo"), setting1, result.data); //实例化树形图
			console.log(result.data);
		});
	}
	var setting1 = {

		callback: {
			onClick: zTreeOnClick
		}
	};

	function zTreeOnClick(event, treeId, treeNode) {
		//		pid = treeNode.pId;
		id = treeNode.id;
		name = treeNode.name;
		Level = treeNode.level;
		console.log(Level);
		$(".Pids").val(id);
		if(Level == 0) {
			GetDic(id);
		} else {
			GetDicValue(id);
		}
	};

	///  获取一级信息
	function GetDic(a) {
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "Dictionary/GetDic?", //				contentType:'
			dataType: "json",
			data: {
				id: a,
				token: token
			},
			success: function(data) {
				var content = data.data;
				$(".inps4").val(content.F_ItemName);
			}

		});
	}
	//获取一级一下信息
	function GetDicValue(b) {
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "Dictionary/GetDicValue?", //				contentType:'
			dataType: "json",
			data: {
				id: b,
				token: token
			},
			success: function(data) {
				var content = data.data;
				$(".inps4").val(content.F_Value);
				$(".iid").val(content.F_ItemId);
				$(".pid").val(content.F_PrentId);
				$(".iids").val(content.F_ItemId);
				$(".pids").val(content.F_ValueId);
			}

		});
	}
	//====================添加功能开始=============================
	$('.tjzd').click(function() {
		$('.addModel').css('display', 'block');
	})
	//关闭按钮
	$('.addBtr ').click(function() {
		$('.addModel').css('display', 'none');
		$('.addMode').css('display', 'none');
	})
	//保存按钮
	$('.addCunzd').click(function() {
		$('.addModel').css('display', 'none');

		if($('.inps1').val() == '') {
			layer.confirm('字典项名称不允许为空！', {
				btn: ['确定']
			});
			return;
		} else {
			AddDic($('.inps1').val());
		};
	});
//	$('.addCunzds').click(function() {
//		$('.addMode').css('display', 'none');
//			var nodes = tree.getSelectedNodes();
//			if(nodes.length != 1) {
//				layer.confirm('请选择一条记录！', {
//					btn: ['确定']
//				});
//				return;
//			} else {
//				var iid = 0;
//				var pid = 0;
//				var node = nodes[0];
//				if(node.level == 0) {
//					iid = node.id;
//				} else {
//					pid = node.id;
//				}
//				AddDicValue($('.idss').val(), $('.inps5').val(), iid, pid)
//			}
//
//
//	})

	//关闭按钮
	$('.delBtr').click(function() {
		$('.delModel').css('display', 'none');
	})
	//取消按钮
	$('.return').click(function() {
		$('.delModel').css('display', 'none');
	})

	//=====================字典修改功能开始==================================
	//关闭按钮
	$('.changeBtr').click(function() {
		$('.changeModel').css('display', 'none');
	})
	//保存按钮
	$('.chanCun').click(function() {
		$('.changeModel').hide();
		if(Level == 0) {
			if($('.inps4').val() == '') {
				layer.confirm('字典项名称不允许为空！', {
					btn: ['确定']
				});
				return;
			} else {
				AddDics($(".Pids").val(), $('.inps4').val());
			}
		} else {
			if($('.inps4').val() == '') {
				layer.confirm('字典项名称不允许为空！', {
					btn: ['确定']
				});
				return;
			} else {
				AddDicValue($(".Pids").val(), $('.inps4').val(), $(".iid").val(), $(".pid").val());
			}
		}

	});
	///编辑一级
	function AddDics(ids, names) {
		$.ajax({
			type: "post",
			url: huayi.config.callcenter_url + "Dictionary/AddDic",
			async: true,
			dataType: 'json',
			data: {
				id: ids,
				name: names,
				token: token
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					layer.msg("修改成功!");
					trees();
					location=location
				}
			}
		});

	}
	//增加一级
	function AddDic(Names) {
		$.ajax({
			type: "post",
			url: huayi.config.callcenter_url + "Dictionary/AddDic",
			async: true,
			dataType: 'json',
			data: {
				name: Names,
				token: token
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					layer.msg("添加成功!");
					trees();
					location=location
				} else {
					layer.msg(data.message);

				}
			}
		});

	}
	//========================字典列表添加功能开始==================================
	$('.zdl_add').click(function() {

		$(".addModel").show();
	})
	$('.zdl_adds').click(function() {
		var nodes = tree.getSelectedNodes();
			if(nodes.length != 1) {
				layer.confirm('请选择一条记录！', {
					btn: ['确定']
				});
				return;
			}else{
				$(".addMode").show();
				$('.addCunzds').click(function(){
					var iid = 0;
				var pid = 0;
				var node = nodes[0];
				if(node.level == 0) {
					iid = node.id;
				} else {
					pid = node.id;
				}
				AddDicValue($('.idss').val(), $('.inps5').val(), iid, pid)
				})
			}
	})

	//关闭按钮
	$('.addListBtr').click(function() {
		$('.zdlist_addModel').css('display', 'none');
	})
	//保存按钮
	$('.addList_cun').click(function() {
		$('.zdlist_addModel').css('display', 'none');
		addList();
	})

	//************************字典列表添加功能结束==================================

	//========================字典列表修改功能开始==================================

	$('.zdl_change').click(function() {
		if($(".Pids").val()){
			$(".changeModel").show();
		}else{
			layer.msg('请选择一条数据修改')
		}
		

	})

	
	//************************字典列表修改功能结束==================================

	//========================字典列表删除功能开始==================================
	$('.zdl_del').click(function() {
		if(Level == 0) {
			if($('.Pids').val() == '') {
				layer.confirm('没有删除的选项！', {
					btn: ['确定']
				});
				return;
			} else {
				layer.confirm('确定要删除吗',{
					btn:['确定','取消']
				},function(){
					var aa = $.fn.zTree.getZTreeObj("treeDemo").getSelectedNodes();
					var Arr = [];
					Arr.push(aa[0].id)
					DelDic(Arr);
				})
				
			}
		} else {
			if($('.Pids').val() == '') {
				layer.confirm('没有删除的选项！', {
					btn: ['确定']
				});
				return;
			} else {
				layer.confirm('确定要删除吗',{
					btn:['确定','取消']
				},function(){
					var aa = $.fn.zTree.getZTreeObj("treeDemo").getSelectedNodes();
					var Arr = [];
					Arr.push(aa[0].id)
					DelDicValue(Arr);
				})
				
			}

		}

	})
	//删除一级
	function DelDic(ids) {
		$.ajax({
			type: "post",
			url: huayi.config.callcenter_url + "Dictionary/DelDic",
			async: true,
			dataType: 'json',
			data: {
				ids: ids,
				token: token
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					layer.msg("删除成功!");
					trees();
				} else {
					layer.msg(data.message);
				}
			}
		});
	}
	//删除一级以下
	function DelDicValue(ids) {
		$.ajax({
			type: "post",
			url: huayi.config.callcenter_url + "Dictionary/DelDicValue",
			async: true,
			dataType: 'json',
			data: {
				ids: ids,
				token: token
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					layer.msg("删除成功!");
					trees();
				} else {
					layer.msg(data.message);

				}
			}
		});
	}
	//修改一级一下菜单
	function AddDicValue(ids, Names, iids, pids) {
		$.ajax({
			type: "post",
			url: huayi.config.callcenter_url + "Dictionary/AddDicValue",
			async: true,
			dataType: 'json',
			data: {
				id: ids,
				name: Names,
				iid: iids,
				pid: pids,
				token: token
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					layer.msg("成功!");
					location=location
					$(".addMode").hide();
					$(".inps5").val('');
					trees();
				} else {
					layer.msg("失败！");

				}
			}
		});

	}