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