123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- var selectCompanyId = "";
- //部门详情弹框
- $(document).on('click', 'a.view-detail', function() {
- let dataId = $(this).data('id'); //单位ID
- companyId = dataId;
- layerDepartmentIndex = layer.open({
- type: 1,
- title: false,
- closeBtn: 0,
- skin: 'yourclass',
- area: ['700px', '500px'],
- content: $(".queryCompanyList"),
- success: function() {
- getDepartmentDataAjax({ "companyId": dataId })
- //获取部门列表 ajax请求
- $('.clsBtn,.cancel').click(function() {
- layer.close(layerDepartmentIndex);
- })
- }
- })
- })
- let scrollPageNo = 2;
- let scrollPageHasMoreData = true;
- var winH = $('.scroll').height(); //页面可视区域高度
- var p = 0,
- t = 0; // 顶部和底部的距离
- $(function() {
- //鼠标滚动事件
- $('.scroll').scroll(function() {
- var pageH = $('.result').height(); //当前文档总高度
- var scrollT = $('.scroll').scrollTop(); //滚动条top的值
- var bottomH = (pageH - winH - scrollT) / winH; // 当前所滚动位置到底部距离
- p = $(this).scrollTop(); //顶部距离
- let dataId = $('a.view-detail').data('id');
- if (t <= p) { // 判断是否下滚
- if (bottomH < 0.01) {
- if (scrollPageHasMoreData) {
- getDepartmentDataAjax({ "companyId": dataId }, scrollPageNo)
- scrollPageNo++
- }
- }
- }
- setTimeout(function() { t = p; }, 2000); //延时2秒
- });
- })
- function getDepartmentDataAjax(queryParam = {}, pageNo = 1) {
- queryParam.pageNo = pageNo;
- queryParam.pageSize = 20;
- var items2 = ''
- ajaxRequest(DEPARTMENT_LIST, "POST", queryParam, function(result) {
- let data = result.pageList;
- if (data.length == 0) {
- scrollPageHasMoreData = false;
- $('#dataList2').html("<br/><span style='display:block;text-align:center'>暂无数据...</span>");
- } else {
- data.forEach(function(item, key) {
- items2 += "<tr>" +
- "<td data-user='" + JSON.stringify(item) + "' data-id=" + item.departmentId + " class='status' style='width:24px!important'></td>" +
- "<td>" + item.departmentName + "</td>" +
- "<td>" + item.departmentMan + "</td>" +
- "<td>" + item.departmentPhone + "</td>" +
- "<td>" + item.creatMan + "</td>" +
- "<td>" + getFormatDate(item.creatTime.time) + "</td>" +
- "</tr>"
- })
- $('#dataList2').html(items2);
- }
- }, function(errorMsg) {
- alert("请求失败!");
- })
- }
- /* 部门新增ajax请求 */
- $('#addDataDepart').click(function() {
- //获取表单的值 并转换成对象
- let allParam = serializeArrayToObj($("#addDepartmentForm").serializeArray());
- //验证数据是否为空
- let res = validParamIsEmpty(allParam, {
- "departmentName": "请填写部门名称",
- "departmentMan": "请填写部门负责人",
- // "departmentPhone": "请填写负责人电话",
- });
- if (res.code == -1) {
- alert(res.msg);
- return;
- }
- var departmentPhone = checkPhoneFormat(allParam.departmentPhone);
- if (!departmentPhone.status) {
- alert(departmentPhone.message)
- return
- }
- //验证通过 请求ajax
- //将当前公司的ID赋值给提交数据
- allParam.companyId = companyId;
- ajaxRequest(DEPARTMENT_ADD, "POST", allParam, function(result) {
- layer.close(layerCreateIndex2);
- layer.msg('添加成功!', { icon: 6 });
- getDepartmentDataAjax({ "companyId": companyId })
- $('#addDepartmentForm')[0].reset();
- }, function(errorMsg) {
- alert("添加失败!");
- })
- })
- /* 部门修改发送请求 */
- $('#editDataDepart').click(function() {
- //获取表单的值 并转换成对象
- let allParam = serializeArrayToObj($("#editDepartmentForm").serializeArray());
- //验证数据是否为空
- let res = validParamIsEmpty(allParam, {
- "departmentName": "请填写部门名称",
- "departmentMan": "请填写部门负责人",
- // "departmentPhone": "请填写负责人电话",
- });
- if (res.code == -1) {
- alert(res.msg);
- return;
- }
- var departmentPhone = checkPhoneFormat(allParam.departmentPhone);
- if (!departmentPhone.status) {
- alert(departmentPhone.message)
- return
- }
- //验证通过 请求ajax
- ajaxRequest(DEPARTMENT_UPDATE, "POST", allParam, function(result) {
- let data = result.data;
- layer.close(layerUpdateIndex2);
- layer.msg('修改成功!', { icon: 6 });
- getDepartmentDataAjax({ "companyId": companyId })
- }, function(errorMsg) {
- alert("修改失败!");
- })
- })
- //部门删除发送请求
- $('.delete2').click(function(event) {
- event.stopPropagation();
- if (!$('.queryCompanyList .pure-table tr').has('.checked').length) {
- //layer.msg('请选择一条需要修改的信息');
- layer.msg('请选择一条需要删除的信息!', { icon: 5 });
- } else {
- let departmentId = $('.queryCompanyList .pure-table tr').find('.checked').data('id');
- ajaxRequest(DEPARTMENT_DELETE, "POST", { "departmentId": departmentId }, function(result) {
- $(".queryCompanyList .pure-table tbody tr.selected").remove()
- let data = result.data;
- // layer.close(layerDepartmentIndex);
- layer.msg('删除部门成功!', { icon: 6 });
- getDepartmentDataAjax({ "companyId": companyId })
- }, function(errorMsg) {
- alert("部门删除失败!");
- })
- }
- })
- //部门新增弹框
- $('.add2').click(function() {
- layerCreateIndex2 = layer.open({
- type: 1,
- title: false,
- closeBtn: 0,
- skin: 'yourclass',
- area: ['410px', '300px'],
- content: $(".addDepartmentDataOut"),
- success: function() {
- $('.clsBtn2,.cancel2').click(function() {
- //alert(1)
- layer.close(layerCreateIndex2);
- })
- }
- })
- })
- //部门修改弹框
- $('.edit2').click(function() {
- if (!$('.queryCompanyList .pure-table tr').has('.checked').length) {
- layer.msg('请选择一条需要修改的信息!', { icon: 5 });
- } else {
- // let dataId = $('.pure-table tr').find('.checked').data('id');
- let userInfo = $('.queryCompanyList .pure-table tr').find('.checked').data('user');
- $('.editDepartmentDataOut input[name=departmentName]').val(userInfo.departmentName)
- $('.editDepartmentDataOut input[name=departmentMan]').val(userInfo.departmentMan)
- $('.editDepartmentDataOut input[name=departmentPhone').val(userInfo.departmentPhone)
- $('.editDepartmentDataOut input[name=companyId').val(userInfo.companyId)
- $('.editDepartmentDataOut input[name=departmentId').val(userInfo.departmentId)
- layerUpdateIndex2 = layer.open({
- type: 1,
- title: false,
- closeBtn: 0,
- skin: 'yourclass',
- area: ['410px', '300px'],
- content: $(".editDepartmentDataOut"),
- success: function() {
- $('.clsBtn2,.cancel2').click(function() {
- layer.close(layerUpdateIndex2);
- })
- }
- });
- }
- })
|