organization-department.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. var selectCompanyId = "";
  2. //部门详情弹框
  3. $(document).on('click', 'a.view-detail', function() {
  4. let dataId = $(this).data('id'); //单位ID
  5. companyId = dataId;
  6. layerDepartmentIndex = layer.open({
  7. type: 1,
  8. title: false,
  9. closeBtn: 0,
  10. skin: 'yourclass',
  11. area: ['700px', '500px'],
  12. content: $(".queryCompanyList"),
  13. success: function() {
  14. getDepartmentDataAjax({ "companyId": dataId })
  15. //获取部门列表 ajax请求
  16. $('.clsBtn,.cancel').click(function() {
  17. layer.close(layerDepartmentIndex);
  18. })
  19. }
  20. })
  21. })
  22. let scrollPageNo = 2;
  23. let scrollPageHasMoreData = true;
  24. var winH = $('.scroll').height(); //页面可视区域高度
  25. var p = 0,
  26. t = 0; // 顶部和底部的距离
  27. $(function() {
  28. //鼠标滚动事件
  29. $('.scroll').scroll(function() {
  30. var pageH = $('.result').height(); //当前文档总高度
  31. var scrollT = $('.scroll').scrollTop(); //滚动条top的值
  32. var bottomH = (pageH - winH - scrollT) / winH; // 当前所滚动位置到底部距离
  33. p = $(this).scrollTop(); //顶部距离
  34. let dataId = $('a.view-detail').data('id');
  35. if (t <= p) { // 判断是否下滚
  36. if (bottomH < 0.01) {
  37. if (scrollPageHasMoreData) {
  38. getDepartmentDataAjax({ "companyId": dataId }, scrollPageNo)
  39. scrollPageNo++
  40. }
  41. }
  42. }
  43. setTimeout(function() { t = p; }, 2000); //延时2秒
  44. });
  45. })
  46. function getDepartmentDataAjax(queryParam = {}, pageNo = 1) {
  47. queryParam.pageNo = pageNo;
  48. queryParam.pageSize = 20;
  49. var items2 = ''
  50. ajaxRequest(DEPARTMENT_LIST, "POST", queryParam, function(result) {
  51. let data = result.pageList;
  52. if (data.length == 0) {
  53. scrollPageHasMoreData = false;
  54. $('#dataList2').html("<br/><span style='display:block;text-align:center'>暂无数据...</span>");
  55. } else {
  56. data.forEach(function(item, key) {
  57. items2 += "<tr>" +
  58. "<td data-user='" + JSON.stringify(item) + "' data-id=" + item.departmentId + " class='status' style='width:24px!important'></td>" +
  59. "<td>" + item.departmentName + "</td>" +
  60. "<td>" + item.departmentMan + "</td>" +
  61. "<td>" + item.departmentPhone + "</td>" +
  62. "<td>" + item.creatMan + "</td>" +
  63. "<td>" + getFormatDate(item.creatTime.time) + "</td>" +
  64. "</tr>"
  65. })
  66. $('#dataList2').html(items2);
  67. }
  68. }, function(errorMsg) {
  69. alert("请求失败!");
  70. })
  71. }
  72. /* 部门新增ajax请求 */
  73. $('#addDataDepart').click(function() {
  74. //获取表单的值 并转换成对象
  75. let allParam = serializeArrayToObj($("#addDepartmentForm").serializeArray());
  76. //验证数据是否为空
  77. let res = validParamIsEmpty(allParam, {
  78. "departmentName": "请填写部门名称",
  79. "departmentMan": "请填写部门负责人",
  80. // "departmentPhone": "请填写负责人电话",
  81. });
  82. if (res.code == -1) {
  83. alert(res.msg);
  84. return;
  85. }
  86. var departmentPhone = checkPhoneFormat(allParam.departmentPhone);
  87. if (!departmentPhone.status) {
  88. alert(departmentPhone.message)
  89. return
  90. }
  91. //验证通过 请求ajax
  92. //将当前公司的ID赋值给提交数据
  93. allParam.companyId = companyId;
  94. ajaxRequest(DEPARTMENT_ADD, "POST", allParam, function(result) {
  95. layer.close(layerCreateIndex2);
  96. layer.msg('添加成功!', { icon: 6 });
  97. getDepartmentDataAjax({ "companyId": companyId })
  98. $('#addDepartmentForm')[0].reset();
  99. }, function(errorMsg) {
  100. alert("添加失败!");
  101. })
  102. })
  103. /* 部门修改发送请求 */
  104. $('#editDataDepart').click(function() {
  105. //获取表单的值 并转换成对象
  106. let allParam = serializeArrayToObj($("#editDepartmentForm").serializeArray());
  107. //验证数据是否为空
  108. let res = validParamIsEmpty(allParam, {
  109. "departmentName": "请填写部门名称",
  110. "departmentMan": "请填写部门负责人",
  111. // "departmentPhone": "请填写负责人电话",
  112. });
  113. if (res.code == -1) {
  114. alert(res.msg);
  115. return;
  116. }
  117. var departmentPhone = checkPhoneFormat(allParam.departmentPhone);
  118. if (!departmentPhone.status) {
  119. alert(departmentPhone.message)
  120. return
  121. }
  122. //验证通过 请求ajax
  123. ajaxRequest(DEPARTMENT_UPDATE, "POST", allParam, function(result) {
  124. let data = result.data;
  125. layer.close(layerUpdateIndex2);
  126. layer.msg('修改成功!', { icon: 6 });
  127. getDepartmentDataAjax({ "companyId": companyId })
  128. }, function(errorMsg) {
  129. alert("修改失败!");
  130. })
  131. })
  132. //部门删除发送请求
  133. $('.delete2').click(function(event) {
  134. event.stopPropagation();
  135. if (!$('.queryCompanyList .pure-table tr').has('.checked').length) {
  136. //layer.msg('请选择一条需要修改的信息');
  137. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  138. } else {
  139. let departmentId = $('.queryCompanyList .pure-table tr').find('.checked').data('id');
  140. ajaxRequest(DEPARTMENT_DELETE, "POST", { "departmentId": departmentId }, function(result) {
  141. $(".queryCompanyList .pure-table tbody tr.selected").remove()
  142. let data = result.data;
  143. // layer.close(layerDepartmentIndex);
  144. layer.msg('删除部门成功!', { icon: 6 });
  145. getDepartmentDataAjax({ "companyId": companyId })
  146. }, function(errorMsg) {
  147. alert("部门删除失败!");
  148. })
  149. }
  150. })
  151. //部门新增弹框
  152. $('.add2').click(function() {
  153. layerCreateIndex2 = layer.open({
  154. type: 1,
  155. title: false,
  156. closeBtn: 0,
  157. skin: 'yourclass',
  158. area: ['410px', '300px'],
  159. content: $(".addDepartmentDataOut"),
  160. success: function() {
  161. $('.clsBtn2,.cancel2').click(function() {
  162. //alert(1)
  163. layer.close(layerCreateIndex2);
  164. })
  165. }
  166. })
  167. })
  168. //部门修改弹框
  169. $('.edit2').click(function() {
  170. if (!$('.queryCompanyList .pure-table tr').has('.checked').length) {
  171. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  172. } else {
  173. // let dataId = $('.pure-table tr').find('.checked').data('id');
  174. let userInfo = $('.queryCompanyList .pure-table tr').find('.checked').data('user');
  175. $('.editDepartmentDataOut input[name=departmentName]').val(userInfo.departmentName)
  176. $('.editDepartmentDataOut input[name=departmentMan]').val(userInfo.departmentMan)
  177. $('.editDepartmentDataOut input[name=departmentPhone').val(userInfo.departmentPhone)
  178. $('.editDepartmentDataOut input[name=companyId').val(userInfo.companyId)
  179. $('.editDepartmentDataOut input[name=departmentId').val(userInfo.departmentId)
  180. layerUpdateIndex2 = layer.open({
  181. type: 1,
  182. title: false,
  183. closeBtn: 0,
  184. skin: 'yourclass',
  185. area: ['410px', '300px'],
  186. content: $(".editDepartmentDataOut"),
  187. success: function() {
  188. $('.clsBtn2,.cancel2').click(function() {
  189. layer.close(layerUpdateIndex2);
  190. })
  191. }
  192. });
  193. }
  194. })