<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no">
    <th:block th:include="include :: header('下载管理表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>

<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <h4>任务列表</h4>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="" shiro:hasPermission="system:user:add">
                    <i class="fa fa-download"></i> 正在下载
                </a>
                <a class="btn btn-primary single disabled" onclick="" shiro:hasPermission="system:user:edit">
                    <i class="fa fa-upload"></i> 已下载
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
                <table id="bootstrap-table" class="fixed-layout-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: bootstrap-table-fixed-columns-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('dtp:pmService:edit')}]];
    var removeFlag = [[${@permission.hasPermi('dtp:pmService:remove')}]];
    var prefix = ctx + "xzgl/sxzgldownloadmanagement";
    $(function() {
        var panehHidden = false;
        if ($(this).width() < 1590) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win:$('.ui-layout-center'),
                doc:$('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryArchivesList();
    });

    function queryArchivesList() {
        var options = {
            url: prefix + "/sXzglDownloadManagementList",
            viewUrl: prefix + "/sXzglDownloadManagementView/{id}",
            createUrl: prefix + "/sXzglDownloadManagementAdd",
            updateUrl: prefix + "/sXzglDownloadManagementEdit/{id}",
            removeUrl: prefix + "/sXzglDownloadManagementRemove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "id",
            sortOrder: "asc",
            modalName: "下载管理表",
            fitColumns: true,
            striped: true,
            autoRowHeight: true,
            rowNumbers: true,
            showFooter:true,  //是否显示表格底部区域。
            clickToSelect: true, //是否启用点击行时选中整行的功能。
            singleSelect: false, //是否仅允许选择一行
            fixedColumns: true,
            //fixedNumber: 3,
            fixedRightNumber: 1,
            columns: [{
                checkbox: true
            },
                { field: 'id', title: '主键', align: 'center' ,visible:false},
                { field: 'name', title: '任务名称', align: 'center' },
                { field: 'startTime', title: '开始日期', align: 'center' },
                { field: 'endTime', title: '结束日期', align: 'center' },
                { field: 'createdDate', title: '创建时间', align: 'center' },
                {
                    field: 'extend',
                    title: '耗时',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (value) {
                            try {
                                // 尝试将字符串解析为 JSON 对象
                                var extendObj = JSON.parse(value);
                                return '<span style="color: #00B83F">' + extendObj.spendTime + '</span>';
                            } catch (e) {
                                // 如果解析失败，返回原始值或空字符串
                                console.error('Failed to parse extend value:', e);
                                return value;
                            }
                        } else {
                            return '';
                        }
                    }
                },
                { field: 'status', title: '状态', align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.id) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.save(\'' + row.id + '\')"><i class="fa fa-edit"></i>保存到本地</a> ');
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }]
        };
        $.table.init(options);
    }

    /* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
    function resetPre() {
        resetDate();
        $("#SXzglDownloadManagement-form")[0].reset();
        $.table.search();
        _refresh();
    }
    function edit_page(id){
        table.set();
        var url = "/404.html";
        if ($.common.isNotEmpty(id)) {
            url = table.options.updateUrl.replace("{id}", id);
        } else {
            var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            url = table.options.updateUrl.replace("{id}", id);
        }
        $.modal.openTab("修改" + table.options.modalName, url + "?editTage=1" );
    }

    /* 用户状态显示1成功，2进行中 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<span style="color: #00B83F">成功</span>';
        } else {
            return '<span style="color: #005cc5">进行中</span>';
        }
    }
</script>
</body>

</html>
