@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['commonTable', 'form', 'table', 'common', 'optimizeSelectOption'], function () {
        var commonTable = layui.commonTable,
            form = layui.form,
            table = layui.table,
            common = layui.common;
        wcLoading.close();
        //权限控制(js是值传递)
        currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        commonTable.rendertable({
            elem: '#currentTableId',
            id: 'currentTableId',
            url: '/SystemSecurity/OpenJobs/GetGridJson',
            page: false,
            cols: [[
                { type: "radio", width: 50, fixed: 'left' },
                { field: 'F_JobName', title: '名称', minWidth: 230, sort: true },
                { field: 'F_JobGroup', title: '组名', minWidth: 180, sort: true },
                { field: 'F_IsLog', title: '是否记录日志', width: 130, sort: true },
                {
                    field: 'F_JobType', title: '类型', width: 100, sort: true,
                    templet: function (d) {
                        return top.clients.dataItems["JobType"][d.F_JobType] == undefined ? "" : top.clients.dataItems["JobType"][d.F_JobType];
                    }
                },
                {
                    field: 'F_EnabledMark', title: '任务状态', width: 110, sort: true,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                },
                { field: 'F_LastRunTime', title: '最近执行时间', width: 160, sort: true },
                { field: 'NextValidTimeAfter', title: '下次执行时间', width: 160 },
                {
                    field: 'F_LastRunMark', title: '最近执行状态', width: 130, sort: true,
                    templet: function (d) {
                        if (d.F_LastRunMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>成功</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>失败</span>";
                        }
                    }
                },
                { field: 'F_LastRunErrTime', title: '上次发生错误时间', width: 160, sort: true },
                { field: 'F_LastRunErrMsg', title: '上次发生错误信息', width: 180, sort: true },
                { field: 'F_StarRunTime', title: '最近启动时间', width: 170, sort: true },
                { field: 'F_EndRunTime', title: '最近关闭时间', width: 170, sort: true },
                { field: 'F_FileName', title: '文件名', width: 180, sort: true  ,hide:true},
                { field: 'F_RequestUrl', title: '请求地址', width: 180, sort: true  ,hide:true},
                { field: 'F_RequestHeaders', title: '请求头', width: 180, sort: true ,hide:true },
                { field: 'F_RequestString', title: '请求参数', width: 180, sort: true  ,hide:true},
                { field: 'F_JobDBProvider', title: '执行数据库', width: 180, sort: true  ,hide:true},
                { field: 'F_JobSql', title: '执行SQL', width: 180, sort: true  ,hide:true},
                { field: 'F_JobSqlParm', title: 'Sql参数', width: 180, sort: true ,hide:true },
                { field: 'F_CronExpress', title: 'CRON', width: 150 },
                { field: 'F_Description', title: '备注', width: 150, sort: true },
                { title: '操作', width: 300, toolbar: '#currentTableBar', align: "center", fixed: 'right' }

            ]]
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            commonTable.reloadtable({
                elem: 'currentTableId',
                page: false,
                curr: 1,
                where: { keyword: data.field.txt_keyword }
            });
            return false;
        });
        //行点击事件监听，控制按钮显示
        var oneList = ["NF-edit", "NF-delete", "NF-disabled", "NF-enabled", "NF-edit", "NF-log", "NF-doNow"];//选择1条显示
        commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList);
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var data = table.checkStatus('currentTableId').data;
            if (obj.event === 'add') {  // 监听删除操作
                common.modalOpen({
                    title: "添加任务",
                    url: "/SystemSecurity/OpenJobs/Form",
                    width: "750px",
                    height: "650px",
                });
            }
            else if (obj.event === 'delete') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemSecurity/OpenJobs/DeleteForm",
                    param: { keyValue: data[0].F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "修改任务",
                    url: "/SystemSecurity/OpenJobs/Form?keyValue=" + data[0].F_Id,
                    width: "750px",
                    height: "650px",
                });
            }
            else if (obj.event === 'clear') {
                common.submitPost({
                    prompt: "注：您确定要【清除所有任务计划】吗？",
                    url: "/SystemSecurity/OpenJobs/ClearScheduleJob",
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'doNow') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.submitPost({
                    prompt: "注：您确定要【执行】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/DoNow",
                    param: { keyValue: data[0].F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'disabled') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                if (data[0].F_EnabledMark != true) {
                    common.modalMsg("任务未启动，无法关闭！", "warning");
                    return false;
                }
                common.submitPost({
                    prompt: "注：您确定要【关闭】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/ChangeStatus",
                    param: { keyValue: data[0].F_Id, status: 0 },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'enabled') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                if (data[0].F_EnabledMark == true) {
                    common.modalMsg("任务已启动，无法启动！", "warning");
                    return false;
                }
                common.submitPost({
                    prompt: "注：您确定要【启动】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/ChangeStatus",
                    param: { keyValue: data[0].F_Id, status: 1 },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'log') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "任务日志",
                    url: "/SystemSecurity/OpenJobs/Details?keyValue=" + data[0].F_Id,
                    width: "700px",
                    height: "600px",
                    btn: []
                });
            }
            else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                    _that.removeClass('layui-hide');
                } else {
                    _that.addClass('layui-hide');
                }
                table.resize();
            }
            return false;
        });
        //toolrow监听事件
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'delete') {
                common.deleteForm({
                    url: "/SystemSecurity/OpenJobs/DeleteForm",
                    param: { keyValue: obj.data.F_Id },
                    success: function () {
                        obj.del();
                    }
                });
            }
            else if (obj.event === 'edit') {
                common.modalOpen({
                    title: "修改任务",
                    url: "/SystemSecurity/OpenJobs/Form?keyValue=" + obj.data.F_Id,
                    width: "750px",
                    height: "650px",
                });
            }
            else if (obj.event === 'doNow') {
                common.submitPost({
                    prompt: "注：您确定要【执行】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/DoNow",
                    param: { keyValue: obj.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'disabled') {
                if (obj.data.F_EnabledMark != true) {
                    common.modalMsg("任务未启动，无法关闭！", "warning");
                    return false;
                }
                common.submitPost({
                    prompt: "注：您确定要【关闭】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/ChangeStatus",
                    param: { keyValue: obj.data.F_Id, status: 0 },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'enabled') {
                if (obj.data.F_EnabledMark == true) {
                    common.modalMsg("任务已启动，无法启动！", "warning");
                    return false;
                }
                common.submitPost({
                    prompt: "注：您确定要【启动】该项任务吗？",
                    url: "/SystemSecurity/OpenJobs/ChangeStatus",
                    param: { keyValue: obj.data.F_Id, status: 1 },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'log') {
                common.modalOpen({
                    title: "任务日志",
                    url: "/SystemSecurity/OpenJobs/Details?keyValue=" + obj.data.F_Id,
                    width: "700px",
                    height: "600px",
                    btn: []
                });
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset layui-hide" id="searchField">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-clear" name="NF-clear" authorize class="layui-btn layui-btn-sm" lay-event="clear"><i class="layui-icon">&#xe665;</i>清除任务计划</button>
                <button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                <button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-doNow" name="NF-doNow" authorize class="layui-btn layui-btn-sm layui-btn-normal layui-hide" lay-event="doNow"><i class="layui-icon">&#xe609;</i>执行</button>
                <button id="NF-enabled" name="NF-enabled" authorize class="layui-btn layui-btn-sm layui-hide" lay-event="enabled"> <i class="fa fa-play-circle"></i>启动</button>
                <button id="NF-disabled" name="NF-disabled" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="disabled"><i class="fa fa-stop-circle"></i>关闭</button>
                <button id="NF-log" name="NF-log" authorize class="layui-btn layui-btn-sm layui-btn-normal layui-hide" lay-event="log"><i class="layui-icon">&#xe702;</i>日志</button>
            </div>
        </script>
        <script type="text/html" id="currentTableBar">
            <a id="NF-edit" authorize class="layui-btn layui-btn-xs  layui-btn-warm" lay-event="edit">修改</a>
            <a id="NF-delete" authorize class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
            <a id="NF-doNow" authorize class="layui-btn layui-btn-xs layui-btn-normal" lay-event="doNow">执行</a>
            <a id="NF-enabled" authorize class="layui-btn layui-btn-xs" lay-event="enabled">启用</a>
            <a id="NF-disabled" authorize class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disabled">禁用</a>
            <a id="NF-log" authorize class="layui-btn layui-btn-xs layui-btn-normal" lay-event="log">日志</a>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>