$(function() { var defaultPage = 0; var defaultSize = 10; var currentPage = defaultPage; var currentSize = defaultSize; var tableFirstLoad = true; layui.use(["form", "table", "laypage", "layer"], function() { var table = layui.table; var laypage = layui.laypage; var layer = layui.layer; var title = $("#realName"); var searchTitleKey = ""; function loadoutLineList(page, size, searchTitle) { if (page === null || page === undefined) page = defaultPage; if (size === null || size === undefined) size = defaultSize; var tableOption = { elem: "#outLineList", height: "full-81", limit: size, cols: [ [ { field: "outline_name", title: "大纲名称", align: "center" }, { fixed: "right", title: "操作", toolbar: "#operationToolbar", align: "center" } ] ] }; if (searchTitle === null || searchTitle === undefined || searchTitle === "") { fetchJSON("api/outline/listpage?page=" + (page + 1) + "&size=" + size, {}, "get", function(data) { if (data.status === 0) { if (tableFirstLoad) { tableFirstLoad = false; laypage.render({ curr: page + 1, elem: "pagination", count: data.data.total, layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"], jump: function(obj, first) { if (first) return; currentPage = obj.curr - 1; currentSize = obj.limit; loadoutLineList(currentPage, currentSize, searchTitleKey); } }); } tableOption.data = data.data.list; table.render(tableOption); } else { showMsg(data.msg, 2, 2000); } }); } else { fetchJSON("api/outline/getByName?name=" + searchTitle + "&page=" + (page + 1) + "&size=" + size, {}, "get", function(data) { if (data.status === 0) { if (tableFirstLoad) { tableFirstLoad = false; laypage.render({ curr: page + 1, elem: "pagination", count: data.data.total, layout: ["count", "prev", "page", "next", "limit", "refresh", "skip"], jump: function(obj, first) { if (first) return; currentPage = obj.curr - 1; currentSize = obj.limit; loadoutLineList(currentPage, currentSize, searchTitleKey); } }); } tableOption.data = data.data.list; table.render(tableOption); } else { showMsg(data.msg, 2, 2000); } }); } } loadoutLineList(); $("#searchArticle").on("click", function(e) { e.preventDefault(); tableFirstLoad = true; searchTitleKey = title.val().trim(); if (searchTitleKey === "") loadoutLineList(0, currentSize); else loadoutLineList(0, currentSize, searchTitleKey); }); $("#keyword").on("keyup", function(e) { e.preventDefault(); if (e.keyCode === 13) { $("#searchArticle").click(); } }); // 监听表内工具条 table.on("tool(outLineList)", function(obj) { var data = obj.data; if (obj.event === "edit") { x_admin_show( "在线预览", encodeURI( "../admin/Uoutline-edit.html?file_path=" + data.file_path ), 1444, 685, function() { loadoutLineList(currentPage, currentSize); } ); // console.log(data.file_path) var data = obj.data.file_path flie = urlBase + data console.log(flie) sessionStorage.setItem("url", flie) } else if (obj.event === "delete") { // console.log(data) // 删除 var ids = []; ids.push(data.id); layer.confirm("确认要删除吗?", function() { fetchJSON("api/outline/delete", { ids: ids }, "post", function(data) { if (data.status === 0) { showMsg("已删除!", 1, 2000); tableFirstLoad = true; loadoutLineList(currentPage, currentSize); } else { showMsg(data.msg, 2, 2000); } }); }); } }); // 批量删除 $("#batchDelete").on("click", function(e) { e.preventDefault(); var checkedData = table.checkStatus("outLineList").data; if (checkedData.length === 0) { showMsg("未选择需要删除的日志", 2, 2000); return; } layer.confirm("确认要删除吗?", function() { var ids = []; for (var i = 0; i < checkedData.length; i++) { ids.push(checkedData[i].id); } fetchJSON("api/outline/delete", { ids: ids }, "post", function(data) { if (data.status === 0) { showMsg("已删除!"); tableFirstLoad = true; loadoutLineList(currentPage, currentSize); } else { showMsg(data.msg, 2, 2000); } }); }); }); // 新建用户 $("#addair").on("click", function(e) { e.preventDefault(); tableFirstLoad = true; x_admin_show("添加", "../admin/outline-add.html?id=0&outline_name=&aircraft_type=&major_type=&description=&file_path=&input_time=&remarks=", 800, 400, function() { loadoutLineList(currentPage, currentSize); }); }); }); });