$(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 loadAirList(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: [
[{
title: '序号',
templet: '#xuhao',
align: "center",
width: 60
},
{
field: "aircraft_type",
title: "机型",
align: "center"
},
{
field: "author",
title: "作者",
templet: '#type',
align: "center"
},
{
field: "book_name",
title: "书名",
templet: '#type',
align: "center"
},
{
field: "description",
title: "描述",
templet: '#type',
align: "center"
},
{
field: "img",
title: "图片",
align: "center",
templet: '
',
},
{
field: "file_path",
title: "文件名",
templet: '#typeTpl',
align: "center"
},
{
field: "input_time",
title: "开始时间",
align: "center"
},
{
field: "major_type",
title: "专业",
align: "center"
},
{
field: "publish_time",
title: "出版时间",
align: "center"
},
// {
// field: "remarks",
// title: "备注",
// align: "center"
// },
{
fixed: "right",
title: "操作",
toolbar: "#operationToolbar",
align: "center"
}
]
]
};
var majorType = "发构";
var name = "";
var major = "发构";
var search = 0;
if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
var url = "api/book/searchByMajor?page=" + (page + 1) + "&size=" + size + "&majorType=" + majorType + "&name=" + name;
fetchJSON(url, {}, "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;
loadAirList(currentPage, currentSize, searchTitleKey);
}
});
}
// console.log(data.data)
tableOption.data = data.data.list;
table.render(tableOption);
} else {
showMsg(data.msg, 2, 2000);
}
});
} else {
var url = "api/book/getByKeyword?major=" + major + "&keyword=" +
searchTitle + "&type=" + search +
"&size=" + size + "&page=" + (page + 1)
fetchJSON(url, {}, "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;
loadAirList(currentPage, currentSize,
searchTitleKey);
}
});
}
console.log(data.data.list)
tableOption.data = data.data.list;
table.render(tableOption);
} else {
showMsg(data.msg, 2, 2000);
}
});
}
}
loadAirList();
$("#searchArticle").on("click", function(e) {
e.preventDefault();
tableFirstLoad = true;
searchTitleKey = title.val().trim();
search = $("#find").find("option:selected").val();
if (searchTitleKey === "")
loadAirList(0, currentSize);
else
loadAirList(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;
console.log(data)
if (obj.event === "edit") {
x_admin_show(
"编辑",
encodeURI(
"book-edit.html?id=" + data.id + "&aircraft_type=" + data.aircraft_type + "&author=" + data.author + "&book_name=" + data.book_name + "&description=" + data.description + "&img=" + data.img + "&input_time=" + data.input_time + "&major_type=" + data.major_type + "&publish_time=" + data.publish_time + "&type_id=" + data.type_id + "&type_name=" + data.type_name + "&file_path=" + data.file_path
),
800,
400,
function() {
loadAirList(currentPage, currentSize);
}
);
} else if (obj.event === "delete") {
// console.log(data)
// 删除
var ids = [];
ids.push(data.id);
layer.confirm("确认要删除吗?", function() {
fetchJSON("api/book/delete", {
ids: ids
}, "post", function(data) {
if (data.status === 0) {
showMsg("已删除!", 1, 2000);
tableFirstLoad = true;
loadAirList(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/book/delete", {
ids: ids
}, "post", function(data) {
if (data.status === 0) {
showMsg("已删除!");
tableFirstLoad = true;
loadAirList(currentPage, currentSize);
} else {
showMsg(data.msg, 2, 2000);
}
});
});
});
// 导入
//表格导入
$("#tolead").on("click", function(e) {
e.preventDefault();
tableFirstLoad = true;
x_admin_show("导入",
"faul-add.html",
350,
200,
function() {
loadAirList(currentPage, currentSize);
});
});
// 新建用户
$("#add").on("click", function(e) {
e.preventDefault();
tableFirstLoad = true;
x_admin_show("添加",
"book-add.html?id=0&author=&aircraft_type=&book_name=&description=&img=&input_time=&major_type&publish_time=&type_id=&type_name=&file_path=",
800,
450,
function() {
loadAirList(currentPage, currentSize);
});
});
});
});