let form, layer, table, laypage, laydate; let pageNum = 1, limitSize = 20; // 默认第一页,分页数量为20 layui.use(['form', 'layer', 'table', 'laypage', 'laydate'], function () { form = layui.form; table = layui.table; laypage = layui.laypage; layer = layui.layer; laydate = layui.laydate; laydate.render({ elem: '#years', //指定元素 元素选择器 type: 'year', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒) trigger: 'click', format: 'yyyy', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss btns: ['clear', 'now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定 done: function (value, date) { //时间回调 } }); layui.form.render(); pages(1, 20, 1); }) function reloadData(){ pages(1, limitSize); } function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl + "proteam/pot/greenBuild/getAwardsListByChild?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) { laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [20, 50, 100, 200, 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) { table.render({ elem: "#table", id: "table", height: "full-160", data: dataList, limit: limit, cols: [ [ //表头 { title: "序号", width: 100, unresize: true, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } }, { field: "years", title: "年份", unresize: true, width: 120, align: "center", }, { field: "proName", title: "工程名称", unresize: true, align: "center", }, { field: "jxName", title: "所获奖项", unresize: true, align: "center", }, { title: "操作", width: 180, unresize: true, align: "center", templet: function (d) { let html = ''; html += "修改" + "
|
删除"; return html; } }, ], ], done: function (res, curr, count) { table.resize("table"); 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 + "", years: $('#years').val(), proName: $('#proName').val(), jxName: $('#jxName').val() }; } else { obj = { page: '1', limit: '20', years: '', proName: '', jxName: '' }; } return obj; } // 查询/重置 function query(type) { let pattern = new RegExp("[%_<>]"); if (pattern.test($("#proName").val())) { $("#proName").val(''); return layer.msg('关键字查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } if (pattern.test($("#jxName").val())) { $("#jxName").val(''); return layer.msg('关键字查询包含特殊字符,请重新输入', { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } pages(1, limitSize) } // 关闭页面 function closePage(type) { let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引 parent.layer.close(index); //再执行关闭 } /*新增*/ function addData() { let id =""; let layerIndex = layer.open({ id: "addVio", title: false, type: 2, maxmin: false, skin: "my-skin child-skin", content: 'awardsAdd.html', area: ["860px", "564px"], shade:0, closeBtn: 0, success: function (layero, index) { let iframeWin = window["layui-layer-iframe" + layerIndex]; iframeWin.setParams(id); } }); } /*修改*/ function editData(id) { let layerIndex = layer.open({ id: "editVio", title: false, type: 2, maxmin: false, skin: "my-skin child-skin", content: 'awardsAdd.html', area: ["860px", "564px"], shade:0, closeBtn: 0, success: function (layero, index) { let iframeWin = window["layui-layer-iframe" + layerIndex]; iframeWin.setParams(id); } }); } /*删除*/ function delData(id) { layer.confirm("确定删除吗?", function () { let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0}); $.ajax({ headers: { "encrypt": sm3(JSON.stringify({ id: id })) }, url: dataUrl + 'proteam/pot/greenBuild/delAwardsById?token=' + token, data: { id: id, }, type: 'post', async: true, success: function (result) { console.log(result) layer.close(loadingMsg); // 关闭提示层 if (result.code === 200) { layer.msg('删除成功', {icon: 1}) pages(1, 20); } 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}); } }); }) }