boss-index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. $(function() {
  2. // 分机构导航
  3. $('span[data-menu="header"]').on('click', function() {
  4. var $menu = $(this).next();
  5. if ($menu.css('display') == 'none') {
  6. $menu.slideDown();
  7. } else {
  8. $menu.slideUp();
  9. }
  10. });
  11. // 搜索
  12. $('input[data-im="search"]').on('focus', function() {
  13. if ($(this).val() == '搜索联系人...') {
  14. $(this).val('').addClass('focus');
  15. $('.im-search-btn').show();
  16. }
  17. }).on('blur', function() {
  18. if ($(this).val() == '') {
  19. //$('.im-menu-hd>a').eq(0).click();
  20. searchFun();
  21. }
  22. });
  23. $('.im-search-btn').on('click', function() {
  24. $(".search-scroll").getNiceScroll().resize();
  25. $('.im-main-search').show();
  26. $('.im-search-close').show();
  27. $('.im-menu-hd>a.curr').removeClass('curr');
  28. searchInfo();
  29. });
  30. $('input[data-im="search"]').keyup(function(e) {
  31. $(".search-scroll").getNiceScroll().resize();
  32. $('.im-main-search').show();
  33. $('.im-search-close').show();
  34. $('.im-menu-hd>a.curr').removeClass('curr');
  35. searchInfo();
  36. });
  37. $('#text_msg').keyup(function(e) {
  38. if (e.ctrlKey && e.which == 13) {
  39. $("#text_msg").val($("#text_msg").val()+"\n");
  40. }else if(e.which == 13) {
  41. sendMsg();
  42. }
  43. });
  44. $('.im-search-close').on('click', function() {
  45. $('input[data-im="search"]').val('').focus();
  46. $("#search_friend_result").html("");
  47. });
  48. // 页面初始化
  49. function scrollFun() {
  50. // 主iframe
  51. $('#iframe-main').css({width : $(window).width(),height : $(window).height() - 50});
  52. $('#iframe-im').css({height : $(window).height() - 50});
  53. // im-main-box 高度
  54. $('.im-main-search,.im-menu-bd,.im-main-mine,.im-main-apps').css({height : $(window).height() - 243});
  55. // 自定义滚动条
  56. $(".apps-scroll").css({height:$(window).height()-276}).niceScroll({cursorborder:"",cursorcolor:"#cccdd1"});
  57. $(".search-scroll").css({height : $(window).height() - 243}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  58. $('.mine-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  59. $('.apply-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  60. $('.group-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  61. $('.tree-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  62. $('.user-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  63. $('.tidings-scroll').css({height : $(window).height() - 276}).niceScroll({cursorborder : "",cursorcolor : "#cccdd1"});
  64. }
  65. scrollFun();
  66. // 窗口大小被改变时
  67. $(window).resize(function() {
  68. throttle(scrollFun(), 300)
  69. });
  70. // tabs
  71. $('.im-menu').tabs({
  72. callback : function(index) {
  73. $('.im-main-mine,.im-main-apps').hide();
  74. searchFun();
  75. switch (index) {
  76. case 0:
  77. $('.tidings-scroll').getNiceScroll().resize();
  78. break;
  79. case 1:
  80. $('.apply-scroll').getNiceScroll().resize();
  81. break;
  82. case 2:
  83. userTabsScroll($('.im-user-hd').find('a.curr').index());
  84. break;
  85. }
  86. }
  87. });
  88. $('.im-user-tabs').tabs({
  89. callback : function(index) {
  90. userTabsScroll(index);
  91. }
  92. });
  93. function userTabsScroll(index) {
  94. switch (index) {
  95. case 0:
  96. $('.user-scroll').getNiceScroll().resize();
  97. break;
  98. case 1:
  99. $('.group-scroll').getNiceScroll().resize();
  100. break;
  101. case 2:
  102. $('.tree-scroll').getNiceScroll().resize();
  103. break;
  104. }
  105. }
  106. // im主窗口
  107. $('.boss-im-arrow').on('click', function() {
  108. showImBox();
  109. });
  110. $('a[data-im="mine"]').on('click', function() {
  111. showImBox("mine");
  112. });
  113. $('a[data-im="tidings"]').on('click', function() {
  114. showImBox("tidings");
  115. });
  116. $('a[data-im="apply"]').on('click', function() {
  117. showImBox("apply");
  118. });
  119. showImBox("apply");
  120. // iframe-im
  121. $('.iframe-im-close').on('click', function() {
  122. imClosed();
  123. });
  124. $('.im-my-head').on('click', function() {
  125. showIframe('myUserInfo.html');
  126. });
  127. $('#detailInfo').on('click', function() {
  128. if ($("#isGroup").val() == 1) {
  129. $('#iframe-userInfo').attr("src", "");
  130. showIframe("myGroupInfo.html?tid=" + $("#talkingID").val());
  131. } else {
  132. $('#iframe-userInfo').attr("src", "");
  133. showIframe("myFriendInfo.html?tid=" + $("#talkingID").val());
  134. }
  135. });
  136. // 组织列表
  137. $(document)
  138. .on(
  139. 'click',
  140. 'div.tree-hd',
  141. function() {
  142. var $el = $(this), $next = $el.next(), $a = $el
  143. .children('a'), $iconfont = $el
  144. .find('i.iconfont'), $box = $next
  145. .find('.tree-bd-box');
  146. //$box.css('padding-left', $a.position().left);
  147. if ($next.css('display') == 'none') {
  148. $iconfont.remove();
  149. $a.prepend('<i class="iconfont">&#xe60f;</i>');
  150. $next.slideDown();
  151. } else {
  152. $iconfont.remove();
  153. $a.prepend('<i class="iconfont">&#xe609;</i>')
  154. $next.slideUp();
  155. }
  156. });
  157. //iframeMenuList();
  158. });
  159. ;
  160. function searchFun() {
  161. $('input[data-im="search"]').val('搜索联系人...').removeClass('focus');
  162. $('.im-search-btn').hide();
  163. $('.im-search-close').hide();
  164. $('.im-main-search').hide();
  165. }
  166. function showImBox(dom) {
  167. var $im = $('.boss-im'), $arrow = $('.boss-im-arrow'), $iframe = $('#iframe-main'), $menua = $('.im-menu-hd>a'), $iframeTab = $('.iframe-menu');
  168. if (typeof (dom) == 'undefined') {
  169. $('.im-main-mine').hide();
  170. searchFun();
  171. }
  172. if (dom != '') {
  173. if ($im.is('.show')) {
  174. switch (dom) {
  175. case 'mine':
  176. if ($('.im-main-mine').css('display') == 'none') {
  177. $('.im-menu-hd>a.curr').removeClass('curr');
  178. $('.im-main-mine').show();
  179. return false;
  180. }
  181. break;
  182. case 'tidings':
  183. if (!($menua.eq(0).is('.curr'))) {
  184. searchFun();
  185. $('.im-main-mine').hide();
  186. $menua.eq(0).click();
  187. return false;
  188. }
  189. break;
  190. case 'apply':
  191. if (!($menua.eq(1).is('.curr'))) {
  192. searchFun();
  193. $('.im-main-mine').hide();
  194. $menua.eq(1).click();
  195. return false;
  196. }
  197. break;
  198. }
  199. } else {
  200. switch (dom) {
  201. case 'mine':
  202. $('.im-main-mine').show();
  203. $('.im-menu-hd>a.curr').removeClass('curr');
  204. break;
  205. case 'tidings':
  206. $menua.eq(0).click();
  207. break;
  208. case 'apply':
  209. $menua.eq(1).click();
  210. break;
  211. }
  212. }
  213. }
  214. if($im.is('.show')){
  215. $im.removeClass('show').animate({
  216. right: -275
  217. },300);
  218. /*$iframe.animate({
  219. width: $(window).width()
  220. },300);*/
  221. $iframeTab.animate({
  222. width: $(window).width()
  223. },300,function(){$arrow.css('left',"-15px")});
  224. $arrow.html('<i class="iconfont">&#xe61c;</i>');
  225. $('#iframe-im').hide();
  226. }else{
  227. $im.addClass('show').animate({
  228. right: 0
  229. },300);
  230. /*$iframe.animate({
  231. width: $(window).width()-260
  232. },300);*/
  233. $iframeTab.animate({
  234. width: $(window).width()-260
  235. },300);
  236. $arrow.css('left',"0px").html('<i class="iconfont">&#xe608;</i>');
  237. }
  238. }
  239. (function($) {
  240. // 选项卡
  241. $.fn.tabs = function(options) {
  242. if (this.length == 0)
  243. return this;
  244. if (this.length > 1) {
  245. this.each(function() {
  246. $(this).tabs(options)
  247. });
  248. return this;
  249. }
  250. if ($(this).data('binds') == 'yes')
  251. return false;
  252. $(this).data('binds', 'yes');
  253. var defaults = {};
  254. var opts = $.extend(defaults, options || {});
  255. var $this = $(this), $hd = $this.children('div.tabs-hd').children('a'), $bd = $this
  256. .children('div.tabs-bd').children('div.tabs-bd-box');
  257. $hd.on('click', function() {
  258. var $el = $(this), index = $el.index();
  259. $el.addClass('curr').siblings().removeClass('curr');
  260. $bd.eq(index).addClass('curr').siblings().removeClass('curr');
  261. if (opts.callback) {
  262. opts.callback(index);
  263. }
  264. });
  265. }
  266. })(jQuery);
  267. // 函数节流
  268. function throttle(fn, delay) {
  269. var timer = null;
  270. return function() {
  271. var context = this, args = arguments;
  272. clearTimeout(timer);
  273. timer = setTimeout(function() {
  274. fn.apply(context, args);
  275. }, delay);
  276. };
  277. };
  278. function searchInfo() {
  279. var orgId = $(".c-f20.c-fff").attr("data-orgid");// myInfo.orgInfo;
  280. var name = jQuery.trim($('input[data-im="search"]').val());
  281. if (name != '') {
  282. $.ajax({
  283. url : "staff/search",
  284. dataType : "json",
  285. type : 'POST',
  286. data : {
  287. orgId : orgId,
  288. name : name
  289. },
  290. success : function(data) {
  291. $("#search_friend_result").html("");
  292. if (data) {
  293. if (data.Code == 10000) {
  294. if (data.Result && data.Result != '') {
  295. var ul = "<ul>";
  296. var liListStr = "";
  297. for ( var i in data.Result) {
  298. var item = data.Result[i];
  299. var clientId = item.clientId;
  300. var photoUri = item.photoUri;
  301. if (photoUri == undefined) {
  302. photoUri = "images/face.png";
  303. }
  304. var liStr = [
  305. "<li class=\"boss-user\" data-clientid=\""
  306. + clientId + "\">",
  307. "<a href=\"javascript:;\" onclick=\"showChat('"
  308. + clientId + "');\" >",
  309. '<div class=\"boss-user-face\"><img class=\"c-images-block\" src="'
  310. + photoUri + '"/></div>',
  311. '<div class=\"boss-user-name c-nowrap c-f14 c-333\">'
  312. + item.cName + '</div>',
  313. '</a>', "</li>" ];
  314. liListStr += liStr.join("");
  315. memberInfos[clientId] = {
  316. "data-id" : item.userID,
  317. "data-name" : item.cName,
  318. "data-clientId" : clientId,
  319. "data-photoUri" : photoUri,
  320. "data-sex" : item.sex
  321. };
  322. }
  323. ul += liListStr + "</ul>";
  324. $("#search_friend_result").append(ul);
  325. }
  326. }else {
  327. //showMsg("系统繁忙,请稍候再试");
  328. }
  329. } else {
  330. //showMsg("系统繁忙,请稍候再试");
  331. }
  332. },
  333. error : function(errorData) {
  334. //showMsg("系统繁忙,请稍候再试");
  335. }
  336. });
  337. } else {
  338. $("#search_friend_result").html("");
  339. }
  340. }
  341. function imClosed() {
  342. $('#talking_box').hide();
  343. $('#iframe-userInfo').hide();
  344. $('#iframe-im').hide();
  345. if($.browser.msie&&($.browser.version == "8.0")){
  346. }else{
  347. $('#iframe-userInfo').attr("src", "");
  348. }
  349. resetStructure();
  350. }
  351. function showIframe(src) {
  352. if ($('#iframe-userInfo').attr("src") == ''
  353. || $('#iframe-userInfo').attr("src") != src) {
  354. $('#iframe-userInfo').attr("src", src);
  355. }
  356. resetStructure();
  357. $('#talking_box').hide();
  358. $('#iframe-userInfo').show();
  359. $('#iframe-im').show();
  360. }
  361. function resetStructure() {
  362. Structure.tarClientId = "";
  363. Structure.topic_id = "";
  364. Structure.cName = "";
  365. Structure.id = "";
  366. Structure.photoUri = "";
  367. Structure.sex = "";
  368. Structure.isGroup = false;
  369. }
  370. // 弹出框
  371. function showMsg(content) {
  372. art.dialog({
  373. lock : true,
  374. artIcon : 'ask',
  375. opacity : 0.4,
  376. width : 250,
  377. title : '提示',
  378. content : content,
  379. ok : function() {
  380. }
  381. });
  382. }
  383. // 弹出框
  384. function showHideMsg(content, time) {
  385. art.dialog({
  386. lock : true,
  387. artIcon : 'ask',
  388. opacity : 0.4,
  389. width : 250,
  390. title : '提示',
  391. time : time,
  392. content : content,
  393. ok : function() {
  394. }
  395. });
  396. }
  397. function iframeMenuList() {
  398. var $menu = $('.iframe-menu-list'), $li = $menu.children('ul')
  399. .children('li'), $wrap = $('.iframe-menu'), w;
  400. if ($('.boss-im').is('.show')) {
  401. w = $(window).width() - 260;
  402. } else {
  403. w = $(window).width();
  404. }
  405. if ($li.length * 181 > w) {
  406. $menu.width($li.length * 181);
  407. $('.iframe-menu-btn').show();
  408. // iframe-menu
  409. $('.iframe-menu-btn>a.prev').on('click', function() {
  410. var left = $('.iframe-menu-list').data('left') * 1;
  411. if (left == 0) {
  412. return false;
  413. } else if (left < 0) {
  414. $('.iframe-menu-list').animate({
  415. 'left' : left + 180
  416. }, "fast", function() {
  417. $('.iframe-menu-list').data('left', left + 180);
  418. });
  419. }
  420. });
  421. $('.iframe-menu-btn>a.next').on('click', function() {
  422. var left = $('.iframe-menu-list').data('left') * 1;
  423. if (left < -(($('.iframe-menu-list>ul>li').length - 2) * 180)) {
  424. return false;
  425. } else if (left <= 0) {
  426. $('.iframe-menu-list').animate({
  427. 'left' : left - 180
  428. }, "fast", function() {
  429. $('.iframe-menu-list').data('left', left - 180);
  430. });
  431. }
  432. });
  433. }
  434. }