let form, layer, table, tableIns; let pageNum = 1, limitSize = 300; // 默认第一页,分页数量为200 let user = getUser(); let accountId = 0; let paramsObj = null; function setParams(params) { paramsObj = JSON.parse(params); accountId = paramsObj.checkUser; layui.use(['form', 'layer', 'table'], function () { form = layui.form; layer = layui.layer; table = layui.table; pages(1, 300, 1); }) } function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); $.ajax({ url: dataUrl + "proteam/pot/allocation/getTwoRiskPlans?token=" + token, data: params, type: 'POST', async: false, success: function (result) { if (result.code === 200) { if (result.data) { initTable(result.data, result.limit, result.curr) laypages(result.count, result.curr, result.limit) } } else if (result.code === 500) { layer.alert(result.msg, { icon: 2 }) } else if (result.code === 401) { logout(1); } }, error: function () { } }); } function laypages(total, page, limit) { layui.use(['laypage'], function () { let laypage = layui.laypage; laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [300, 400, 500], layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], groups: 5, jump: function (obj, first) { if (!first) { pageNum = obj.curr, limitSize = obj.limit; pages(obj.curr, obj.limit, null); } } }); }) } /*初始化表格*/ function initTable(dataList, limit, page) { let loadingMsg = layer.msg("数据加载中,请稍候...", { icon: 16, scrollbar: false, time: 0, }); tableIns = table.render({ id: 'todayTaskTable', elem: "#todayTaskTable", height: "full-130", data: dataList, cols: [ [ //表头 { type: 'checkbox', width: '5%', }, { title: "序号", width: '8%', unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_NUM; } }, { field: "orgName", title: "建管单位", width: '10%', unresize: false, align: "center", }, { field: "proName", title: "工程名称", width: '20%', unresize: false, align: "center", }, { field: "workManager", title: "班组长", width: '10%', unresize: false, align: "center", }, { field: "workContent", title: "作业内容", width: '47%', unresize: false, align: "center", }, ], ], limit: limit, done: function (res, curr, count) { layer.close(loadingMsg); // 遍历数据,设置选中状态 $.each(res.data, function (index, item) { if (item.checkData === 1) { // 选中行 $('tr[data-index="' + index + '"] input[type="checkbox"]').prop('checked', true); // 更新表格选中状态 $('.layui-table-box').find('.layui-table-body tr[data-index="' + index + '"]').addClass('layui-table-click'); } }); layui.form.render(); }, }); } // 获取参数 function getReqParams(page, limit, type) { let obj = {}; if (!type) { obj = { page: page + "", limit: limit + "", type: 3, accountId: accountId }; } else { obj = { page: 1, limit: limit, accountId: accountId, type: 3 }; } return obj; } // 分配数据 function addData() { let selectedIds = []; $('.layui-table-body .layui-form-checked').each(function () { var tr = $(this).closest('tr'); var id = tr.attr('data-index'); // 获取行索引 // 或者从数据属性获取 var data = table.cache['todayTaskTable'][id]; selectedIds.push(data.id); }); let url = dataUrl + "proteam/pot/allocation/distributionData"; let params = { ids: selectedIds, accountId: accountId } let loadingMsg = layer.msg('数据分配中,请稍候...', { icon: 16, scrollbar: false, time: 0 }); ajaxRequest2(url, "POST", params, true, function (result) { layer.close(loadingMsg); // 关闭提示层 if (result.code === 200) { parent.layer.msg(result.msg, { icon: 1 }) closePage(1); } else { layer.msg(result.msg, { icon: 2 }) } }, function (xhr) { layer.close(loadingMsg); // 关闭提示层 error(xhr) }, null, token); } // 关闭页面 function closePage(type) { let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引 parent.layer.close(index); //再执行关闭 if (type === 1) { window.parent.reloadData() } }