• zTree


    <script type="text/javascript">

                //控制tab标签切换

                $(function() {
                    $("#divtab").tabs({
                        height: $(window).height() - 60,
                        border: false,
                        plain: true,
                        onSelect: function(title) {
                            if (title == "组织机构") {
                                $("#divTab2").hide();
                                $("#divTab3").hide();
                                $("#divTab1").show();
                            }
                            if (title == "公共组") {
                                $("#divTab1").hide();
                                $("#divTab3").hide();
                                $("#divTab2").show();
                            }
                            if (title == "私有组") {
                                $("#divTab1").hide();
                                $("#divTab2").hide();
                                $("#divTab3").show();
                            }
                        }
                    });
                });
                //提交验证事件
                function checkInput() {
                    var returnvalue = "";
                    var list = $('#ultree').find("input:checkbox[checked=true]");
                    var s = '';
                    for (var i = 0; i < list.length; i++) {
                        if ($(list[i]).attr("checked") == true) {
                            var spara = $(list[i]).attr("chktype");
                            if (spara != "0") {
                                if (returnvalue != '') returnvalue += ',';
                                returnvalue += $(list[i]).attr("chktext") + "(" + $(list[i]).attr("chkid") + ")";
                            }
                        }
                    }
                    

                    //获取选中的节点

                    var nodes = $.fn.zTree.getZTreeObj("tree").getCheckedNodes(true);                
                    if (nodes != null && nodes.length > 0) {
                        for (var i = 0; i < nodes.length; i++) {
                            if (nodes[i].iconSkin == "person") {
                                if (nodes[i].id == "0")
                                    continue;
                                if (nodes[i].iconSkin == "person") {
                                    if (returnvalue != '') returnvalue += ',';
                                    returnvalue += nodes[i].name + "(" + nodes[i].id + ")";
                                }
                            }
                        }
                    }
                    

                   //验证是否选中人员

                   if (returnvalue == "") {
                        $.messager.alert("系统提示""没选中人员!""error");
                        return false;
                    } else {
                        window.returnValue = returnvalue;
                        window.close();
                        return false;
                    }
                }
                //点击节点事件(JSON字符串中  id,pid,name是必须的字段
                var MultipleSetting = {
                    view: {
                        selectedMulti: false
                    },
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: ""
                        }
                    },
                    check: {
                        enable: true
                    },
                    async: {
                        enable: true,
                        url: getUrl//获取一般处理程序地址
                    },
                    callback: {
                        onClick: function (event, treeId, treeNode) {
                            currentTreeNode = treeNode;
                        },
                        onAsyncSuccess: zTreeOnAsyncSuccess
                    }
                };
                

                function zTreeOnAsyncSuccess(event, treeId, treeNode) {
                    if (treeNode == null)
                        zTree_SelectNodePureById("0""tree");
                    else
                        zTree_SelectNodePureById(treeNode.id, "tree");//JS事件
                    $("#datagridmask").remove();
                    $("#datagridmaskmsg").remove();
                }

                //获取成功后的返回事件

                function zTreeOnAsyncSuccessGG(event, treeId, treeNode) {
                    if (treeNode == null)
                        zTree_SelectNodePureById("0""treeGG");
                    else
                        zTree_SelectNodePureById(treeNode.Guid, "treeGG");
                    $("#datagridmask").remove();
                    $("#datagridmaskmsg").remove();
                }

                  //获取一般处理程序地址            

                  function getUrl(treeId, treeNode) {
                    //expandlevel表示展开层数 0表示全展开
                    var url = "";
                    
                    if (treeNode == null)  //根节点
                        url = "/CommonPage/NonInherited/SelUser/ExOperate.ashx?HandlerType=getusertreeinfo&expandlevel=2&id=0&rand=" + newCommon.atrand(10000000);
                    else
                        url = "/CommonPage/NonInherited/SelUser/ExOperate.ashx?HandlerType=getusertreeinfo&expandlevel=1&id=" + treeNode.id + "&rand=" + newCommon.atrand(10000000);
                    
                    return url;
                    
                }

                //显示等候窗口(异步调用一般处理手法) 

                function initTree() {
                    $("<div id="datagridmask" class="datagrid-mask"></div>").css({ display: "block",  "100%", height: $(window).height() }).appendTo("body");
                    $("<div id="datagridmaskmsg" class="datagrid-mask-msg"></div>").html("正在处理,请稍候...").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 150) / 2, top: ($(window).height() - 45) / 2 });

                    $.fn.zTree.init($("#tree"), MultipleSetting);
                    $.fn.zTree.init($("#treeGG"), MultipleSettingGG);
    //                $("#datagridmask").remove();
    //                $("#datagridmaskmsg").remove();
                }

                $(function () {
                    initTree();
                    $("#tree").width($(window).width() - 20);
                    $("#tree").height($(window).height() - 110);
                });
            </script>


    //一般处理程序,获取数据(AJAX异步调用) 

    #region 获取公共组人员树
            /// <summary>
            
    /// 获取人员树
            
    /// </summary>
            
    /// <param name="context"></param>
            
    /// <returns></returns>
            public string FGetUserTreeInfoGG(HttpContext context)
            {
                var id = "0";
                var constraintOrgCode = "";
                var hidConstraintOrgCode = "";
                if (!string.IsNullOrWhiteSpace(context.Request["id"]))
                    id = context.Request["id"];
                if (!string.IsNullOrWhiteSpace(context.Request["ConstraintOrgCode"]))
                    constraintOrgCode = context.Request.QueryString["ConstraintOrgCode"];
                if (!string.IsNullOrWhiteSpace(context.Request["HidConstraintOrgCode"]))
                    hidConstraintOrgCode = context.Request["HidConstraintOrgCode"];
                var strContent = new StringBuilder();
                try
                {
                    var haveOrgCode = new List<string>();
                    var HidOrgCodeList = hidConstraintOrgCode.Split(new string[] { ",""" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    var oClient = Hzjg.OA.Pub.WcfReference.fCreateInterfaceOut();

                    if (!string.IsNullOrWhiteSpace(constraintOrgCode))
                    {
                        var arryOrgCode = constraintOrgCode.Split(new string[] { ",""" }, StringSplitOptions.RemoveEmptyEntries);
                        if (arryOrgCode.Length > 0)
                            haveOrgCode.AddRange(arryOrgCode);
                        foreach (var orgcode in haveOrgCode)
                        {
                            var OrgUserTree = CommonCode.GetDataService.GetData().GetOAGroupUser(orgcode, System.Configuration.ConfigurationManager.AppSettings["SMSKey"]);
                            if (OrgUserTree != null)
                            {
                                //反序列化
                                var objUser = Newtonsoft.Json.Linq.JObject.Parse(OrgUserTree)["data"];//把json格式的字符串转换成json
                                strContent.Append("[");
                                foreach (var item in objUser)
                                {
                                    //strContent.Append("{id:'" + item["UserID"] + "', pId:'" + orgcode + "', name:'" + item["UserName"] + "', iconSkin:'folder'},");
                                    strContent.Append("{id:" + item["UserID"].ToString() + ", pId:" + orgcode + ", name:" + item["UserName"].ToString() + ",OrgCode:" + orgcode + ",OrgName:'组织结构', NodeType:'USER', iconSkin:'person'},");
                                }
                                if (objUser.Count() > 0)
                                {
                                    strContent = strContent.Remove(strContent.ToString().LastIndexOf(','), 1);
                                }
                                strContent.Append("]");
                            }
                        }
                    }
                    else //显示整个组织机构
                    {
                        if (id == "0")
                        {
                            string OrgList = CommonCode.GetDataService.GetData().GetOAGroup(System.Configuration.ConfigurationManager.AppSettings["SMSKey"]);
                            if (!string.IsNullOrEmpty(OrgList))
                            {
                                //反序列化
                                var obj = Newtonsoft.Json.Linq.JObject.Parse(OrgList)["data"];//把json格式的字符串转换成json
                                strContent.Append("[");
                                foreach (var item in obj)
                                {
                                    //strContent.Append("{id:'" + item["Guid"] + "', pId:'0', name:'" + item["GroupName"] + "', iconSkin:'folder'},");
                                    strContent.Append("{id:" + item["Guid"].ToString() + ", pId:'0', name:" + item["GroupName"].ToString() + ",NodeType:'ORG', open:false, isParent: true, iconSkin:'folder'},");
                                }
                                if (obj.Count() > 0)
                                {
                                    strContent = strContent.Remove(strContent.ToString().LastIndexOf(','), 1);
                                }
                                strContent.Append("]");
                            }
                            else
                            {
                                strContent.Append("[{id:" + 0 + ", pId:'0', name:'组织机构', iconSkin:'folder'}]");
                            }
                        }
                        else
                        {
                            var OrgUserTree = CommonCode.GetDataService.GetData().GetOAGroupUser(id, System.Configuration.ConfigurationManager.AppSettings["SMSKey"]);
                            if (OrgUserTree != null)
                            {
                                //反序列化
                                var objUser = Newtonsoft.Json.Linq.JObject.Parse(OrgUserTree)["data"];//把json格式的字符串转换成json
                                strContent.Append("[");
                                foreach (var item in objUser)
                                {
                                    strContent.Append("{id:" + item["UserID"].ToString() + ", pId:'" + id + "', name:" + item["UserName"].ToString() + ",OrgCode:'" + id + "',OrgName:'组织结构', NodeType:'USER', iconSkin:'person'},");
                                }
                                if (objUser.Count() > 0)
                                {
                                    strContent = strContent.Remove(strContent.ToString().LastIndexOf(','), 1);
                                }
                                strContent.Append("]");
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.fWriterLog("获取人员树异常:" + exception.Message, exception);
                }
                return strContent.ToString();
            }
            #endregion

    //加载自定义人员树 总结: 先加载目录树,在加载目录时判断该目录下有没有人员,有人员加载人员,没有人员加载目录
    #region 获取机构人员树
            public string AgencyPersonnel(HttpContext context)
            {
                var strContent = new StringBuilder();
                string id = "0"//当前要开始展开的节点
                string pid = ""//父节点
                string name = "组织机构";
                if (!string.IsNullOrWhiteSpace(context.Request["id"]))
                    id = context.Request["id"];
                try
                {
                    //获取通讯录机构
                    List<Model.OFFICE_PERSONALADDRESSBOOKGROUP> orgInfos = new BLL.OFFICE_PERSONALADDRESSBOOKGROUP().GetList("""").ToList();
                    //获取通讯录人员
                    List<Model.OFFICE_PERSONALADDRESSBOOKUSER> jgrys = new BLL.OFFICE_PERSONALADDRESSBOOKUSER().GetList("""").ToList();
                    List<dynamic> teachers = new BLL.JCJG0101().GetDynamicList(" select t.GH,t.SJH,t.XBM,t.XM  from JCJG0101 t""").ToList();
                    List<dynamic> student = new BLL.JCXS0101().GetDynamicList(" select t.XH,t.XBM,t.XM  from JCXS0101 t""").ToList();
                    strContent.Append("[");
                    //if (id == "0")
                    
    //{
                    if (orgInfos.Count > 0)
                    {

                        var topOrgs = orgInfos.Where(p => p.PARENTID == "0" || p.PARENTID == "");
                        //strContent.Append("{id:'" + id + "', pId:'" + pid + "', name:'" + name + "',open:true, iconSkin:'folder'}");
                        foreach (var orgInfo in topOrgs)
                        {
                            var isParent = false;
                            if (strContent.ToString() != "[")
                                strContent.Append(",");
                            //获取该目录下人员
                            List<OFFICE_PERSONALADDRESSBOOKUSER> underTeacher = jgrys.Where(o => o.GROUPID == orgInfo.ID).ToList().OrderBy(o => o.SEQ).ToList();
                            if (underTeacher.Count > 0)
                                isParent = true;
                            if (isParent)
                            {
                                strContent.Append("{id:'" + orgInfo.ID + "', pId:'" + id + "', name:'" + orgInfo.GROUPNAME + "',open:true, isParent: true, iconSkin:'folder'}");
                                foreach (var caJgry in underTeacher)
                                {
                                    var userModel = teachers.FirstOrDefault(o => o.GH == caJgry.RYH);
                                    var userStudent = student.FirstOrDefault(s => s.XH == caJgry.RYH);
                                    if (userModel != null)
                                    {
                                        //根据人员号获取教师数据
                                        Model.JCJG0101 mJcjg0101 = new BLL.JCJG0101().GetModel(userModel.GH);
                                        if (strContent.ToString() != "[")
                                            strContent.Append(",");
                                        strContent.Append("{id:'" + userModel.GH + "', pId:'" + orgInfo.ID + "', sjh:'" + (mJcjg0101 == null ? "" : mJcjg0101.SJH) + "',rylx:'" + "1" + "',xbm:'" + (mJcjg0101 == null ? "" : mJcjg0101.XBM) + "', name:'" + (mJcjg0101 == null ? "" : mJcjg0101.XM) + "', iconSkin:'person'}");
                                    }
                                    if (userStudent != null)
                                    {
                                        //根据人员号获取教师数据
                                        Model.JCXS0101 mJcxs0101 = new BLL.JCXS0101().GetModel(userStudent.XH);
                                        Model.JCXS0106 mJcxs0106 = new BLL.JCXS0106().GetModel(userStudent.XH);
                                        if (strContent.ToString() != "[")
                                            strContent.Append(",");
                                        strContent.Append("{id:'" + userStudent.GH + "', pId:'" + orgInfo.ID + "', sjh:'" + "" + "',rylx:'" + "1" + "',xbm:'" + (mJcxs0101 == null ? "" : mJcxs0101.XBM) + "', name:'" + (mJcxs0101 == null ? "" : mJcxs0101.XM) + "', iconSkin:'person'}");
                                    }
                                }
                            }
                            else
                            {
                                strContent.Append("{id:'" + orgInfo.ID + "', pId:'" + id + "', name:'" + orgInfo.GROUPNAME + "', iconSkin:'folder'}");
                            }
                            FRecursive(orgInfo.ID, ref strContent, jgrys, orgInfos, teachers, student);
                        }
                    }
                    else
                    {
                        strContent.Append("{id:'" + id + "', pId:'" + pid + "', name:'" + name +
                                          "',open:true, iconSkin:'folder'}");
                    }
                    //}
                    strContent.Append("]");
                }
                catch (Exception exception)
                {
                    Log.fWriterLog("获取教师信息树业务处理业务处理层异常:" + exception.Message, exception);
                }
                return strContent.ToString();
            }
            #region 递归加载

            public void FRecursive(string pid, ref StringBuilder strContent, List<Model.OFFICE_PERSONALADDRESSBOOKUSER> userList,
                                   List<Model.OFFICE_PERSONALADDRESSBOOKGROUP> groupList, List<dynamic> teachers, List<dynamic> student)
            {
                if (groupList != null)
                {
                    var child = groupList.Where(o => o.PARENTID == pid).ToList();
                    foreach (var orgInfo in child)
                    {
                        var isParent = false;
                        if (strContent.ToString() != "[")
                            strContent.Append(",");
                        //获取改机构下的教师人员
                        List<Model.OFFICE_PERSONALADDRESSBOOKUSER> underTeacher = userList.Where(o => o.GROUPID == orgInfo.ID).ToList().OrderBy(o => o.SEQ).ToList();
                        if (underTeacher.Count > 0)
                            isParent = true;
                        if (isParent)
                        {
                            strContent.Append("{id:'" + orgInfo.ID + "', pId:'" + pid + "', name:'" + orgInfo.GROUPNAME + "',open:true, isParent: true, iconSkin:'folder'}");
                            foreach (var caJgry in underTeacher)
                            {
                                var userModel = teachers.FirstOrDefault(o => o.GH == caJgry.RYH);
                                var userStudent = student.FirstOrDefault(s => s.XH == caJgry.RYH);
                                if (userModel != null)
                                {
                                    //根据人员号获取教师数据
                                    Model.JCJG0101 mJcjg0101 = new BLL.JCJG0101().GetModel(userModel.GH);
                                    if (strContent.ToString() != "[")
                                        strContent.Append(",");
                                    strContent.Append("{id:'" + userModel.GH + "', pId:'" + orgInfo.ID + "', sjh:'" + (mJcjg0101 == null ? "" : mJcjg0101.SJH) + "',rylx:'" + "1" + "',xbm:'" + (mJcjg0101 == null ? "" : mJcjg0101.XBM) + "', name:'" + (mJcjg0101 == null ? "" : mJcjg0101.XM) + "', iconSkin:'person'}");
                                }
                                if (userStudent != null)
                                {
                                    //根据人员号获取教师数据
                                    Model.JCXS0101 mJcxs0101 = new BLL.JCXS0101().GetModel(userStudent.XH);
                                    Model.JCXS0106 mJcxs0106 = new BLL.JCXS0106().GetModel(userStudent.XH);
                                    if (strContent.ToString() != "[")
                                        strContent.Append(",");
                                    strContent.Append("{id:'" + userStudent.GH + "', pId:'" + orgInfo.ID + "', sjh:'" + "" + "',rylx:'" + "1" + "',xbm:'" + (mJcxs0101 == null ? "" : mJcxs0101.XBM) + "', name:'" + (mJcxs0101 == null ? "" : mJcxs0101.XM) + "', iconSkin:'person'}");
                                }
                            }
                        }
                        else
                        {
                            strContent.Append("{id:'" + orgInfo.ID + "', pId:'" + pid + "', name:'" + orgInfo.GROUPNAME + "', iconSkin:'folder'}");
                        }

                        FRecursive(orgInfo.ID, ref strContent, userList, groupList, teachers, student);
                    }
                }
            }

            #endregion
            #endregion
  • 相关阅读:
    每日一题
    每日一题
    每日一题
    每日一题
    GitLab 部署
    Golang Web开发之Gin入门
    Golang消息队列之NSQ
    Golang操作Redis
    Golang操作MySQL
    Golang Json数据处理方法
  • 原文地址:https://www.cnblogs.com/zecVip/p/4441943.html
Copyright © 2020-2023  润新知