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.
 
 
 
 
 
 

225 lines
9.8 KiB

  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. var et = e.target || e.srcElement;
  101. var $et = $(et);
  102. if (et.tagName === 'IMG' || et.tagName === 'SPAN') {
  103. $et = $et.parent();
  104. }
  105. var $list = $('<div class="lr-user-list" ></div>');
  106. var flag = false;
  107. var id = $et.attr('data-value');
  108. if ($et.hasClass('company')) {
  109. if ($et.hasClass('bottom')) {
  110. $et.removeClass('bottom');
  111. $et.parent().find('.lr-user-list').remove();
  112. }
  113. else {
  114. $list.css({ 'padding-left': '10px' });
  115. // 加载人员
  116. $.each(userMap[id] || [], function (_index, _item) {
  117. var _html = '\
  118. <div class="lr-list-item user" data-value="'+ _item.id + '" >\
  119. <img src="'+ getHeadImg(_item) + '" >\
  120. <span >' + _item.name + '('+_item.mobile+')</span>\
  121. </div>';
  122. $list.append(_html);
  123. flag = true;
  124. });
  125. // 加载部门
  126. $.each(departmentMap[id] || [], function (_index, _item) {
  127. var _html = '\
  128. <div class="lr-list-item" >\
  129. <a class="lr-nav-left department" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  130. </div>';
  131. $list.append(_html);
  132. flag = true;
  133. });
  134. // 加载公司
  135. $.each(companyMap[id] || [], function (_index, _item) {
  136. var _html = '\
  137. <div class="lr-list-item" >\
  138. <a class="lr-nav-left company" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  139. </div>';
  140. $list.append(_html);
  141. flag = true;
  142. });
  143. if (flag) {
  144. $et.parent().append($list);
  145. }
  146. $et.addClass('bottom');
  147. }
  148. $list = null;
  149. return false;
  150. }
  151. else if ($et.hasClass('department')) {
  152. if ($et.hasClass('bottom')) {
  153. $et.removeClass('bottom');
  154. $et.parent().find('.lr-user-list').remove();
  155. }
  156. else {
  157. $list.css({ 'padding-left': '10px' });
  158. // 加载人员
  159. $.each(userMap[id] || [], function (_index, _item) {
  160. var _html = '\
  161. <div class="lr-list-item user" data-value="'+ _item.id + '" >\
  162. <img src="'+ getHeadImg(_item) + '" >\
  163. <span >' + _item.name + '('+_item.mobile+')</span>\
  164. </div>';
  165. $list.append(_html);
  166. flag = true;
  167. });
  168. // 加载部门
  169. $.each(departmentMap[id] || [], function (_index, _item) {
  170. var _html = '\
  171. <div class="lr-list-item" >\
  172. <a class="lr-nav-left department" data-value="'+ _item.id + '" >' + _item.name + '</a>\
  173. </div>';
  174. $list.append(_html);
  175. flag = true;
  176. });
  177. if (flag) {
  178. $et.parent().append($list);
  179. }
  180. $et.addClass('bottom');
  181. }
  182. $list = null;
  183. return false;
  184. }
  185. // else if ($et.hasClass('user')) {
  186. // var userName = $et.find('span').text();
  187. // learun.nav.go({ path: 'chat', title: userName, isBack: true, isHead: true, param: { hasHistory: true, userId: id }, type: 'right' });
  188. // $list = null;
  189. // return false;
  190. // }
  191. });
  192. // 点击搜索框
  193. $page.find('.searchBox').on('tap', function () {
  194. learun.nav.go({ path: 'contacts/search', title: '', isBack: true, isHead: true });
  195. });
  196. },
  197. destroy: function (pageinfo) {
  198. companyMap = null;
  199. departmentMap = null;
  200. userMap = null;
  201. }
  202. };
  203. return page;
  204. })();