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.

contacts.js 9.7 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*页面js模板,必须有init方法*/
  2. (function () {
  3. var companyMap;
  4. var departmentMap;
  5. var userMap;
  6. var getHeadImg = function (user) {
  7. var url = '';
  8. switch (user.img) {
  9. case '0':
  10. url += 'images/on-girl.jpg';
  11. break;
  12. case '1':
  13. url += 'images/on-boy.jpg';
  14. break;
  15. default:
  16. url += config.webapi + 'learun/adms/user/img?data=' + user.id;
  17. break;
  18. }
  19. return url;
  20. };
  21. var page = {
  22. isScroll: true,
  23. init: function ($page) {
  24. companyMap = {};
  25. departmentMap = {};
  26. userMap = {};
  27. var logininfo = learun.storage.get("userinfo");
  28. if (logininfo.baseinfo.Description == "学生") {
  29. //if (true) {
  30. learun.httpget(config.webapi + "learun/adms/user/saveMap", { account: logininfo.baseinfo.account }, function (data) {
  31. if (data) {
  32. $.each(data.data, function (_id, _item) {
  33. userMap["207fa1a9-160c-4943-a89b-8fa4db0547ce"] = userMap["207fa1a9-160c-4943-a89b-8fa4db0547ce"] || [];
  34. userMap["207fa1a9-160c-4943-a89b-8fa4db0547ce"].push(_item);
  35. });
  36. var $list = $page.find('#lr_contact_companylist');
  37. var _html = '\
  38. <div class="lr-list-item" >\
  39. <a class="lr-nav-left company" data-value="207fa1a9-160c-4943-a89b-8fa4db0547ce" >同学</a>\
  40. </div>';
  41. $list.append(_html);
  42. $(".company").trigger("tap");
  43. }
  44. });
  45. } else {
  46. // 公司列表数据初始化
  47. learun.clientdata.getAll('company', {
  48. callback: function (data) {
  49. $.each(data, function (_id, _item) {
  50. companyMap[_item.parentId] = companyMap[_item.parentId] || [];
  51. _item.id = _id;
  52. companyMap[_item.parentId].push(_item);
  53. });
  54. var $list = $page.find('#lr_contact_companylist');
  55. $.each(companyMap["0"], function (_index, _item) {
  56. var _html = '\
  57. <div class="lr-list-item" >\
  58. <a class="lr-nav-left company" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  59. </div>';
  60. $list.append(_html);
  61. });
  62. // 部门列表数据初始化
  63. learun.clientdata.getAll('department', {
  64. callback: function (data) {
  65. $.each(data, function (_id, _item) {
  66. _item.id = _id;
  67. if (_item.parentId === "0") {
  68. departmentMap[_item.companyId] = departmentMap[_item.companyId] || [];
  69. departmentMap[_item.companyId].push(_item);
  70. }
  71. else {
  72. departmentMap[_item.parentId] = departmentMap[_item.parentId] || [];
  73. departmentMap[_item.parentId].push(_item);
  74. }
  75. });
  76. // 人员列表数据初始化
  77. learun.clientdata.getAll('user', {
  78. callback: function (data) {
  79. $.each(data, function (_id, _item) {
  80. _item.id = _id;
  81. if (_item.departmentId) {
  82. userMap[_item.departmentId] = userMap[_item.departmentId] || [];
  83. userMap[_item.departmentId].push(_item);
  84. }
  85. else if (_item.companyId) {
  86. userMap[_item.companyId] = userMap[_item.companyId] || [];
  87. userMap[_item.companyId].push(_item);
  88. }
  89. });
  90. }
  91. });
  92. }
  93. });
  94. }
  95. });
  96. }
  97. // 注册点击事件
  98. $('#lr_contact_companylist').on('tap', function (e) {
  99. e = e || window.event;
  100. console.log(1213);
  101. var et = e.target || e.srcElement;
  102. var $et = $(et);
  103. if (et.tagName === 'IMG' || et.tagName === 'SPAN') {
  104. $et = $et.parent();
  105. }
  106. var $list = $('<div class="lr-user-list" ></div>');
  107. var flag = false;
  108. var id = $et.attr('data-value');
  109. console.log(id);
  110. if ($et.hasClass('company')) {
  111. if ($et.hasClass('bottom')) {
  112. $et.removeClass('bottom');
  113. $et.parent().find('.lr-user-list').remove();
  114. }
  115. else {
  116. $list.css({ 'padding-left': '10px' });
  117. // 加载人员
  118. $.each(userMap[id] || [], function (_index, _item) {
  119. var _html = '\
  120. <div class="lr-list-item user" data-value="'+ _item.id + '" >\
  121. <img src="'+ getHeadImg(_item) + '" >\
  122. <span >' + _item.name + '</span>\
  123. </div>';
  124. $list.append(_html);
  125. flag = true;
  126. });
  127. // 加载部门
  128. $.each(departmentMap[id] || [], function (_index, _item) {
  129. var _html = '\
  130. <div class="lr-list-item" >\
  131. <a class="lr-nav-left department" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  132. </div>';
  133. $list.append(_html);
  134. flag = true;
  135. });
  136. // 加载公司
  137. $.each(companyMap[id] || [], function (_index, _item) {
  138. var _html = '\
  139. <div class="lr-list-item" >\
  140. <a class="lr-nav-left company" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  141. </div>';
  142. $list.append(_html);
  143. flag = true;
  144. });
  145. if (flag) {
  146. $et.parent().append($list);
  147. }
  148. $et.addClass('bottom');
  149. }
  150. $list = null;
  151. return false;
  152. }
  153. else if ($et.hasClass('department')) {
  154. if ($et.hasClass('bottom')) {
  155. $et.removeClass('bottom');
  156. $et.parent().find('.lr-user-list').remove();
  157. }
  158. else {
  159. $list.css({ 'padding-left': '10px' });
  160. // 加载人员
  161. $.each(userMap[id] || [], function (_index, _item) {
  162. var _html = '\
  163. <div class="lr-list-item user" data-value="'+ _item.id + '" >\
  164. <img src="'+ getHeadImg(_item) + '" >\
  165. <span >' + _item.name + '</span>\
  166. </div>';
  167. $list.append(_html);
  168. flag = true;
  169. });
  170. // 加载部门
  171. $.each(departmentMap[id] || [], function (_index, _item) {
  172. var _html = '\
  173. <div class="lr-list-item" >\
  174. <a class="lr-nav-left department" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  175. </div>';
  176. $list.append(_html);
  177. flag = true;
  178. });
  179. if (flag) {
  180. $et.parent().append($list);
  181. }
  182. $et.addClass('bottom');
  183. }
  184. $list = null;
  185. return false;
  186. }
  187. else if ($et.hasClass('user')) {
  188. var userName = $et.find('span').text();
  189. learun.nav.go({ path: 'chat', title: userName, isBack: true, isHead: true, param: { hasHistory: true, userId: id }, type: 'right' });
  190. $list = null;
  191. return false;
  192. }
  193. });
  194. // 点击搜索框
  195. $page.find('.searchBox').on('tap', function () {
  196. learun.nav.go({ path: 'contacts/search', title: '', isBack: true, isHead: true });
  197. });
  198. },
  199. destroy: function (pageinfo) {
  200. companyMap = null;
  201. departmentMap = null;
  202. userMap = null;
  203. }
  204. };
  205. return page;
  206. })();