
$(document).ready(function () {
	laydate.render({
	    elem: '#starttime' //指定元素
	    ,range:'~'
	});
	getDicValueList($("#source"),1); //工单来源
	getDicValueList($("#type"),2)  //工单类别
	getDicValueList($("#keyid"),3)  //主题词
	helper.getDropList.getOrderAreas($('#sourceAreas'))  //区域
	getMultipleChoice($("#ZX"),"UserAccount/GetSeatList"); //受话坐席
	getMultipleChoice($("#yardman"),"UserAccount/GetUsersList","ZXLD")//审核员
	tree(); 
});
//键盘登录事件
$('input').bind('keypress', function(event) {
	if(event.keyCode == "13") {
		$('.Seach').trigger("click");
	}
});
///搜素
$(".Seach").click(function() {
	load();
})
//承办单位下拉事件开始
$(".inps").focus(function() {
	$(".xlAdd").css("display", "block");
});
$(".xl").click(function() {
	if($(".xlAdd").css("display") == "block") {
		$(".xlAdd").css("display", "none");
	} else {
		$(".xlAdd").css("display", "block");
	}
});
$(".addTree").mouseleave(function() {
	$(this).css("display", "none");
});
//清除
$(".Cleans ").click(function() {
	$(".inps").val("");
	$("#PID").val("");
	$("#Dpment").val("");
});
//承办单位下拉事件结束


//下拉框多选开始
function selectMultiple(obj) {
	var maindeptId = "";
	var maindeptId_ = obj.val(); //坐席
	if(maindeptId_ != null) {
		$(maindeptId_).each(function(i, n) {
			var obj2 = '';
			obj2 = n + ",";
			maindeptId += obj2;
		})
		maindeptId = maindeptId.substring(0, maindeptId.length - 1)
	} else {
		maindeptId = ""
	}
	return maindeptId
}

function getMultipleChoice(obj,urlParame,rolecode) {
	obj.empty();
	var parameData = {
		token: $.cookie("token"),
	}
	if (rolecode) {
		parameData.rolecode = rolecode
	}
	
	$.getJSON(
		huayi.config.callcenter_url + urlParame, parameData,
		function(data) {
			if(data.state.toLowerCase() == "success") {
				var content = data.data;
				$(content).each(function(i, n) {
					$("<option value='" + n.F_UserCode + "'>" + n.F_UserName + "</option>").appendTo(obj);
				});
				obj.selectpicker({ noneSelectedText: "请选择",}); //默认显示内容
				obj.selectpicker("refresh");
			}
		}
	);
}
//下拉框多选结束


//数据字典获取开始
function getDicValueList(obj,id) {
	obj.empty();
	obj.append('<option selected="selected" value="">请选择</option>');
	$.getJSON(
		huayi.config.callcenter_url + "Dictionary/GetDicValueListById", {
			token: $.cookie("token"),
			id: id,
		},
		function(data) {
			if(data.state.toLowerCase() == "success") {
				var content = data.data;
				$(content).each(function(i, n) {
					$("<option value='" + n.F_ValueId + "'>" + n.F_Value + "</option>").appendTo(obj);
				});
			}
		}
	);
}
//数据字典获取结束



//树形下拉开始
function tree() {
	$.get(
		huayi.config.callcenter_url + "Department/GetDeptList", {
			token: $.cookie("token"),
		},
		function(result) {
			result = $.parseJSON(result);
			$.fn.zTree.init( $("#addTreeDemo"),setting1, result.data); //实例化树形图
		}
	);
}
var setting1 = {
	data: {
		key: {
			name: "F_DeptName",
		},
		simpleData: {
			enable: true,
			idKey: "F_DeptId",
			pIdKey: "F_PartentId",
			rootPId: 0,
		},
	},
	callback: {
		onClick: zTreeOnClick,
	},
};

function zTreeOnClick(event, treeId, treeNode) {
	if(treeNode.level >= 1) {
		$(".inps").val(treeNode.F_DeptName);
		$("#PID").val(treeNode.F_DeptId);
		$("#Dpment").val(treeNode.F_DeptId);
		$(".Cleans").show();
	}
}
//树形下拉开始
