<style>
    .layui-form-item{
        margin-bottom: 0px;
    }
    legend{
        font-size: 14px !important;
        color: #009688;
        font-weight: bold !important;
    }
</style>
<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
    <div class="layui-btn-container mw200">
        {{if eq $.task.Status 2}}
            <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="audit">审核通过</button>
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="nopass">审核不通过</button>
        {{end}}
        {{if eq $.task.Status 1}}
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="pause">暂停任务</button>
        {{end}}
        {{if eq $.task.Status 0}}
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="start">启动任务</button>
        {{end}}

        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="edit">编辑任务</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="run">测试执行</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="log">任务日志</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="copy">复制任务</button>
        <button lay-submit class="layui-btn  layui-btn-sm layui-btn-primary" lay-filter="del">删除任务</button>
    </div>

    <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;padding-right: 10px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{.task.TaskName}}（#{{.task.Id}}）任务详细</legend>
        </fieldset>
        <table class="layui-table" lay-skin="nob" lay-size="sm">
            <colgroup>
                <col width="80">
                <col width="400">
                <col>
            </colgroup>

            <tbody>

            <tr>
                <td>任务说明</td>
                <td>{{.task.TaskName}}</td>
                <td></td>
            </tr>
            <tr>
                <td>任务状态</td>
                <td>{{.TextStatus|str2html}}</td>
                <td></td>
            </tr>

            <tr>
                <td>执行次数</td>
                <td>{{.task.ExecuteTimes}}</td>
                <td></td>
            </tr>

            <tr>
                <td>任务分组</td>
                <td> {{.GroupName}}</td>
                <td></td>
            </tr>
            <tr>
                <td>执行资源</td>
                <td>  {{str2html .serverName}}</td>
                <td></td>
            </tr>

            <tr>
                <td>执行策略</td>
                <td>  {{.ServerType}}</td>
                <td></td>
            </tr>
            <tr>
                <td>是否单例</td>
                <td>{{if eq .task.Concurrent 0}}是{{end}} {{if eq .task.Concurrent 1}}否{{end}}</td>
                <td></td>
            </tr>
            <tr>
                <td>执行时间</td>
                <td> {{.task.CronSpec}}</td>
                <td></td>
            </tr>

            <tr>
                <td>命令脚本</td>
                <td>{{.task.Command}}</td>
                <td></td>
            </tr>

            <tr>
                <td>超时设置</td>
                <td>{{.task.Timeout}}</td>
                <td></td>
            </tr>

            <tr>
                <td>出错通知</td>
                <td>{{if eq .task.IsNotify 0}}否{{end}} {{if eq .task.IsNotify 1}}是{{end}}</td>
                <td></td>
            </tr>

            {{if eq .task.IsNotify 1}}
            <tr>
                <td>通知类型</td>
                <td>{{if eq .task.NotifyType 1}}短信{{end}} {{if eq .task.NotifyType 0}}邮件{{end}} {{if eq .task.NotifyType 2}}钉钉{{end}} {{if eq .task.NotifyType 3}}微信{{end}}</td>
                <td></td>
            </tr>

            <tr>
                <td>通知模板</td>
                <td>{{.NotifyTplName}}</td>
                <td></td>
            </tr>

            <tr>
                <td>通知用户</td>
                <td>
                {{range $k, $v := .adminInfo}}
                    {{$v.RealName}} &nbsp;<br>
                {{end}}
                </td>
                <td></td>
            </tr>

            {{end}}

            <tr>
                <td>创建时间</td>
                <td>{{.CreateTime}}</td>
                <td></td>
            </tr>

            <tr>
                <td>创建人</td>
                <td>{{.CreateName}}</td>
                <td></td>
            </tr>

            <tr>
                <td>修改时间</td>
                <td>{{.UpdateTime}}</td>
                <td></td>
            </tr>

            <tr>
                <td>最后修改人</td>
                <td>{{.UpdateName}}</td>
                <td></td>
            </tr>

            </tbody>
        </table>
        <input type="hidden" name="id" id="id" value="{{.task.Id}}">
    </div>


</div>
<script>
    layui.use(['form','element','layer','jquery'],function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var id = $("#id").val();
        var error_info = "{{.flash.error}}";
        if(error_info){
            layer.msg(error_info,{icon: 2,shade:0.3},function () {
                window.history.go(-1)
            })
            return;
        }
        var task_name = "{{.task.TaskName}}";
        $('.layui-btn-container button').on('click',function () {
            var event = $(this).attr('lay-filter');

            if (event==='edit'){
                var status =" {{.task.Status}}";
                if(status==1){
                    layer.msg("运行状态无法编辑任务，请先暂停任务");
                    return;
                }
                window.parent.openTab("/task/edit?id="+id,task_name+' 编辑',"admin_task_edit-"+id,'fa-edit');
            }else if(event==='log'){
                window.parent.openTab("/tasklog/list?task_id="+id,task_name+'日志',"admin_log-"+id,'');
            }else if(event==='copy'){
                window.parent.openTab("/task/copy?id="+id,task_name+' 复制',"admin_task_copy-"+id,'fa-copy');
            }else if(event==="del"){
                var status =" {{.task.Status}}";
                if(status==1){
                    layer.msg("运行状态无法删除任务，请先暂停任务");
                    return;
                }

                layer.confirm("确认要删除这条任务吗？", {icon: 3, title:'提示'}, function(index){
                    layer.load();
                    $.post('/task/ajaxdel', {id:id}, function (out) {

                        if (out.status == 0) {
                            layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                                window.parent.deleteCurrentTab();
                            })
                        } else {
                            layer.msg(out.message);
                            return
                        }
                    }, "json");

                    setTimeout(function(){
                        layer.closeAll('loading');
                    }, 2000);

                    layer.close(index);
                });

            }else if (event==='run'){
                layer.confirm("测试执行任务，注意不要超时，请确认执行", {icon: 3, title:'提示'}, function(index){
                    layer.load();
                    $.post('/task/ajaxrun', {id:id}, function (out) {
                        if (out.status == 0) {
                            layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                                window.parent.openTab("/tasklog/list?task_id="+id,task_name+' 日志',"admin_task_log-"+id,'');

                            })
                        } else {
                            layer.msg(out.message)
                            return
                        }
                    }, "json");
                    setTimeout(function(){
                        layer.closeAll('loading');
                    }, 2000);
                    layer.close(index);
                });
            }else if (event==='audit' || event==='start' || event==='pause' || event==="nopass"){
                $.post('/task/ajax'+event, {id:id}, function (out) {
                    if (out.status == 0) {
                        layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                            window.location.reload()
                        })
                    } else {
                        layer.msg(out.message)
                        return
                    }
                }, "json");
                return
            }else{
                layer.msg("操作不存在")
            }
        })


        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();
    });
</script>