<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>

<body class="timo-layout-page">
<div class="layui-card">
    <div class="layui-card-header timo-card-header">
        <span><i class="fa fa-bars"></i> 视频稿件列表</span>
        <i class="layui-icon layui-icon-refresh refresh-btn"></i>
    </div>
    <div class="layui-card-body">
        <div class="layui-row timo-card-screen put-row">
            <div class="layui-row timo-card-screen put-row">
                <div class="pull-left layui-form-pane">
                    <!--<div class="layui-inline">
                        <label class="layui-form-label">环境</label>
                        <div class="layui-input-block timo-search-status">
                            <select id="getPageByEnv" class="timo-search-select" name="env" onchange="getPageByEnv()"
                                    mo:dict="ENVIRONMENT" mo-selected="${env}"></select>
                        </div>
                    </div>-->
                    <div class="layui-inline timo-search-box">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" th:value="${param.title}" placeholder="请输入视频标题"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn timo-search-btn">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
                <div class="pull-right">
                    <div class="btn-group-right">
                        <div class="btn-group">
                            <button class="layui-btn">批量处理<span class="caret"></span></button>
                            <dl class="layui-nav-child layui-anim layui-anim-upbit">
                                <dd><a class="ajax-status" th:href="@{/api/machine/host/delete}">批量删除</a></dd>
                            </dl>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="timo-table-wrap">
            <table class="layui-table timo-table" style="table-layout:fixed">
                <thead>
                <tr>
                    <th class="timo-table-checkbox">
                        <label class="timo-checkbox"><input type="checkbox">
                            <i class="layui-icon layui-icon-ok"></i></label>
                    </th>
                    <th data-field="avatarUrl">发布时间</th>
                    <th data-field="avatarUrl">封面</th>
                    <th data-field="videoId">视频 ID</th>
                    <th data-field="screenName">标题</th>
                    <!--<th data-field="gender">描述</th>-->
                    <th data-field="gender">时长</th>
                    <th data-field="gender">方向</th>
                    <!--<th data-field="signature">视频资源</th>-->
                    <th data-field="following">可见范围</th>
                    <th data-field="follower">审核状态</th>
                    <th data-field="publishBy">发布用户</th>
                    <th width="90px">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td><label class="timo-checkbox"><input type="checkbox" th:value="${item.videoId}">
                        <i class="layui-icon layui-icon-ok"></i></label>
                    </td>
                    <td th:text="${item.publishAt}"></td>
                    <td>
                        <img class="layui-side-user-avatar" data-size="320,240" th:src="@{${item.coverUrl}}" alt="video cover">
                    </td>
                    <td th:text="${item.videoId}"></td>
                    <td th:text="${item.title}"></td>
                    <!--<td th:text="${item.description}"></td>-->
                    <td th:text="${item.duration}"></td>
                    <td th:text="${item.horizontal}"></td>
                    <td th:text="${item.scope}"></td>
                    <td>
                        <a class="open-popup" data-title="修改状态" th:attr="data-url=@{'/bili/post/video/status/'+${item.videoId}}"
                           href="#" th:text="${item.status}"></a>
                    </td>
                    <td th:text="${item.publishBy}"></td>
                    <td width="90px">
                        <a class="open-popup" data-title="视频预览" th:attr="data-url=@{'/bili/post/video/preview/'+${item.videoId}}"
                           data-size="960,480" href="#">预览</a>
                        <a class="open-popup" data-title="修改状态" th:attr="data-url=@{'/bili/post/video/status/'+${item.videoId}}"
                           href="#">修改状态</a>
                        <a class="open-popup" data-title="视频资源" th:attr="data-url=@{'/bili/post/video/resource/'+${item.videoId}}"
                           data-size="960,480" href="#">视频资源</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div th:replace="/common/fragment :: page"></div>
    </div>
</div>

<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
<script type="text/javascript">
    var tip_index;
    /**
     * 页面表格内容超出宽度显示...
     * 鼠标放上去之后回显具体内容
     * 移开鼠标内容消失
     */
    function showAndHideMsg(){
        $(document).on("mouseenter","td",function(){
            if (this.offsetWidth < this.scrollWidth) {
                let that = this;
                let text = $(this).text();
                let wid;

                if(text.length>1000){
                    wid = '900px';
                }else if(text.length>600){
                    wid = '700px';
                }else if(text.length>150){
                    wid = '500px';
                }else if(text.length>100){
                    wid = '250px';
                }else if(text.length>50){
                    wid = '150px';
                }
                layui.use('layer', function(layer) {
                    tip_index = layer.tips('<span style="word-wrap: break-word;">'+text+'</span>', that, {
                        tips: [4, "#000000"],
                        time: 0,
                        area: [wid, 'auto']
                    });
                });
            }
        });
        $(document).on("mouseout","td",function(){
            layui.use('layer', function(layer) {
                layer.close(tip_index);
            });
        });
    }
    showAndHideMsg();

    function getPageByEnv() {
        var selectedOption = $("#getPageByEnv option:selected")
        var param = selectedOption.text()
        url = '?env=' + param
        window.location.href = window.location.pathname + url;
    }

    $(".machine-status").each(function () {
        var text = $(this).text().trim()
        if (text === 'Online') {
            $(this).css("color", "#009688")
        } else {
            $(this).css("color", "#ff0000")
        }
    })
</script>
</body>
</html>