let form, layer, table, tableIns, user = getUser(), tableHeight; let pageNum = 1, limitSize = 30; // 默认第一页,分页数量为10 function setParams() { layui.use(['form', 'layer', 'table'], function () { form = layui.form; layer = layui.layer; table = layui.table; pages(1, 30, 1); $('#myModal_edit').on('show.bs.modal', centerModals); }) } function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl + "proteam/pot/bidTowerMain/getBidTowerMainList?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: [30, 50, 100], 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({ elem: "#violationStatisticsTable", height: 'full-160', data: dataList, limit: limit, cols: [ [ //表头 { title: "序号", width: 80, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "proNo", title: "工程编码", unresize: true, align: "center", sort: true }, { field: "bidNo", title: "标段工程编码", unresize: true, align: "center", sort: true, style: 'word-break: break-all' }, { field: "proName", title: "标段工程名称", unresize: true, align: "center", sort: true }, { field: "towerName", title: "杆塔编号", unresize: true, align: "center", sort: true }, { field: "lon", title: "经度", unresize: true, align: "center", sort: true }, { field: "lat", title: "纬度", unresize: true, align: "center", sort: true }, { title: "操作", width: 200, unresize: true, align: "center", templet: function (d) { let html = ''; html += "编辑"; html += "
|
删除"; return html; } } ], ], done: function (res, curr, count) { layer.close(loadingMsg); table.resize("violationStatisticsTable"); count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block"); count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto"); }, }); } // 获取参数 function getReqParams(page, limit, type) { let obj = {}; if (!type) { obj = { page: page + "", limit: limit + "", proName: $('#proName').val(), towerName: $('#towerName').val() }; } else { obj = { page: '1', limit: '30', proName: '', towerName: '' }; } return obj; } // 查询/重置 function query(type) { if (type === 2) { $('#proName').val(''); $('#towerName').val(''); } let pattern = new RegExp("[%_<>]"); if (pattern.test($("#proName").val())) { $("#proName").val(''); return layer.msg('标段名称查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } if (pattern.test($("#towerName").val())) { $("#towerName").val(''); return layer.msg('标段名称查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } pageNum = 1; pages(1, limitSize) } /*删除标段杆塔*/ function delData(id) { let params = { 'id':id } layer.confirm("确定删除吗?", { move:false }, function () { let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0}); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl + 'proteam/pot/bidTowerMain/delData?token=' + token, data: params, type: 'post', async: true, success: function (result) { layer.close(loadingMsg); // 关闭提示层 if (result.code === 200) { parent.layer.msg('删除成功', {icon: 1}) query() } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } else if (result.code === 401) { logout(1) } }, error: function () { layer.close(loadingMsg); // 关闭提示层 layer.msg('服务异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000}); } }); }) } // 标段杆塔维护模版下载 function modelDownload() { let loadingMsg = layer.msg('模板下载中,请稍候...', { icon: 16, scrollbar: false, time: 0 }); let url = dataUrl + 'proteam/pot/bidTowerMain/downLoadExcelModel?token=' + token; let xhr = new XMLHttpRequest(); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt", sm3(JSON.stringify({}))); xhr.onload = function () { layer.close(loadingMsg); // 关闭提示层 if (this.status === 200) { let blob = this.response; var a = document.createElement("a"); var url = window.URL.createObjectURL(blob); a.href = url; a.download = "标段杆塔维护-导入模板.xlsx"; // 文件名 } else { layer.msg('服务异常,请稍后重试', { icon: 16, scrollbar: false, time: 2000 }); } a.click() window.URL.revokeObjectURL(url) }; xhr.send(); } /*导入*/ function chooseFile(){ $("#import-excel").trigger("click"); } $("#import-excel").change(function () { if($(this).val()){ let files = $(this)[0].files[0]; let fileType = files.name.substring( files.name.lastIndexOf(".") + 1, files.name.length ); if (fileType === "xlsx" || fileType === "xls") { excelUpload7(this,dataUrl + "proteam/pot/bidTowerMain/importExcel?token=" + token) } else { layer.msg("仅支持上传文件格式为:xlx、xlsx", {icon: 7,}); $("#import-excel").val(""); } } }); // 弹出模态框 function centerModals() { $('#myModal_edit').each(function (i) { var $clone = $(this).clone().css('display', 'block').appendTo('body'); var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 3); top = top > 0 ? top : 0; $clone.remove(); $(this).find('.modal-content').css("margin-top", top); }); }; // 新增/修改标段杆塔 function addData(type,id) { let title = '新增' if(type){ title = '编辑' } let layerIndex = layer.open({ id: "dutyPerson", title: ['
' + title + '
', 'font-size:16px;background-color:#f0f0f0;display: flex;align-items: center;'], type: 2, maxmin: false, content: 'bidTowerForm.html', area: ['800px', '650px'], move: false, success: function (layero, index) { let iframeWin = window["layui-layer-iframe" + layerIndex]; iframeWin.setParams(id); } }); } // 关闭页面 function closePage() { let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引 parent.layer.close(index); //再执行关闭 }