You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

837 lines
38 KiB

  1. /*
  2. * 版 本 Learun-ADMS V7.0.0 数字化智慧校园(http://www.learun.cn)
  3. * Copyright (c) 2013-2018 北京泉江科技有限公司
  4. * 创建人:数字化智慧校园-前端开发组
  5. * 日 期:2017.03.16
  6. * 描 述:window窗口皮肤
  7. */
  8. var bootstrap = function ($, learun) {
  9. "use strict";
  10. var isInit = false;
  11. // 菜单操作
  12. var meuns = {
  13. init: function () {
  14. var $menuwarp = $('.lr-frame-menu');
  15. if ($menuwarp != undefined && $('#lr_second_menu_wrap').length == 0) {
  16. $menuwarp.append('<div class="lr-second-menu-wrap" id="lr_second_menu_wrap"></div><div class="lr-frame-menu-overlay" id="lr_frame_menu_overlay"></div>');
  17. }
  18. this.load();
  19. this.bind();
  20. },
  21. load: function () {
  22. var modulesTree = learun.clientdata.get(['modulesTree']);
  23. // 第一级菜单
  24. var parentId = '0';
  25. var modules = modulesTree[parentId] || [];
  26. var $firstmenus = $('<ul class="lr-first-menu-list"></ul>');
  27. for (var i = 0, l = modules.length; i < l; i++) {
  28. var item = modules[i];
  29. if (item.F_IsMenu == 1) {
  30. var $applistul = $('<ul></ul>');// 应用列表
  31. if (item.F_Target != 'expand') {
  32. $applistul.append(meuns.getAppItem(item));
  33. }
  34. var $firstMenuItem = $('<li></li>');
  35. if (!!item.F_Description) {
  36. $firstMenuItem.attr('title', item.F_Description);
  37. }
  38. var menuItemHtml = '<a id="' + item.F_ModuleId + '" href="javascript:void(0);" class="lr-menu-item">';
  39. menuItemHtml += '<i class="' + item.F_Icon + ' lr-menu-item-icon"></i>';
  40. menuItemHtml += '<span class="lr-menu-item-text">' + item.F_FullName + '</span>';
  41. menuItemHtml += '<span class="lr-menu-item-arrow"></span></a>';
  42. $firstMenuItem.append(menuItemHtml);
  43. // 第二级菜单
  44. var secondModules = modulesTree[item.F_ModuleId] || [];
  45. var $secondMenus = $('<ul class="lr-second-menu-list"></ul>');
  46. var secondMenuHad = false;
  47. for (var j = 0, sl = secondModules.length; j < sl; j++) {
  48. var secondItem = secondModules[j];
  49. if (secondItem.F_IsMenu == 1) {
  50. if (secondItem.F_Target != 'expand') {
  51. $applistul.append(meuns.getAppItem(secondItem));
  52. }
  53. secondMenuHad = true;
  54. var $secondMenuItem = $('<li></li>');
  55. if (!!secondItem.F_Description) {
  56. $secondMenuItem.attr('title', secondItem.F_Description);
  57. }
  58. var secondItemHtml = '<a id="' + secondItem.F_ModuleId + '" href="javascript:void(0);" class="lr-menu-item" >';
  59. secondItemHtml += '<i class="' + secondItem.F_Icon + ' lr-menu-item-icon"></i>';
  60. secondItemHtml += '<span class="lr-menu-item-text">' + secondItem.F_FullName + '</span>';
  61. secondItemHtml += '</a>';
  62. $secondMenuItem.append(secondItemHtml);
  63. // 第三级菜单
  64. var threeModules = modulesTree[secondItem.F_ModuleId] || [];
  65. var $threeMenus = $('<ul class="lr-three-menu-list"></ul>');
  66. var threeMenuHad = false;
  67. for (var m = 0, tl = threeModules.length; m < tl; m++) {
  68. var threeItem = threeModules[m];
  69. if (threeItem.F_IsMenu == 1) {
  70. if (threeItem.F_Target != 'expand') {
  71. $applistul.append(meuns.getAppItem(threeItem));
  72. }
  73. threeMenuHad = true;
  74. var $threeMenuItem = $('<li></li>');
  75. $threeMenuItem.attr('title', threeItem.F_FullName);
  76. var threeItemHtml = '<a id="' + threeItem.F_ModuleId + '" href="javascript:void(0);" class="lr-menu-item" >';
  77. threeItemHtml += '<i class="' + threeItem.F_Icon + ' lr-menu-item-icon"></i>';
  78. threeItemHtml += '<span class="lr-menu-item-text">' + threeItem.F_FullName + '</span>';
  79. threeItemHtml += '</a>';
  80. $threeMenuItem.append(threeItemHtml);
  81. $threeMenus.append($threeMenuItem);
  82. }
  83. }
  84. if (threeMenuHad) {
  85. $secondMenuItem.addClass('lr-meun-had');
  86. $secondMenuItem.find('a').append('<span class="lr-menu-item-arrow"><i class="fa fa-angle-left"></i></span>');
  87. $secondMenuItem.append($threeMenus);
  88. }
  89. $secondMenus.append($secondMenuItem);
  90. }
  91. }
  92. if (secondMenuHad) {
  93. $secondMenus.attr('data-value', item.F_ModuleId);
  94. $('#lr_second_menu_wrap').append($secondMenus);
  95. }
  96. $firstmenus.append($firstMenuItem);
  97. if ($applistul.find('li').length > 0) {
  98. $("#lr_applist_slidebox").append($applistul);
  99. $(".lr-applist-slidebox-slider-content").append('<li><i class="fa fa-circle"></i></li>');
  100. }
  101. }
  102. }
  103. $('#lr_frame_menu').html($firstmenus);
  104. // 语言包翻译
  105. $('.lr-menu-item-text').each(function () {
  106. var $this = $(this);
  107. var text = $this.text();
  108. learun.language.get(text, function (_text) {
  109. $this.text(_text);
  110. $this.parent().parent().attr('title', _text);
  111. });
  112. });
  113. $('.icon-text').each(function () {
  114. var $this = $(this);
  115. var text = $this.text() || '';
  116. learun.language.get(text.replace(/^\s+|\s+$/g, ""), function (_text) {
  117. $this.text(_text);
  118. });
  119. });
  120. },
  121. bind: function () {
  122. $("#lr_frame_menu").lrscroll();
  123. $("#lr_second_menu_wrap").lrscroll();
  124. $('#lr_windows_start').on('click', meuns.startMenuClick);
  125. $('#lr_frame_menu_overlay').on('click', meuns.startMenuClick);
  126. // 添加点击事件
  127. $('#lr_frame_menu a').on('click', function () {
  128. var $obj = $(this);
  129. var id = $obj.attr('id');
  130. var _module = learun.clientdata.get(['modulesMap', id]);
  131. switch (_module.F_Target) {
  132. case 'iframe':// 窗口
  133. meuns.startMenuClick();
  134. setTimeout(function () {
  135. if (learun.validator.isNotNull(_module.F_UrlAddress).code) {
  136. learun.frameTab.open(_module);
  137. }
  138. else {
  139. }
  140. }, 250);
  141. break;
  142. case 'expand':
  143. var $li = $obj.parent();
  144. if (!$li.hasClass('active')) {
  145. $('#lr_frame_menu li.active').removeClass('active');
  146. $li.addClass('active');
  147. $('#lr_second_menu_wrap .lr-second-menu-list').hide();
  148. $('#lr_second_menu_wrap .lr-second-menu-list[data-value="' + _module.F_ModuleId + '"]').show();
  149. }
  150. break;
  151. }
  152. });
  153. $('#lr_second_menu_wrap a').on('click', function () {
  154. var $obj = $(this);
  155. var id = $obj.attr('id');
  156. var _module = learun.clientdata.get(['modulesMap', id]);
  157. switch (_module.F_Target) {
  158. case 'iframe':// 窗口
  159. meuns.startMenuClick();
  160. setTimeout(function () {
  161. if (learun.validator.isNotNull(_module.F_UrlAddress).code) {
  162. learun.frameTab.open(_module);
  163. }
  164. else {
  165. }
  166. }, 250);
  167. break;
  168. case 'expand':
  169. var $ul = $obj.next();
  170. if ($ul.is(':visible')) {
  171. $ul.slideUp(500, function () {
  172. $obj.removeClass('open');
  173. });
  174. }
  175. else {
  176. $ul.parents('.lr-second-menu-list').find('.lr-three-menu-list').slideUp(300, function () {
  177. $(this).prev().removeClass('open');
  178. });
  179. $ul.slideDown(300, function () {
  180. $obj.addClass('open');
  181. });
  182. }
  183. break;
  184. }
  185. });
  186. $('.lr-first-menu-list>li').eq(0).find('a').trigger('click');
  187. $(".lr-applist-slidebox-slider-content li").click(function () {
  188. var $this = $(this);
  189. if (!$this.hasClass("active")) {
  190. var $oldli = $(".lr-applist-slidebox-slider-content li.active");
  191. $oldli.removeClass("active");
  192. $this.addClass("active");
  193. var oldindex = $oldli.index();
  194. var index = $(this).index();
  195. $("#lr_applist_slidebox ul").eq(oldindex).hide();
  196. $("#lr_applist_slidebox ul").eq(index).fadeIn("slow");
  197. }
  198. });
  199. $('#lr_applist_btn').on('click', function () {
  200. meuns.openApplist();
  201. });
  202. $('#lr_applist_slidebox .appItem').on('click', function () {
  203. var $obj = $(this);
  204. var id = $obj.attr('data-id');
  205. var _module = learun.clientdata.get(['modulesMap', id]);
  206. if (learun.validator.isNotNull(_module.F_UrlAddress).code) {
  207. learun.frameTab.open(_module);
  208. }
  209. });
  210. $('#lr_applist_content').hide();
  211. $(".lr-applist-slidebox-slider-content li").eq(0).trigger('click');
  212. //learun.frameTab.leaveFocus();
  213. },
  214. startMenuClick: function () {
  215. debugger;
  216. var $lr_frame_menu = $('.lr-frame-menu');
  217. if (!isInit) {
  218. isInit = true;
  219. $lr_frame_menu.show();
  220. } else {
  221. if ($lr_frame_menu.is(':visible')) {
  222. $lr_frame_menu.show();
  223. }
  224. else {
  225. $lr_frame_menu.hide();
  226. }
  227. //$lr_frame_menu.slideToggle(300);
  228. }
  229. },
  230. getAppItem: function (item) {
  231. var colorindex = Math.round(Math.random() * 9 + 1);
  232. var _html = '';
  233. _html += '<li class="appItem" data-id="' + item.F_ModuleId + '" href="' + item.F_UrlAddress + '">';
  234. _html += '<div class="icon" >';
  235. _html += '<i class="fa ' + item.F_Icon + '"></i>';
  236. _html += '</div>';
  237. _html += '<div class="icon-text">';
  238. _html += item.F_FullName;
  239. _html += '</div>';
  240. _html += '</li>';
  241. return _html;
  242. },
  243. closeApplist: function () {
  244. var appBtn = $('#lr_applist_btn');
  245. if (!appBtn.hasClass('off')) {
  246. $('#lr_applist_btn').addClass('off');
  247. $('#lr_applist_content').hide();
  248. }
  249. },
  250. openApplist: function () {
  251. var appBtn = $('#lr_applist_btn');
  252. if (appBtn.hasClass('off')) {
  253. learun.frameTab.leaveFocus();
  254. $('#lr_applist_btn').removeClass('off');
  255. $('#lr_applist_content').show();
  256. }
  257. }
  258. };
  259. learun.frameTab.opencallback = function () {
  260. meuns.closeApplist();
  261. };
  262. learun.frameTab.closecallback = function () {
  263. if (learun.frameTab.iframeId == '') {
  264. meuns.openApplist();
  265. }
  266. };
  267. meuns.init();
  268. var companyMap = {};
  269. var departmentMap = {};
  270. var userMap = {};
  271. var imUserId = '';
  272. var getHeadImg = function (user) {
  273. var url = top.$.rootUrl;
  274. switch (user.img) {
  275. case '0':
  276. url += '/Content/images/head/on-girl.jpg';
  277. break;
  278. case '1':
  279. url += '/Content/images/head/on-boy.jpg';
  280. break;
  281. default:
  282. url += '/LR_OrganizationModule/User/GetImg?userId=' + user.id;
  283. break;
  284. }
  285. return url;
  286. };
  287. // 发送聊天信息
  288. var sendMsg = function (msg, time) {
  289. var loginInfo = learun.clientdata.get(['userinfo']);
  290. learun.clientdata.getAsync('user', {
  291. key: loginInfo.userId,
  292. callback: function (data, op) {
  293. data.id = op.key;
  294. var _html = '\
  295. <div class="me im-time">'+ (time || '') + '</div>\
  296. <div class="im-me">\
  297. <div class="headimg"><img src="'+ getHeadImg(data) + '"></div>\
  298. <div class="arrow"></div>\
  299. <span class="content">'+ msg + '</span>\
  300. </div>';
  301. $('.lr-im-msgcontent .lr-scroll-box').append(_html);
  302. $('.lr-im-msgcontent').lrscrollSet('moveBottom');
  303. }
  304. });
  305. };
  306. // 接收聊天消息
  307. var revMsg = function (userId, msg, time) {
  308. learun.clientdata.getAsync('user', {
  309. key: userId,
  310. callback: function (data, op) {
  311. data.id = op.key;
  312. var _html = '\
  313. <div class="im-time">'+ (time || '') + '</div>\
  314. <div class="im-other">\
  315. <div class="headimg"><img src="'+ getHeadImg(data) + '"></div>\
  316. <div class="arrow"></div>\
  317. <span class="content">'+ msg + '</span>\
  318. </div>';
  319. $('.lr-im-msgcontent .lr-scroll-box').append(_html);
  320. $('.lr-im-msgcontent').lrscrollSet('moveBottom');
  321. }
  322. });
  323. };
  324. var getTime = function (time) {
  325. var d = new Date();
  326. var c = d.DateDiff('d', time);
  327. if (c <= 1) {
  328. return learun.formatDate(time, 'hh:mm:ss');
  329. }
  330. else {
  331. return learun.formatDate(time, 'yyyy/MM/dd');
  332. }
  333. }
  334. // 即时通讯
  335. var im = {
  336. init: function () {
  337. this.bind();
  338. this.load();
  339. },
  340. load: function () {
  341. // 获取下公司列表
  342. learun.clientdata.getAllAsync('company', {
  343. callback: function (data) {
  344. $.each(data, function (_id, _item) {
  345. companyMap[_item.parentId] = companyMap[_item.parentId] || [];
  346. _item.id = _id;
  347. companyMap[_item.parentId].push(_item);
  348. });
  349. var $list = $('#lr_im_content_userlist .lr-scroll-box');
  350. $.each(companyMap["0"], function (_index, _item) {
  351. var _html = '\
  352. <div class="lr-im-company-item">\
  353. <div class="lr-im-item-name lr-im-company" data-value="'+ _item.id + '" data-deep="0" >\
  354. <i class="fa fa-angle-right"></i>'+ _item.name + '\
  355. </div>\
  356. </div>';
  357. $list.append(_html);
  358. });
  359. // 获取部门列表
  360. learun.clientdata.getAllAsync('department', {
  361. callback: function (data) {
  362. $.each(data, function (_id, _item) {
  363. _item.id = _id;
  364. if (_item.parentId == "0") {
  365. departmentMap[_item.companyId] = departmentMap[_item.companyId] || [];
  366. departmentMap[_item.companyId].push(_item);
  367. }
  368. else {
  369. departmentMap[_item.parentId] = departmentMap[_item.parentId] || [];
  370. departmentMap[_item.parentId].push(_item);
  371. }
  372. });
  373. // 获取人员数据
  374. learun.clientdata.getAllAsync('user', {
  375. callback: function (data) {
  376. $.each(data, function (_id, _item) {
  377. _item.id = _id;
  378. if (_item.departmentId) {
  379. userMap[_item.departmentId] = userMap[_item.departmentId] || [];
  380. userMap[_item.departmentId].push(_item);
  381. }
  382. else if (_item.companyId) {
  383. userMap[_item.companyId] = userMap[_item.companyId] || [];
  384. userMap[_item.companyId].push(_item);
  385. }
  386. });
  387. // 获取最近联系人列表
  388. learun.im.getContacts(function (data) {
  389. var $userList = $('#lr_immsg_userlist .lr-scroll-box');
  390. $.each(data, function (_index, _item) {
  391. var html = '\
  392. <div class="msg-item'+ (_item.F_IsRead == '1' ? 'imHasMsg' : '') + '" data-value="' + _item.F_OtherUserId + '" >\
  393. <div class="photo">\
  394. <img src="'+ top.$.rootUrl + '/Content/images/head/on-boy.jpg">\
  395. <div class="point"></div>\
  396. </div>\
  397. <div class="name"></div>\
  398. <div class="msg">'+ (_item.F_Content || '') + '</div>\
  399. <div class="date">'+ getTime(_item.F_Time) + '</div>\
  400. </div>';
  401. $userList.append(html);
  402. learun.clientdata.getAsync('user', {
  403. key: _item.F_OtherUserId,
  404. callback: function (data, op) {
  405. var $item = $userList.find('[data-value="' + op.key + '"]');
  406. $item.find('.name').text(data.name);
  407. data.id = op.key;
  408. $item.find('img').attr('src', getHeadImg(data));
  409. $item = null;
  410. }
  411. });
  412. });
  413. });
  414. }
  415. });
  416. }
  417. });
  418. }
  419. });
  420. },
  421. bind: function () {
  422. $('#lr_immsg_userlist').lrscroll();
  423. $('#lr_im_content_userlist').lrscroll();
  424. $('.lr-im-msgcontent').lrscroll();
  425. // 打开关闭聊天窗
  426. $('.lr-im-bell').on('click', function () {
  427. var $this = $(this);
  428. if ($this.hasClass('open')) {
  429. $this.removeClass('open');
  430. $('.lr-im-body').removeClass('open');
  431. $('.lr-im-black-overlay').hide();
  432. imUserId = '';
  433. }
  434. else {
  435. $this.addClass('open');
  436. $('.lr-im-bell .point').hide();
  437. $('.lr-im-body').addClass('open');
  438. }
  439. });
  440. // 最近消息 与 联系人之间的切换
  441. $('.lr-im-title .title-item').on('click', function () {
  442. var $this = $(this);
  443. if (!$this.hasClass('active')) {
  444. $('.lr-im-body>.active').removeClass('active');
  445. $('.lr-im-title>.active').removeClass('active');
  446. $this.addClass('active');
  447. var v = $this.attr('data-value');
  448. $('#' + v).addClass('active');
  449. }
  450. });
  451. // 联系人
  452. $('#lr_im_content_userlist .lr-scroll-box').on('click', function (e) {
  453. e = e || window.event;
  454. var et = e.target || e.srcElement;
  455. var $et = $(et);
  456. if (et.tagName == 'IMG' || et.tagName == 'I') {
  457. $et = $et.parent();
  458. }
  459. if ($et.hasClass('lr-im-company')) {// 点击公司项
  460. // 判断是否是打开的状态
  461. if ($et.hasClass('open')) {
  462. $et.removeClass('open');
  463. $et.parent().find('.lr-im-user-list').remove();
  464. } else {
  465. var id = $et.attr('data-value');
  466. var deep = parseInt($et.attr('data-deep'));
  467. var $list = $('<div class="lr-im-user-list" ></div>');
  468. $list.css({ 'padding-left': '10px' });
  469. var flag = false;
  470. // 加载员工
  471. $.each(userMap[id] || [], function (_index, _item) {
  472. var _html = '\
  473. <div class="lr-im-company-item">\
  474. <div class="lr-im-item-name lr-im-user" data-value="'+ _item.id + '" >\
  475. <img src="'+ getHeadImg(_item) + '" >' + _item.name + '\
  476. </div>\
  477. </div>';
  478. $list.append(_html);
  479. flag = true;
  480. });
  481. // 加载部门
  482. $.each(departmentMap[id] || [], function (_index, _item) {
  483. var _html = '\
  484. <div class="lr-im-company-item">\
  485. <div class="lr-im-item-name lr-im-department" data-value="'+ _item.id + '" data-deep="' + (deep + 1) + '" >\
  486. <i class="fa fa-angle-right"></i>'+ _item.name + '\
  487. </div>\
  488. </div>';
  489. $list.append(_html);
  490. flag = true;
  491. });
  492. // 加载下属公司
  493. $.each(companyMap[id] || [], function (_index, _item) {
  494. var _html = '\
  495. <div class="lr-im-company-item">\
  496. <div class="lr-im-item-name lr-im-company" data-value="'+ _item.id + '" data-deep="' + (deep + 1) + '" >\
  497. <i class="fa fa-angle-right"></i>'+ _item.name + '\
  498. </div>\
  499. </div>';
  500. $list.append(_html);
  501. flag = true;
  502. });
  503. if (flag) {
  504. $et.parent().append($list);
  505. }
  506. $et.addClass('open');
  507. }
  508. return false;
  509. }
  510. else if ($et.hasClass('lr-im-department')) {
  511. // 判断是否是打开的状态
  512. if ($et.hasClass('open')) {
  513. $et.removeClass('open');
  514. $et.parent().find('.lr-im-user-list').remove();
  515. } else {
  516. var id = $et.attr('data-value');
  517. var deep = parseInt($et.attr('data-deep'));
  518. var $list = $('<div class="lr-im-user-list" ></div>');
  519. $list.css({ 'padding-left': '10px' });
  520. var flag = false;
  521. // 加载员工
  522. $.each(userMap[id] || [], function (_index, _item) {
  523. var _html = '\
  524. <div class="lr-im-company-item">\
  525. <div class="lr-im-item-name lr-im-user" data-value="'+ _item.id + '" >\
  526. <img src="'+ getHeadImg(_item) + '" >' + _item.name + '\
  527. </div>\
  528. </div>';
  529. $list.append(_html);
  530. flag = true;
  531. });
  532. // 加载部门
  533. $.each(departmentMap[id] || [], function (_index, _item) {
  534. var _html = '\
  535. <div class="lr-im-company-item">\
  536. <div class="lr-im-item-name lr-im-department" data-value="'+ _item.id + '" data-deep="' + (deep + 1) + '" >\
  537. <i class="fa fa-angle-right"></i>'+ _item.name + '\
  538. </div>\
  539. </div>';
  540. $list.append(_html);
  541. flag = true;
  542. });
  543. if (flag) {
  544. $et.parent().append($list);
  545. }
  546. $et.addClass('open');
  547. }
  548. }
  549. else if ($et.hasClass('lr-im-user')) {
  550. // 如果是用户列表
  551. // 1.打开聊天窗口
  552. // 2.添加一条最近联系人数据(如果没有添加的话)
  553. // 3.获取最近的20条聊天数据或者最近的聊天信息
  554. var id = $et.attr('data-value');
  555. var $userList = $('#lr_immsg_userlist .lr-scroll-box');
  556. var $userItem = $userList.find('[data-value="' + id + '"]');
  557. // 更新下最近的联系人列表数据
  558. $('.lr-im-title .title-item').eq(0).trigger('click');
  559. imUserId = id;
  560. if ($userItem.length > 0) {
  561. $userList.prepend($userItem);
  562. $userItem.trigger('click');
  563. }
  564. else {
  565. var imgurl = $et.find('img').attr('src');
  566. var _html = '\
  567. <div class="msg-item" data-value="' + id + '" >\
  568. <div class="photo">\
  569. <img src="'+ imgurl + '">\
  570. <div class="point"></div>\
  571. </div>\
  572. <div class="name"></div>\
  573. <div class="msg"></div>\
  574. <div class="date"></div>\
  575. </div>';
  576. $userList.prepend(_html);
  577. $userItem = $userList.find('[data-value="' + id + '"]');
  578. // 获取人员数据
  579. learun.clientdata.getAsync('user', {
  580. key: id,
  581. callback: function (data, op) {
  582. $userList.find('[data-value="' + op.key + '"] .name').text(data.name);
  583. $userItem.trigger('click');
  584. }
  585. });
  586. learun.im.addContacts(id);
  587. }
  588. }
  589. });
  590. // 最近联系人列表点击
  591. $('#lr_immsg_userlist .lr-scroll-box').on('click', function (e) {
  592. e = e || window.event;
  593. var et = e.target || e.srcElement;
  594. var $et = $(et);
  595. if (!$et.hasClass('msg-item')) {
  596. $et = $et.parents('.msg-item');
  597. }
  598. if ($et.length > 0) {
  599. if (!$et.hasClass('active')) {
  600. var name = $et.find('.name').text();
  601. imUserId = $et.attr('data-value');
  602. $('#lr_immsg_userlist .lr-scroll-box .active').removeClass('active');
  603. $et.addClass('active');
  604. $('.lr-im-black-overlay').show();
  605. var $imdialog = $('.lr-im-dialog');
  606. $imdialog.find('.im-title').text("与" + name + "对话中");
  607. $('#lr_im_input').val('');
  608. $('#lr_im_input').select();
  609. $('.lr-im-msgcontent .lr-scroll-box').html('');
  610. // 获取聊天信息
  611. learun.im.getMsgList(imUserId, function (data) {
  612. var len = data.length;
  613. if (len > 0) {
  614. for (var i = len - 1; i >= 0; i--) {
  615. var _item = data[i];
  616. learun.clientdata.getAsync('user', {
  617. key: _item.userId,
  618. msg: _item.content,
  619. time: _item.time,
  620. callback: function (data, op) {
  621. data.id = op.key;
  622. var loginInfo = learun.clientdata.get(['userinfo']);
  623. var _html = '\
  624. <div class="im-time '+ (loginInfo.userId == op.key ? 'me' : '') + ' ">' + op.time + '</div>\
  625. <div class="'+ (loginInfo.userId == op.key ? 'im-me' : 'im-other') + '">\
  626. <div class="headimg"><img src="'+ getHeadImg(data) + '"></div>\
  627. <div class="arrow"></div>\
  628. <span class="content">'+ op.msg + '</span>\
  629. </div>';
  630. $('.lr-im-msgcontent .lr-scroll-box').prepend(_html);
  631. }
  632. });
  633. }
  634. $('.lr-im-msgcontent').lrscrollSet('moveBottom');
  635. }
  636. }, $et.hasClass('imHasMsg'));
  637. $et.removeClass('imHasMsg');
  638. learun.im.updateContacts(imUserId);
  639. }
  640. }
  641. });
  642. // 联系人搜索
  643. $('.lr-im-search input').on("keypress", function (e) {
  644. e = e || window.event;
  645. if (e.keyCode == "13") {
  646. var $this = $(this);
  647. var keyword = $this.val();
  648. var $list = $('#lr_im_content_userlist .lr-scroll-box');
  649. $list.html("");
  650. if (keyword) {
  651. learun.clientdata.getAllAsync('user', {
  652. callback: function (data) {
  653. $.each(data, function (_index, _item) {
  654. if (_item.name.indexOf(keyword) != -1) {
  655. _item.id = _index;
  656. var _html = '\
  657. <div class="lr-im-company-item">\
  658. <div class="lr-im-item-name lr-im-user" data-value="'+ _item.id + '" >\
  659. <img src="'+ getHeadImg(_item) + '" >' + _item.name + '\
  660. </div>\
  661. </div>';
  662. $list.append(_html);
  663. }
  664. });
  665. }
  666. });
  667. }
  668. else {
  669. $.each(companyMap["0"], function (_index, _item) {
  670. var _html = '\
  671. <div class="lr-im-company-item">\
  672. <div class="lr-im-item-name lr-im-company" data-value="'+ _item.id + '" data-deep="0" >\
  673. <i class="fa fa-angle-right"></i>'+ _item.name + '\
  674. </div>\
  675. </div>';
  676. $list.append(_html);
  677. });
  678. }
  679. }
  680. });
  681. // 发送消息
  682. $('#lr_im_input').on("keypress", function (e) {
  683. e = e || window.event;
  684. if (e.keyCode == "13") {
  685. var text = $(this).val();
  686. $(this).val('');
  687. if (text.replace(/(^\s*)|(\s*$)/g, "") != '') {
  688. var time = learun.im.sendMsg(imUserId, text);
  689. sendMsg(text, time);
  690. var $userItem = $('#lr_immsg_userlist .lr-scroll-box [data-value="' + imUserId + '"]');
  691. $userItem.find('.msg').text(text);
  692. $userItem.find('.date').text(getTime(learun.getDate('yyyy-MM-dd hh:mm:ss')));
  693. $userItem = null;
  694. }
  695. return false;
  696. }
  697. });
  698. // 注册消息接收
  699. learun.im.registerRevMsg(function (userId, msg, dateTime) {
  700. var $userList = $('#lr_immsg_userlist .lr-scroll-box');
  701. var $userItem = $userList.find('[data-value="' + userId + '"]');
  702. // 判断当前账号是否打开聊天窗口
  703. if (userId == imUserId) {
  704. revMsg(userId, msg, dateTime);
  705. learun.im.updateContacts(userId);
  706. $userItem.find('.msg').text(msg);
  707. $userItem.find('.date').text(getTime(dateTime));
  708. }
  709. else {
  710. if ($userItem.length > 0) {
  711. $userList.prepend($userItem);
  712. if (!$userItem.hasClass('imHasMsg')) {
  713. $userItem.addClass('imHasMsg');
  714. }
  715. $userItem.find('.msg').text(msg);
  716. $userItem.find('.date').text(getTime(dateTime));
  717. }
  718. else {
  719. var html = '\
  720. <div class="msg-item" data-value="' + userId + '" >\
  721. <div class="photo">\
  722. <img src="'+ top.$.rootUrl + '/Content/images/head/on-boy.jpg">\
  723. <div class="point"></div>\
  724. </div>\
  725. <div class="name"></div>\
  726. <div class="msg">'+ msg + '</div>\
  727. <div class="date">'+ getTime(dateTime) + '</div>\
  728. </div>';
  729. $userList.prepend(html);
  730. learun.clientdata.getAsync('user', {
  731. key: userId,
  732. callback: function (data, op) {
  733. var $item = $userList.find('[data-value="' + op.key + '"]');
  734. $item.find('.name').text(data.name);
  735. data.id = op.key;
  736. $item.find('img').attr('src', getHeadImg(data));
  737. $item = null;
  738. }
  739. });
  740. }
  741. }
  742. if (!$('.lr-im-bell').hasClass('open')) {
  743. $('.lr-im-bell .point').show();
  744. }
  745. });
  746. // 查看聊天记录
  747. $('#lr_im_look_msg_btn').on('click', function () {
  748. learun.layerForm({
  749. id: 'LookMsgIndex',
  750. title: '查看聊天记录-' + $('#lr_im_msglist .lr-im-right .lr-im-touser').text(),
  751. url: top.$.rootUrl + '/LR_IM/IMMsg/Index?userId=' + imUserId,
  752. width: 800,
  753. height: 500,
  754. maxmin: true,
  755. btn: null
  756. });
  757. });
  758. $('.im-close').on('click', function () {
  759. $('#lr_immsg_userlist .lr-scroll-box [data-value="' + imUserId + '"]').removeClass('active');
  760. $('.lr-im-black-overlay').hide();
  761. imUserId = '';
  762. });
  763. }
  764. };
  765. im.init();
  766. };