
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="referrer" content="no-referrer">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="/css/common/common.css" rel="stylesheet" type="text/css" />
    <link href="/css/admin/console.css" rel="stylesheet" type="text/css"/>
    <link href="/ref/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <script src="/ref/layui-v2.6.8/layui/layui.js" type="text/javascript"></script>
    <script src="/ref/jquery/jquery-3.4.1.js" type="text/javascript"></script>
    <script src="/js/client/chat.js" type="text/javascript"></script>

    <style>
        .search-condition-elem {
            width: 170px;
        }
    </style>
</head>
<body style="overflow-x: hidden">
<center>

    <div class="search-condition-module">
        <input class="search-condition-elem" id="search-keyword" placeholder="消息正文检索">
        <button class="btn" style="left: 350px" id="search-engine-btn" onclick="searchMessList()">检索</button>
    </div>

    <table class="account-apply-tab layui-table" id="search-result-tab">
        <thead>
        <tr>
            <th style="width: 200px">发送人</th>
            <th style="width: 200px">接受人</th>
            <th style="width: 200px">消息正文</th>
            <th style="width: 200px">时间</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <div id="page"></div>
</center>
</body>


<script>

    var firstSearch = true;
    var curr = 0, size = 10, total = 0;
    searchMessList();
    function searchMessList() {
        $.ajax({
            url:"/api/chat/mess/page?pageNo="+(curr == 0 ? 1 : curr)+"&pageSize="+size+"&mess="+$("#search-keyword").val(),
            type:"get",
            success:function (data) {
                data = eval(data);
                if (data.success){
                    $("#search-result-tab").children("tbody").empty();
                    $.each(data.data, function (index, value) {
                        var tr = "<tr>"+
                            "<td style='width: 100px;'>"+value.sender.userName+"</td>"+
                            "<td style='width: 100px;'>"+value.receiver.userName+"</td>"+
                            "<td style='width: 100px;'>"+value.message+"</td>"+
                            "<td style='width: 200px;'>"+formatMsgTime(value.time)+"</td>"+
                            "</tr>";

                        if (!firstSearch) {
                            $("#search-result-tab").children("tbody").append(tr);
                        }
                    });
                    if (curr == 0 || data.total != total) {
                        curr = 1;
                        firstSearch = false;
                        total = data.total;
                        initPage();
                    }
                }
            },
            error:function () {
                layer.msg("error");
            }
        })
    }

    function initPage() {
        layui.use('laypage', function(){
            var laypage = layui.laypage;
            laypage.render({
                elem: 'page',
                count: total,
                limit: size,
                curr: curr,
                jump: function(obj){
                    curr = obj.curr;
                    searchMessList();
                }
            });
        })
    }
</script>
<style>
    .layui-laypage a, .layui-laypage span {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        vertical-align: middle;
        padding: 3px 13px;
        height: 28px;
        line-height: 28px;
        margin: 0px 5px;
        border-radius: 4px;
        background-color: #fff;
        color: #4e6ef2;
        font-size: 14px;
        border: none;
    }
    .layui-laypage a:hover, .layui-laypage span:hover {
        background: #4e6ef2;
        color: #fff;
    }
    .layui-laypage .layui-laypage-curr .layui-laypage-em {
        position: absolute;
        left: -1px;
        top: -1px;
        padding: 1px;
        width: 100%;
        height: 100%;
        border-radius: 4px;
        background: #4e6ef2;
        color: #fff;
        font-weight: normal;
    }
    .layui-laypage-next, .layui-laypage-prev {
        border-radius: 4px;
    }
    .layui-laypage-default {
        float: right;
    }
</style>
</html>