{{include "com/inc.html"}}
<!-- Main Header -->
{{include "com/header.html"}}
<!-- Left side column. 权限菜单 -->
{{include "com/menu.html"}}
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            <small></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 任务列表</a></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">

                        <div class="form-horizontal">
                            <div class="box-body margin">
                                <table id="dataTable" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th></th>
                                        <th>公司名称</th>
                                        <th>部门名称</th>
                                        <th>规则名称</th>
                                        <th>项目名称</th>
                                        <th>用户组名称</th>
                                        <th>负责人</th>
                                        <th>清洗数据量</th>
                                        <th>任务状态</th>
                                        <th>完成进度</th>
                                        <th>任务时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
</div>

{{include "com/footer.html"}}
<script>
    menuActive("/front/group/admin/task/list");

    $(function () {
        ttable = $('#dataTable').dataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "serverSide": true,
            "ajax": {
                "url": "/front/group/admin/task/list",
                "type": "post",
                "data": {"status": "-1"}
            },
            "language": {
                "url": "/dist/js/dataTables.chinese.lang"
            },
            "fnDrawCallback": function () {
                $("ul.pagination").prepend("&nbsp;&nbsp;&nbsp;转到第 <input type='text' id='changePage'   style='width:20px;'> 页    <a type='text' href='javascript:void(0);' id='dataTable-btn' style='text-align:center'>GO</a>");
                $('#dataTable-btn').click(function (e) {
                    var redirectpage = 0
                    if ($("#changePage").val() && $("#changePage").val() > 0) {
                        var redirectpage = $("#changePage").val() - 1;
                    }
                    ttable.page(redirectpage).draw(false);
                });
                this.api().column(0).nodes().each(function (cell, i) {
                    cell.innerHTML = i + 1;
                });
            },
            "columns": [
                {"data": null, width: "1%"},
                {"data": "s_entname", width: "4%"},
                {"data": "s_departname", width: "4%"},
                {"data": "s_rulename", width: "4%"},
                {"data": "s_projectname", width: "4%"},
                {"data": "s_groupname", width: "4%"},
                {"data": "s_personname", width: "4%"},
                {"data": "i_givenum", width: "4%"},
                {"data": "s_status", width: "4%"},
                {"data": "s_progress", width: "4%"},
                {
                    "data": "_id", width: "4%", render: function (val, a, row) {
                        let str = ""
                        if (row['i_starttime'] === undefined) {
                            str = "未开始"
                        }else if (row['i_starttime'] && row['i_completetime'] === undefined) {
                            let dt = new Date()
                            dt.setTime(parseInt(row['i_starttime']) * 1000);
                            str = dt.format("yyyy-MM-dd") + " - 未结束"
                        }else {
                            let dt = new Date()
                            let ds = new Date()
                            dt.setTime(parseInt(row['i_starttime']) * 1000);
                            ds.setTime(parseInt(row["i_completetime"]) * 1000)
                            str = dt.format("yyyy-MM-dd") + " - " + ds.format("yyyy-MM-dd")
                        }
                        return str
                    }
                },
                {
                    "data": "_id", width: "11%", render: function (val, a, row, pos) {
                        tmp = '<div>' +
                            '<a class="btn btn-sm btn-primary" href="/front/user/task/save?tid=' + val + '">查看</a>&nbsp;&nbsp;' +
                            '<a class="btn btn-sm btn-warning" onclick="retrieveTask(' + row + ')">收回</a>&nbsp;&nbsp;' +
                            '<a class="btn btn-sm btn-info">质检</a>&nbsp;&nbsp;' +
                            '<a class="btn btn-sm btn-info" onclick="closeTask(\'' + val + '\',\'' + row.s_status + '\')">关闭</a>&nbsp;&nbsp;' +
                            '</div>';
                        return tmp
                    }
                }
            ]
        });
    });

    // 收回
    function retrieveTask(row) {
        $.ajax({
            url: "/front/project/task/retrieve",
            type: 'POST',
            data: {"s_status": row.s_status, "id": row._id, "s_groupid": row.s_groupid, "s_sourceinfo": row.s_sourceinfo,
                "s_sourcetaskinfo": row.s_sourcetaskinfo},
            success: function (r) {
                if (r.success) {
                    ttable.api().ajax.reload()
                } else {
                    showTip(r.msg);
                }
            }
        })
    }
    function closeTask(val, status) {
        $.ajax({
            url: "/front/project/task/close",
            type: 'POST',
            data: {"s_status": status, "id": val},
            success: function (r) {
                if (r.success) {
                    ttable.api().ajax.reload()
                } else {
                    showTip(r.msg);
                }
            }
        })
    }

</script>
