(function ($) { function _getstyles(){ var s=''; return s; } function chnageuser(sobj, options) { var obj = sobj; var rand = '' + parseInt(Math.random() * 9999999); var me = this; this.rand = rand; this.changesel = ''; this.firstpid = 0; this._init = function() { for (var i in options) this[i] = options[i]; this.oveob = false; if (this.showview !='' && get(this.showview)) this.oveob = true; if (!this.oveob) { window.onhashchange = function() { var has = location.hash; if (has.indexOf('#changeuser') == -1) me.hide(); } js.location('#changeuser'); } this.userarr = []; this.deptarr = []; this.grouparr = []; if (isempt(this.changerange) && isempt(this.changerangeno)) { var us = js.getoption('userjson'); if (us) this.userarr = js.decode(us); us = js.getoption('deptjson'); if (us) this.deptarr = js.decode(us); us = js.getoption('groupjson'); if (us) this.grouparr = js.decode(us); } this.show(); }; this.creatediv = function() { var type='checkbox'; if (this.changetype.indexOf('check') == -1) type='radio'; this.inputtype = type; $('#changeuser_' + rand).remove(); var hei = $(window).height(), jhei=50, atts='position:fixed;'; if (this.oveob) { hei = $('#'+this.showview+'').height(); atts=''; } var s='
'; if (this.titlebool) { s += '
'+this.title+'
'; jhei += 50; } if (this.changetype.indexOf('user') >= 0) { s += '
'; jhei += 50; } s += '
'; s += ''; s += ''; s += '
'; var s3= ''; if (type != 'checkbox1') s3 = ''; if (1==1) { s3=''; } s += '
 '+s3+'   
'; s += _getstyles(); s += '
'; if (atts=='') { $('#'+this.showview+'').html(s); } else { obj.append(s); } $('#changecancl_'+this.rand+'').click(function(){ me._clickcancel(); }); $('#changereload_'+this.rand+'').click(function(){ me._loaddata(); }); $('#changeok_'+this.rand+'').click(function(){ me.queding(); }); $('#changesoubtn_'+this.rand+'').click(function(){ me._searchkey(true); }); $('#changekey_'+this.rand+'').keydown(function(e){ me._searchkeys(e) }); $('#changeboxs_'+this.rand+'').click(function(){ me._changboxxuan(this) }); $('#changesel_'+this.rand+'').change(function(){ me._changesel(this) }); }; this.showlist=function(pid,oi){ var type=this.inputtype,hw=24; var s='',ssu='',s1=''; var sel = this.changesel; var dob = this.changetype.indexOf('dept')==-1; var uob = this.changetype.indexOf('user')>=0; this.fid = 1; if(sel=='1'){ ssu = this._showuser(0,'',type,sel); }else if(sel=='2'){ s = this._showdept(pid,oi,s1,type,sel,dob,uob); }else if(sel=='3'){ s = this._showgorup(type); }else{ s1='
'; s = this._showdept(pid,oi,s1,type,sel,dob,uob); if(uob){ ssu+=this._showuser(pid,s1,type,sel); } } var xud = (oi==0)?'0' : pid; $('#showdiv'+rand+'_'+xud+'').html(ssu+s).attr('show','true'); if(sel==''){ if(oi==0)this.showlist(this.fid, 1); $('#showdiv'+rand+'_0 [deptxu]').unbind('click').click(function(){ me._deptclicks(this); }); } if(sel=='3'){ $('#showdiv'+rand+'_0 [groupxu]').unbind('click').click(function(){ me._groupclicks(this); }); } }; this._showuser=function(pid,s1,type,sel){ var a,len,i,ssu='',dids,zoi=0,ids; a=this.userarr; len=a.length; for(i=0;i-1 || sel=='1') && sel!='3') || (sel=='3' && (','+a[i].groupname+',').indexOf(','+pid+',')>-1)//显示组下人员 ){ ssu+='
'; ssu+='
'+s1+' '+a[i].name+'('+a[i].ranking+')
'; ssu+='
'; zoi++; if(zoi>=200)break;//最多显示200人,其他用搜索 } } return ssu; }; this._showdept=function(pid,oi,s1,type,sel,dob,uob){ var a,len,i,wwj,s2='',s=''; a=this.deptarr; len=a.length; for(i=0;i'; if(dob)s2=''; if(s2!='' && !this._isdeptcheck(a[i]))s2=''; s+='
'; s+='
'+s1+' '+a[i].name+''+s2+'
'; s+='
'; s+=''; } } return s; }; this._showgorup=function(type){ var a,len,i,ssu='',s1; a=this.grouparr; len=a.length; for(i=0;i'; if(this.changetype.indexOf('deptuser')==-1)s1=''; ssu+='
'; ssu+='
 '+a[i].name+' ('+a[i].usershu+'人)'+s1+'
'; ssu+='
'; ssu+=''; } return ssu; }; this._groupclicks = function(o) { if (this.changetype.indexOf('user')==-1)return; var sxu = $(o).attr('groupxu'); var a = this.grouparr[sxu]; var o1 = $('#showgroup'+rand+'_'+a.id+''); var lx = o1.attr('show'); if (lx=='false') { var s1='
'; var s = this._showuser(a.id,s1,this.inputtype, this.changesel); o1.html(s).attr('show','true'); } else { o1.toggle(); } }; this._changesel = function(o1) { var val = o1.value; this.changesel = val; this.showlist(this.firstpid, 0); }; this._searchkeys=function(e){ clearTimeout(this._searchkeystime); this._searchkeystime=setTimeout(function(){ me._searchkey(false); },500); }; this._isdeptcheck=function(a){ if(this.inputtype=='checkbox' && this.changetype.indexOf('user')>=0 && this.changetype.indexOf('dept')>=0){ var stotal,i,nstotal=0,len=this.userarr.length,spath; stotal = parseFloat(a.stotal); for(i=0;i=0)nstotal++; } return nstotal>=stotal; }else{ return true; } }, this._clickcheckbox=function(o1) { var o = $(o1),xu,a,stotal,i,nstotal=0,len=this.userarr.length,spath; if (o.attr('xls') != 'd') return; xu = parseFloat(o.attr('xu')); a = this.deptarr[xu]; stotal = parseFloat(a.stotal); for (i=0; i < len; i++) { spath = this.userarr[i].deptpath; if (spath.indexOf('['+a.id+']')>=0)nstotal++; } if (nstotal < stotal) { o1.checked=false; o1.disabled=true; js.msg('msg','无权选择部门['+a.name+']'); } }, this._searchkey = function(bo){ var key = $('#changekey_'+this.rand+'').val(),s='',a=[],d=[],len,i; a=this.userarr; len=a.length; if(key!='')for(i=0;i-1 || a[i].pingyin.indexOf(key)==0 || a[i].deptname.indexOf(key)>-1 || a[i].ranking.indexOf(key)>-1){a[i].xu=i;d.push(a[i])}; len = d.length; for(i=0;i '+d[i].name+'('+d[i].ranking+')'; s+=''; } if(bo && s=='' && key!='')js.msg('msg','无相关['+key+']的记录', 2); $('#showdiv'+rand+'_search').html(s); var o1 = $('#showdiv'+rand+'_0'); if(s==''){o1.show();}else{o1.hide();} }; this._clickcancel=function(){ if(!this.oveob)history.back(); this.hide(); }; this.hide=function(){ $('#changeuser_'+rand+'').remove(); this.oncancel(); }; this.show=function() { this.creatediv(); if (this.deptarr.length > 0) { this.firstpid = this.deptarr[0].pid; this.showlist(this.firstpid, 0); } else { this._loaddata(); } }; this._deptclicks=function(o){ var sxu = $(o).attr('deptxu').split('_'); var a = this.deptarr[sxu[0]]; var o1 = $('#showdiv' + rand + '_' + a.id); var lx = o1.attr('show'); if (lx=='false') { this.showlist(a.id, parseFloat(sxu[1]) + 1); } else { o1.toggle(); } }; this._loaddata = function() { var o1 = $('#showdiv'+rand+'_0'),url; o1.html('
'); // var url = 'index.php?a=deptuserjson&m=dept&d=system&ajaxbool=true&changerange='+this.changerange+'&changerangeno='+this.changerangeno+'>ype=change'; var url = '/chat/chat/getDepartmentUserData?changerange='+this.changerange+'&changerangeno='+this.changerangeno+'>ype=change'; $.getJSON(url, function(ret) { if (ret.code == 200) { ret = ret.data; me._loaddatashow(ret); } else { o1.html(ret.msg); } }); }; this._loaddatashow = function(ret) { if (isempt(this.changerange) && isempt(this.changerangeno)) { js.setoption('deptjson', ret.deptjson); js.setoption('userjson', ret.userjson); js.setoption('groupjson', ret.groupjson); } this.userarr = ret.userjson; this.deptarr = ret.deptjson; this.grouparr = ret.groupjson; this.firstpid = 0; if (this.deptarr[0]) { this.firstpid = this.deptarr[0].pid; } this.showlist(this.firstpid, 0); }; this._changboxxuan=function(os) { var ns= 'changeuserinput_' + rand; if($('#showdiv'+rand+'_search').html()!='')ns+='_soukey'; var ob = os.checked,o=$("input[name='"+ns+"']"),i; for(i=0;i'; s+='
'; s+='
   '+this.title+'
'; s+='
'; s+='
'; s+='
    
'; s+='
'; s+=''; s+=_getstyles(); $('body').append(s); this.showdata(this.data); var o = this._getobj('main'); var l = ($(window).width()-o.width())*0.5,t = ($(window).height()-o.height())*0.5; o.css({'left':''+l+'px','top':''+t+'px'}); $('#changecancl_'+this.rand+'').click(function(){ me._clickcancel(); }); $('#changeok_'+this.rand+'').click(function(){ me.queding(); }); $('#changereload_'+this.rand+'').click(function(){ me.loaddata(); }); $('#changesoubtn_'+this.rand+'').click(function(){ me._searchkey(true); }); $('#changekey_'+this.rand+'').keydown(function(e){ me._searchkeys(e) }); $('#changekey_'+this.rand+'').keyup(function(e){ me._searchkeys(e) }); }; this._getobj=function(lx){ var o = $('#selectdata_'+rand+'').find("[tsid='"+lx+"']"); return o; }; this._clickcancel=function(){ this.hide(); }; this.hide=function(){ $('#selectdata_'+rand+'').remove(); this.oncancel(); }; this.queding=function(){ var ns= 'changeuserinput_'+rand+''; var o = $("input[name='"+ns+"']"); var i,len=o.length,o1,xna,xu,xal,sid='',sna='',seld=[]; for(i=0;i 0) { this.showselbo=true; } $(o).change(function() { me._changeselval(this); }).show(); }; this._changeselval = function(o) { this.loaddata(o.value); }; this.showhtml=function(a){ this.nowdata = a; var i,len=a.length,s='',s2,s1='',atr,oldvel='',d; if(this.nameobj)oldvel=this.nameobj.value; if(this.idobj)oldvel=this.idobj.value; var type='checkbox',ched=''; if(!this.checked)type='radio'; oldvel = ','+oldvel+','; for(i=0;i-1)ched='checked'; if(d.disabled)ched+=' disabled'; s2 = ''; atr = ''; if(d.padding)atr='style="padding-left:'+d.padding+'px"'; if(!d.iconswidth)d.iconswidth=18; if(d.iconsimg)s2+=' '; s+='
'; } return s; }; this.loaddata=function(svel){ var url = this.url; if(svel)url+='&selvalue='+svel+''; if(url=='')return; $('#selectlist_'+rand+'').html('
'); $.getJSON(url, function(a){ me.data = a; me.onloaddata(a); me.showdata(a, true); }); }; this._searchkeys=function(e){ clearTimeout(this._searchkeystime); this._searchkeystime=setTimeout(function(){ me._searchkey(false); },500); }; this._searchkey = function(bo){ var key = $('#changekey_'+this.rand+'').val(),a=[],d=[],d1,len,i,oi=0,s; a=this.data; if(a.rows)a=a.rows; len=a.length;if(len==0)return; if(key!='')for(i=0;i-1 || d1.value==key || (d1.subname && d1.subname.indexOf(key)>-1)){ d.push(d1); oi++; if(oi>20)break;//最多显示搜索 } } len = d.length; if(len==0){ s=this.showhtml(a); }else{ s=this.showhtml(d); } $('#selectlist_'+rand+'').html(s); if(bo && len==0 && key!='')js.msg('msg','无相关['+key+']的记录', 2); }; } $.fn.chnageuser = function(options) { var defaultVal = { 'title': '请选择...', 'titlebool': true, 'showview': '', 'changerange': '', //从哪些人员中选择 'changerangeno': '', //不从哪些人选择 'changetype' : 'user', 'idobj': false, 'nameobj': false, 'onselect': function() {}, 'oncancel': function() {} }; var can = $.extend({}, defaultVal, options); var funcls = new chnageuser($(this), can); funcls._init(); return funcls; }; $.selectdata = function(options) { var defaultVal = { 'showview': '', 'title': '请选择...', 'maxshow': 100, // 最多显示防止卡死浏览器 'data': [], 'url' : '', 'checked': false, 'idobj': false, 'nameobj': false, 'onselect': function() {}, 'oncancel': function() {}, 'onloaddata': function() {} }; var can = $.extend({}, defaultVal, options); var funcls = new selectdata(false, can); funcls._init(); return funcls; }; })(jQuery);