123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- var setting1,setting3;
- var dept_id = top.com.sinosoft.lz.system.user.LoginInfo.getCorp_ids();
- /*var deptId = top.com.sinosoft.lz.system.user.LoginInfo.getDept_id();*/
- //获取用户Id
- var user_id = top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
- //获取公司id
- var comp_id = top.com.sinosoft.lz.system.user.LoginInfo.getParent_ids();
- //获取登录用户的角色
- var role_id = top.com.sinosoft.lz.system.user.LoginInfo.getRoleids();
- var dept_name = top.com.sinosoft.lz.system.user.LoginInfo.getCorp_names();
- var contcactIdArr = [];
- //判定是选择外部还是内部单位
- //记录选中的组织id
- var selectedOrgId=[];
- //记录要添加的常用组id
- var groupId="";
-
- var addTreeNodes=[
-
- ];
- function initTree3(){
-
- $.fn.zTree.init($("#myTree3"),setting3,addTreeNodes);
-
- }
-
- $(function() {
- contcactIdArr = getContactUserId();
- setting1 = {
- view : {
- addHoverDom: addHoverDom,
- removeHoverDom: removeHoverDom,
- selectedMulti: false
- },
- async : {
- enable : true,
- dataType : 'JSON',
- contentType : "application/json",
- dataName : 'treeNodes',
- url : $.pathname()+'/ws/GetDeptTree/GetDeptTreeService/getUserTree/',
- autoParam : [ "id" ],
- },
-
- check: {
- enable: true
- },
- callback:{
- onClick:nodeNick,
- beforeCheck:beforeChecked,
- onCheck:onChecked
- }
- };
- $.fn.zTree.init($("#myTree1"), setting1);
-
- setting3={
- edit: {
- enable: true,
- removeTitle:"删除",
- showRemoveBtn : setRemoveBtn,
- // 显示编辑按钮
- showRenameBtn : setRenameBtn
- },
- callback:{
-
- //禁止拖拽
- beforeDrag : beforeDrag,
- beforeRemove: beforeRemove1,
- }
-
- };
- initTree3();
-
-
-
-
-
-
-
- //绑定清除事件
- $("#clearChosen").bind("click",function(){
-
- backToEver();
- });
-
-
-
- $("#queryInput").on("keyup",function(){
-
- ye = 1;
- //var zTree = $.fn.zTree.getZTreeObj("myTree3");
- /*var nodes = zTree.getNodes();
- if(nodes.length>0){
- for(var i=0;i<nodes.length;i++){
- tels +=nodes[i].id.split("_")[0]+",";
- }
- }*/
-
- var ids = "";
- if(selectedOrgId.length>0){
- for(var i=0;i<selectedOrgId.length;i++){
- ids += "'"+selectedOrgId[i]+"'"+",";
- }
- }
- var val = $("#queryInput").val().trim();
-
- if(val.length==0){
- $("#search").hide();
- $("#org_inner1").show();
- $("#selectPeople").show();
- $("#clearChosen").css("margin-top","0");
- }
-
- var pattern = new RegExp("[`~!@#$^&*()=|{}:;,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“。,、?]");
- if(val==""||val==null||val=="null"){
- return;
- }
-
-
- else if(isNaN(val)&&pattern.test(val)){
- top.Dialog.alert("不能输入非法字符");
- }else{
- $.ajax({
- url : $.pathname()+'/ws/GetDeptTree/GetDeptTreeService/getPeople/',
- type : 'post',
- data : {
- name:val,
- id:ids
- },
- dataType : 'json',
- timeout : 60000,
- success : function(data){
- $("#search").find("ul").empty();
- var getPep = data.treeNodes;
- var totalRows = data.totalRows;
- var $ul = $("#search").find("ul");
- if(getPep.length>0){
-
- for(var i=0;i<getPep.length;i++){
- $ul.append("<li class=_lis id=pep_"+i+" title="+getPep[i].key+" >"+getPep[i].key+"</li>");
- $("#pep_"+i).data("data",getPep[i].value);
- }
- $("#search").show();
- $("#org_inner1").hide();
- $("#selectPeople").hide();
- $("#clearChosen").css("margin-top","200px");
- var pageNow = pages(totalRows);
- if(pageNow>1){
- var $next = $("<span id='next'>下一页</span>");
- var $li = $("<li></li>");
- $ul.append($li.append($next));
- }
- }else{
- $ul.append("<li class=_lis>没有符合查询条件的人员</li>");
- }
- },
- error : function(){
- top.Dialog.alert('操作失败');
- }
- });
- }
- });
-
-
- $("._lis").live("click",function(){
- /*var thisId = $(this).attr("id");*/
- var pepId = $(this).data("data");
- if(pepId){
-
- /*var pepTel = thisId.split("|")[0];
- var pepcorp =thisId.split("|")[1];
- var pepDept = thisId.split("|")[2];*/
- var p = $(this).text();
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- if(!chekedTel(selectedOrgId,pepId)){
- top.Dialog.alert("此联系人已选择");
- return;
- }else if(contcactIdArr.indexValuess(pepId)!=-1){
- top.Dialog.alert("此联系人已存在");
- return;
- }else{
- $(this).addClass("selchecked");
- selectedOrgId.push(pepId);
- zTree.addNodes(null,showNames(p,pepId));
- }
-
- getSelectedNum(selectedOrgId);
-
- }
-
- /*var pepId = $(this).data("data");
- if(pepId){
-
- var p = $(this).text();
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- if(chekedTel(selectedOrgId,pepId)){
- $(this).addClass("selchecked");
- selectedOrgId.push(pepId);
- zTree.addNodes(null,showNames(p,pepId));
- }else{
- top.Dialog.alert("此联系人已选择");
- }
-
- getSelectedNum(selectedOrgId);
- }*/
-
- });
-
- //点击下一页
- var ye=1;
- $("#next").live("click",function(){
- ye++;
- fenye("next",ye);
-
- });
-
- //点击上一页
- $("#prev").live("click",function(){
- ye--;
- fenye("prev",ye);
- });
-
- $("#selectPeople").on("click",function(){
-
- var zTree = $.fn.zTree.getZTreeObj("myTree1");
- var treeObject = $.fn.zTree.getZTreeObj("myTree3");
- var checkedNodes = zTree.getCheckedNodes(true);
-
-
- if(checkedNodes.length==0){
- top.Dialog.alert("请勾选要选择的联系人");
- return;
- }else{
- for(var i=0;i<checkedNodes.length;i++){
- if(!checkedNodes[i].isParent&&checkedNodes[i].type!="corp"){
- if(contcactIdArr.indexValuess(checkedNodes[i].id)!=-1){
- top.Dialog.alert("联系人"+checkedNodes[i].name+"已存在");
- return;
- }else if(selectedOrgId.indexValuess(checkedNodes[i].id)!=-1){
- top.Dialog.alert("联系人"+checkedNodes[i].name+"已选择");
- return;
- }else{
- selectedOrgId.push(checkedNodes[i].id);
- treeObject.addNodes(null,gernerateSimpleNode(checkedNodes[i]));
- zTree.checkNode(checkedNodes[i],false,true);
- zTree.setChkDisabled(checkedNodes[i],true);
- $("#"+checkedNodes[i].tId).hide();
- }
- }
- }
- getSelectedNum(selectedOrgId);
- }
- });
- });
- function showNames(name,id){
- var names = {id:"",name:"",parentId:"1",icon:'/nwyj/scripts/qui/libs/icons/user_group.gif',title:""};
- names.id = id;
- names.name = name;
- names.title = name;
- return names;
- }
-
- //单个选中
- function getHoverNode(treeNode){
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- var treeObj = $.fn.zTree.getZTreeObj("myTree1");
- if(contcactIdArr.indexValuess(treeNode.id)!=-1){
- top.Dialog.alert("此联系人已存在");
- }else if(!chekedTel(selectedOrgId,treeNode.id)){
- top.Dialog.alert("此联系人已选择");
- }else{
- selectedOrgId.push(treeNode.id);
- zTree.addNodes(null,gernerateSimpleNode(treeNode));
- treeObj.checkNode(treeNode,false,true);
- treeObj.setChkDisabled(treeNode,true);
- $("#"+treeNode.tId).hide();
- }
- getSelectedNum(selectedOrgId);
- }
-
-
- //清除所有选择的组织
- function backToEver(){
-
- if(selectedOrgId.length>0){
-
- var flag = $("#search").is(":hidden");
- /* if(flag){*/
- var treeObj = $.fn.zTree.getZTreeObj("myTree1");
- for(var i=0;i<selectedOrgId.length;i++){
- var node = treeObj.getNodeByParam("id", selectedOrgId[i], null);
- if(node!=null){
-
- treeObj.checkNode(node,false,true);
- treeObj.setChkDisabled(node,false);
- $("#"+node.tId).show();
- }
- }
- /*}else{*/
- if(!flag){
-
- $("#search").find("ul").find("li").removeClass("selchecked");
- }
-
- /*}*/
- initTree3();
- selectedOrgId=[];
- getSelectedNum(selectedOrgId);
- }
-
-
- }
- //手动生成简易的节点
- function gernerateSimpleNode(treeNode){
-
- var sNode ={id:"",name:"",parentId:"1",icon:'/nwyj/scripts/qui/libs/icons/user_group.gif',title:"",deptName:"",corpName:""};
- sNode.title = treeNode.name;
- sNode.id=treeNode.id;
- sNode.name=treeNode.name;
- return sNode;
-
-
- }
-
-
- //更新已选择的数目
- function getSelectedNum(selectedOrgId){
- $("#selectedNum").html("已选择人员 ("+selectedOrgId.length+")");
- }
- //确认是否删除+删除处理
- function addHoverDom(treeId, treeNode) {
- if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0||treeNode.isParent==true||treeNode.type=="corp") return;
-
- var sObj = $("#" + treeNode.tId + "_span");
- var addStr = "<span class='zbutton add' id='addBtn_" + treeNode.id
- + "' title=添加 onfocus='this.blur();'></span>";
- sObj.append(addStr);
-
- var btn = $("#addBtn_" + treeNode.id);
- if (btn){
- btn.bind("click", function(){
- getHoverNode(treeNode);
- return false;
- });
- }
- };
- function setRemoveBtn(treeId, treeNode) {
- return true;
- }
- function setRenameBtn(treeId, treeNode) {
- return false;
- }
- function removeHoverDom(treeId, treeNode) {
- $("#addBtn_" + treeNode.id).unbind().remove();
- };
- function beforeDrag(){
- return false;
- }
- function beforeRemove1(treeId, treeNode) {
-
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- var flag = $("#search").is(":hidden");
- /*if(flag){*/
- var treeObj = $.fn.zTree.getZTreeObj("myTree1");
- var node = treeObj.getNodeByParam("id", treeNode.id, null);
- if(node!=null){
-
- $("#"+node.tId).show();
- treeObj.setChkDisabled(node,false);
- }
- /*if(node!=""||node!=null){
-
- }*/
- /*}else{*/
- if(!flag){
-
- var $title = $("#search").find("ul").find("li");
- for(var i=0;i<$title.length;i++){
- if($title.eq(i).data("data")==treeNode.id){
- $title.eq(i).removeClass("selchecked");
- }
- }
- /*}*/
-
- }
- zTree.removeNode(treeNode);
- selectedOrgId.removeGetInfo(treeNode.id);
- getSelectedNum(selectedOrgId);
- return false;
- }
- function chekedTel(arr,str){
- if(arr.length==0){
- return true;
- }
- for(var i=0;i<arr.length;i++){
- if(arr[i]==str){
- return false;
- }
- }
- return true;
- }
- function nodeNick(event ,treeId,treeNode){
- getHoverNode(treeNode);
-
- return false;
- }
- function cancle(){
- top.Dialog.confirm("确定不选择人员?",function(){
- top.Dialog.close();
- });
-
- }
- function beforeChecked(treeId, treeNode) {
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- var node = zTree.getNodes();
- if(node.length>0){
- for(var i=0;i<node.length;i++){
- if(treeNode.id==node[i].id){
- zTree.removeNode(node[i]);
- selectedOrgId.removeGetInfo(treeNode.id);
- }
- }
- }
- }
- function onChecked(treeId, treeNode){
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- var node = zTree.getNodes();
- if(node.length>0){
- for(var i=0;i<node.length;i++){
- if(treeNode.id==node[i].id){
- zTree.removeNode(node[i]);
- selectedOrgId.removeGetInfo(treeNode.id);
- }
- }
- }
- }
- function savePeople(){
- //获取常用联系组的人员电话和名字
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- var nodes = zTree.getNodes();
- if(nodes.length==0){
- top.Dialog.alert("请选择要添加到常用联系人里的人员");
- return;
- }
- var contactId = "";
- for(var i=0;i<nodes.length;i++){
- contactId +=nodes[i].id+",";
- }
- contactId = contactId.substring(0, contactId.lastIndexOf(","));
- $.ajax({
- url : $.pathname()+'/ws/GetDeptTree/GetDeptTreeService/createContact/',
- type : 'post',
- timeout : 15000,
- data : {
- userId :user_id,
- contactId:contactId
- },
- dataType : 'json',
- success : function(result){
- if (result.Msg.sucsess == true) {
- top.Dialog.alert("保存成功!",null,null,null,null);
- top.document.getElementById("_DialogFrame_addPeople").contentWindow.initTree1();
-
- $(parent.document.body).find("#_ButtonClose_addContactPeople").click();
- } else {
- top.Dialog.alert("保存失败!");
- }
- },
- error : function(e){
- top.Dialog.alert("保存失败");
- }
- });
-
-
-
- }
- //分页查询
- function pages(total){
- //页数
- var page=0;
- //每页显示的条数
- var pageSize=10;
- if(total%pageSize==0){
- page = total/pageSize;
- }else{
- page = Math.ceil(total/pageSize);
- }
- return page;
- }
- function fenye(obj,ye){
- var val = $("#queryInput").val().trim();
- var ids = "";
- if(selectedOrgId.length>0){
- for(var i=0;i<selectedOrgId.length;i++){
- ids += "'"+selectedOrgId[i]+"'"+",";
- }
- }
- $.ajax({
- url : $.pathname()+'/ws/GetDeptTree/GetDeptTreeService/getPeople/',
- type : 'post',
- data : {
- id:ids,
- name:val,
- page:ye,
- pageSize:10
- },
- dataType : 'json',
- timeout : 60000,
- success : function(data){
- $("#search").find("ul").empty();
- var getPep = data.treeNodes;
- var totalRows = data.totalRows;
- var $ul = $("#search").find("ul");
- for(var i=0;i<getPep.length;i++){
- $ul.append("<li class=_lis id=pep_"+i+" title="+getPep[i].key+">"+getPep[i].key+"</li>");
- $("#pep_"+i).data("data",getPep[i].value);
- }
- $("#search").show();
- $("#org_inner1").hide();
- $("#selectPeople").hide();
- $("#clearChosen").css("margin-top","200px");
- if(obj=="next"){
- var pageNow = pages(totalRows);
- var $spanYe = "";
- var $li = $("<li></li>");
- if(ye<pageNow){
- $spanYe = $("<span id='prev'>上一页</span><span id='next'>下一页</span>");
- }else{
- $spanYe = ("<li span id='prev'>上一页</li>");
- }
- $ul.append($li.append($spanYe));
- }else{
- if(ye==1){
- $ul.append("<li span id='next'>下一页</li>");
- }else{
- $ul.append("<li><span id='prev'>上一页</span><span id='next'>下一页</span></li>");
- }
- }
-
- },
- error : function(){
- top.Dialog.alert('操作失败');
- }
- });
- }
- function getContactUserId(){
-
- var idArr = [];
- $.ajax({
- url : $.pathname()+'/ws/GetDeptTree/GetDeptTreeService/getgetUserContactIds/',
- type : 'post',
- data : {
-
- userId:user_id,
-
- },
- dataType : 'json',
- timeout : 60000,
- async:false,
- success : function(data){
- idArr = data;
- },
- error : function(){
- top.Dialog.alert('操作失败');
- }
- });
-
- return idArr;
- }
|