Spring Boot圖書管理系統項目實戰-9.歸還圖書

導航:

pre:  8.續借圖書

next:10.借還統計

 

只挑重點的講,具體的請看項目源碼。

1.項目源碼

需要的朋友請給個贊,並留下郵箱,給你們發!

 

2.頁面設計

2.1 bookReturn.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>歸還圖書</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" th:href="@{/static/layui/css/layui.css}">
</head>

<body>
<!-- 內容主體區域 -->
<div>
    <!--<div class="demoTable" style="padding: 15px">
        搜索:
        <div class="layui-inline">
            <input class="layui-input" id="find" autocomplete="off">
        </div>
        <button class="layui-btn" data-type="reload" id="queryRole">搜索</button>
    </div>-->

    <table id="tb-bookReturn" lay-filter="tb-bookReturn"></table>

</div>

<!--編輯表單-->
<script type="text/html" id="book-toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="return"><i class="layui-icon">&#xe605;</i>歸還</button>
        <button class="layui-btn layui-btn-sm" lay-event="refresh"><i class="layui-icon">&#xe666;</i>刷新
        </button>
    </div>
    <!--<div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">獲取選中行數據</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">獲取選中數目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">驗證是否全選</button>
    </div>-->
</script>

<script type="text/html" id="barOps">
    <a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i> </a>
</script>

<script src="/static/js/jquery-1.11.3.min.js" th:src="@{/static/js/jquery-1.11.3.min.js}"></script>
<script src="/static/layui/layui.all.js" th:src="@{static/layui/layui.all.js}"></script>
<script src="/static/js/util.js" th:src="@{/static/js/util.js}"></script>

<!--ctx-->
<script th:replace="~{fragment::ctx}"/>

<script>
    var element, layer, laydate, table, form,userTable;

    function reload(){
        userTable.reload();
    }

    $(function () {
        // 使用模塊
        layui.use(['element', 'layer', 'laydate', 'table', 'form'], function () {
            element = layui.element;
            layer = layui.layer;
            laydate = layui.laydate;
            table = layui.table;
            form = layui.form;
        });

        //第一個實例
         userTable = table.render({
             elem: '#tb-bookReturn'
             , height: 515
             , url: ctx+'api/bookBorrow/getPageResult' //數據接口
             , where:{borrowStatus: '0,2'}
             , page: true //開啓分頁
             , toolbar: '#book-toolbar'
             /*,request: {
                 pageName: 'pageNo' //頁碼的參數名稱,默認:page
                 ,limitName: 'pageSize' //每頁數據量的參數名,默認:limit
             }

             , response: {
                 statusName: 'code', //規定返回的狀態碼字段爲code
                 statusCode: 200 //規定成功的狀態碼爲200,默認爲0
             }
             , parseData: function (res) {
                  return {
                      "code": res.code, //解析接口狀態
                      "msg": res.msg, //解析提示文本
                      "count": res.records, //解析數據長度
                      "data": res.rows //解析數據列表
                  }
              }*/
            , cols: [
                [ //表頭
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left',hide:true}
                , {field: 'readerCode', title: '讀者編碼', width: 160}
                , {field: 'readerName', title: '讀者姓名', width: 160}
                , {field: 'readerSex', title: '讀者性別', width: 120}
                , {field: 'readerPhone', title: '讀者電話', width: 160}
                , {field: 'bookIsbn', title: '圖書ISBN', width: 160}
                , {field: 'bookName', title: '圖書名稱', width: 160}
                , {field: 'bookAuthor', title: '圖書作者', width: 120}
                , {field: 'bookCategory', title: '圖書分類', width: 120}
                , {field: 'bookLocation', title: '圖書位置', width: 180}
                , {field: 'bookTotal', title: '圖書數量', width: 120}
                , {field: 'bookLeft', title: '圖書剩餘', width: 120}
                , {field: 'borrowDate', title: '借閱日期', width: 120,templet:'<div>{{ layui.util.toDateString(d.borrowDate, "yyyy-MM-dd") }}</div>'}
                , {field: 'returnDate', title: '應還日期', width: 120,templet:'<div>{{ layui.util.toDateString(d.returnDate, "yyyy-MM-dd") }}</div>'}
                , {field: 'borrowDays', title: '借閱天數', width: 120}
                , {field: 'remark', title: '備註', width: 180}
            ]
             ]
        });

        userTable.reload({
            where: { //設定異步數據接口的額外參數,任意設
                CustomName: $("#CustomName").val()//這裏獲取input的值
            }
            ,page: {
                curr: 1 //重新從第 1 頁開始
            }
        });

        //工具欄事件
        table.on('toolbar(tb-bookReturn)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data;
            var ids = [];
            switch (obj.event) {
                // 歸還
                case 'return':
                    if (checkData.length == 0) {
                        layer.alert('請選擇要操作的行');
                    } else {
                        layer.confirm('確定要歸還嗎?', function (index) {
                            for (var i = 0; i < checkData.length; i++) {
                                ids.push(checkData[i].id);
                            }
                            //layer.alert(JSON.stringify(ids));
                            $.ajax({
                                url: ctx+'api/bookBorrow/return',
                                type: 'POST',
                                contentType: "application/json",
                                dataType: "json",
                                data: JSON.stringify(ids),
                                success: function (result) {
                                    if (result.code == 200) {
                                        setTimeout(function () {
                                            layer.closeAll();//關閉所有的彈出層
                                            userTable.reload();
                                        }, 300);
                                    }else {
                                        layer.msg("操作失敗!", {icon: 5});
                                    }
                                }
                            });
                        });
                    }
                    break;
                case 'refresh':
                    userTable.reload();
                    break;
                case 'getCheckData':
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('選中了:' + data.length + ' 個');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全選' : '未全選')
                    break;
            }
            ;
        });

    });


</script>
</body>

</html>

 

3.歸還圖書service

參考:借閱圖書。

4.歸還圖書controller

參考:借閱圖書。

 

 

需要源碼的朋友留下郵箱:)

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章