PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/static/js/page/organization/org_tree_create.js

https://gitlab.com/lyslys34/node_test1
JavaScript | 238 lines | 208 code | 30 blank | 0 comment | 35 complexity | 053ca6f71daed278616c1d725c581931 MD5 | raw file
  1. require.config({
  2. baseUrl: MT.STATIC_ROOT + '/js', urlArgs: 'ver=' + pageVersion
  3. });
  4. require(['module/root'], function (t) {
  5. $(document).ready(function () {
  6. var lastTime;
  7. $(".panel-body").delegate(".js_mis_box", "keyup", function (event) {
  8. lastTime = event.timeStamp;
  9. var misId = $(this).val();
  10. var showResultTag = $(this).parent().children(".mis-search");
  11. setTimeout(function () {
  12. if (lastTime - event.timeStamp == 0) {
  13. var date = new Date();
  14. $.getJSON('/employee/query?q=' + misId).success(function (data) {
  15. var city_list = new Array();
  16. if (data.data.length == 0) {
  17. return;
  18. }
  19. showResultTag.show();
  20. var listTag = showResultTag.find('.mis-search-ul');
  21. listTag.empty();
  22. for (var i in data.data) {
  23. var name = data.data[i].name;
  24. var id = data.data[i].id;
  25. var misId = data.data[i].login;
  26. var realName = name ? name.replace('(' + misId + ')', '') : '';
  27. listTag.append('<li onclick="add_to_input($(this))" class="js_mis_item" uid="' + id + '" misid="' + misId + '" uname="' + name + '" realname="' + realName + '" >' + name + '</li>');
  28. }
  29. }).error(function (data) {
  30. alert.log('网络错误');
  31. });
  32. }
  33. }, 300);
  34. });
  35. $(".panel-body").delegate(".js_mis_box", "focus", function(){
  36. $(this).val('');
  37. var showResultTag = $(this).parent().children(".mis-search");
  38. showResultTag.find(".js_employee_id").val('');
  39. showResultTag.find(".js_mis_id").val('');
  40. showResultTag.find(".js_user_name").val('');
  41. });
  42. add_to_input = function (e) {
  43. var searchBox = e.parents(".mis-search");
  44. searchBox.prev().val(e.text());
  45. searchBox.find(".js_employee_id").val(e.attr('uid'));
  46. searchBox.find(".js_mis_id").val(e.attr('misid'));
  47. searchBox.find(".js_user_name").val(e.attr('realname'));
  48. searchBox.hide();
  49. }
  50. $("#js_save").click(function () {
  51. submit();
  52. });
  53. function bindSubmit() {
  54. $("#js_save").on("click", function () {
  55. submit();
  56. }).removeAttr("disabled");
  57. $(".js_loading").toggleClass("hidden");
  58. }
  59. function unbindSubmit() {
  60. $("#js_save").off("click").attr("disabled", "disabled");
  61. $(".js_loading").toggleClass("hidden");
  62. }
  63. function submit() {
  64. var parentId = $("#parentId").val();
  65. var orgName = $('#orgName').val();
  66. var cityId = $("#cityId").val();
  67. var parentType = $("#parentType").val();
  68. var parentLevelType = $("#parentLevelType").val();
  69. var roleTagList = $(".js_role_list");
  70. var users = []
  71. if (roleTagList) {
  72. $.each(roleTagList, function (index, item) {
  73. var roleCode = $(item).find(".js_role_code").val();
  74. var userItems = $(item).find(".js_user_item");
  75. if (userItems) {
  76. $.each(userItems, function (index1, item1) {
  77. var employeeId = $(item1).find(".js_employee_id").val();
  78. var misId = $(item1).find(".js_mis_id").val();
  79. var userName = $(item1).find(".js_user_name").val();
  80. var phone = $(item1).find(".js_phone_box").val();
  81. var user = {}
  82. user.employeeId = employeeId;
  83. user.bmRoleCode = roleCode;
  84. user.mobile = phone;
  85. user.misId = misId;
  86. user.name = userName;
  87. if (misId != '') {
  88. users.push(user);
  89. }
  90. });
  91. }
  92. });
  93. }
  94. var validFlag = true;
  95. if ($.trim(orgName) == "") {
  96. alert("组织名称不能为空");
  97. return false;
  98. }
  99. if (orgName.length > 30) {
  100. alert("组织名称太长");
  101. return false;
  102. }
  103. if (typeof cityId == 'undefined' || cityId == '' || cityId == 0) {
  104. alert("所在城市不能为空");
  105. return false;
  106. }
  107. var len = users.length;
  108. var misIds = [];
  109. for (var i = 0; i < len; i++) {
  110. var user = users[i];
  111. var misId = user['misId'];
  112. if (misId != "") {
  113. if($.inArray(misId, misIds) > -1) {
  114. alert(misId + '已经输入,请勿重复输入');
  115. return false;
  116. }
  117. if ($.trim(user['mobile']) == '') {
  118. alert('请填写' + misId + '的手机号码');
  119. return false;
  120. }
  121. if (!/^1\d{10}$/.test($.trim(user['mobile']))) {
  122. alert('请正确填写' + misId + '的手机号码');
  123. return false;
  124. }
  125. misIds.push(misId);
  126. }
  127. }
  128. var data = {}
  129. data.parentId = parentId;
  130. data.orgName = orgName;
  131. data.parentType = parentType;
  132. data.parentLevelType = parentLevelType;
  133. data.cityId = cityId;
  134. data.users = users;
  135. unbindSubmit();
  136. $.ajax({
  137. dataType: 'json',
  138. contentType: 'application/json;charset=utf-8',
  139. type: 'post',
  140. url: "/orgtree/docreate",
  141. data: JSON.stringify(data),
  142. success: function (r) {
  143. if (r) {
  144. if (r.code == 0) {
  145. var content = '保存成功';
  146. _showPop({
  147. type: 1,
  148. content: "<div style='font-size:16px; font-weight:bold; padding:0px 20px;'>" + content + "</div>",
  149. cancel: {
  150. display: true,
  151. name: "确定",
  152. callback: function () {
  153. window.location.href = '/orgtree';
  154. }
  155. }
  156. });
  157. } else {
  158. if (r.data && r.data != '') {
  159. var errorMsg = '';
  160. if (r.msg) {
  161. errorMsg = r.msg.replace(/;/g, '<br/>');
  162. }
  163. var content = '组织保存成功!<br/>' + errorMsg;
  164. _showPop({
  165. type: 1,
  166. content: "<div style='font-size:16px; font-weight:bold; padding:0px 20px;'>" + content + "</div>",
  167. cancel: {
  168. display: true,
  169. name: "确定",
  170. callback: function () {
  171. window.location.href = '/orgtree';
  172. }
  173. }
  174. });
  175. } else {
  176. showTip(r.msg, 2);
  177. bindSubmit();
  178. }
  179. }
  180. } else {
  181. showTip("保存失败!", 2);
  182. bindSubmit();
  183. }
  184. },
  185. error: function () {
  186. showTip("保存失败!网络异常!", 2);
  187. bindSubmit();
  188. }
  189. });
  190. }
  191. var userAddItemHtml = $("#js_user_item_html").html();
  192. $(".panel-body").delegate(".js_add_user", "click", function () {
  193. $(this).after(userAddItemHtml);
  194. });
  195. $(".panel-body").delegate(".js_user_remove", "click", function () {
  196. $(this).parent().remove();
  197. });
  198. $("body").click(function () {
  199. $(".mis-search").hide();
  200. });
  201. function showTip(content, type) {
  202. _showPop({
  203. type: type,
  204. content: "<div style='font-size:16px; font-weight:bold; padding:0px 20px;'>" + content + "</div>"
  205. });
  206. }
  207. });
  208. });