123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- $(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: [
- [{
- field: "img",
- title: "预览图",
- templet: '#typeTpl',
- align: "left",
- width: 100,
- },
- {
- field: "book_name",
- title: "书相关信息",
- templet: '#type',
- align: "left",
- width: 430,
- },
- {
- field: "author",
- title: "书相关信息",
- templet: '#book',
- width: 250,
- align: "left",
- },
- {
- fixed: "right",
- title: "操作",
- toolbar: "#operationToolbar",
- align: "left",
- }
- ]
- ]
- };
- if (searchTitle === null || searchTitle === undefined || searchTitle === "") {
- var url = "api/book/listpage?page=" + (page + 1) + "&size=" + size;
- 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);
- }
- });
- }
- tableOption.data = data.data.list;
- console.log(data.data)
- table.render(tableOption);
- } else {
- showMsg(data.msg, 2, 2000);
- }
- });
- } else {
- // var url = ;
- fetchJSON("api/book/getByName?name=" + searchTitle, {}, "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);
- }
- });
- }
- tableOption.data = data.data;
- table.render(tableOption);
- } else {
- showMsg(data.msg, 2, 2000);
- }
- });
- }
- }
- loadAirList();
- $("#searchArticle").on("click", function(e) {
- e.preventDefault();
- tableFirstLoad = true;
- searchTitleKey = title.val().trim();
- 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;
- if (obj.event === "edit") {
- x_admin_show(
- "在线预览",
- encodeURI(
- "../admin/Ubookshow.html?bookName=" + data.book_name + "&file_path=" + data.file_path + "&id=" + data.id
- ),
- 1400,
- 700,
- function() {
- loadAirList(currentPage, currentSize);
- }
- );
- var file_path = data.file_path;
- // console.log(file_path)
- sessionStorage.setItem("url", file_path)
- var book_name = obj.data.book_name
- sessionStorage.setItem("book_name", book_name)
- }
- });
- // 批量删除
- $("#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("导入",
- "../admin/faul-add.html",
- 350,
- 200,
- function() {
- loadAirList(currentPage, currentSize);
- });
- });
- // 新建用户
- $("#add").on("click", function(e) {
- e.preventDefault();
- tableFirstLoad = true;
- x_admin_show("添加",
- "../admin/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);
- });
- });
- });
- });
|