{{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">
                        <hr>
                        <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>
                                    </tr>
                                    </thead>
                                </table>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
</div>

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

    $(function () {
        ttable = $('#dataTable').dataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "serverSide": true,
            "ajax": {
                "url": "/front/user/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": "", width: "1%"},
                {"data": "s_personname", width: "5%"},
                {"data": "s_projectname", width: "4%"},
                {"data": "i_givenum", width: "4%"},
                {"data": "", width: "4%"},
                {"data": "", width: "4%"},
                {"data": "", width: "4%"},
                {"data": "", width: "4%"},
                {
                    "data": "_id", width: "11%", render: function (val, a, row, pos) {
                        tmp = '<div>' +
                            '<a class="btn btn-sm btn-primary" onclick="editPro(\'' + pos.row + '\')">收回</a>&nbsp;&nbsp;' +
                            '<a class="btn btn-sm btn-warning" href="/front/project/clear?pid=' + val + '">质检</a>&nbsp;&nbsp;' +
                            '<a class="btn btn-sm btn-info" onclick="del(\'' + val + '\')">关闭</a>&nbsp;&nbsp;' +
                            '</div>';
                        return tmp
                    }
                }
            ]
        });

        $('input[type=radio][name=stype]').change(function () {
            if (this.value === 'coll') {
                stype = "coll"
                $("#import-coll").attr("style", "display:block;")
                $("#import-excel").attr("style", "display:none;")
            } else if (this.value === 'excel') {
                stype = "excel"
                $("#import-coll").attr("style", "display:none;")
                $("#import-excel").attr("style", "display:block;")
            }
        });
    });


    function del(id) {
        showConfirm("确定删除该用户组？", function () {
            $.ajax({
                url: "",
                type: 'POST',
                data: {"id": id},
                success: function (r) {
                    if (r.rep) {
                        ttable.ajax.reload();
                    } else {
                        showTip("状态修改失败");
                    }
                }
            })
        })
    }

    function createPro() {
       $("#modal-create-project").modal('show')
    }

    function cancelModel() {
        document.getElementById("model-form-project").reset();
        $("#modal-create-project").modal('hide')
        $("#modal-edit-project").modal('hide')
    }

    function editPro(index) {
        projectmap = ttable.fnGetData()[index]
        console.log(projectmap)
        $('#modal-edit-project').modal('show')
        $('#company-edit-name').val(projectmap["s_entname"])
        $('#rule-edit-name').val(projectmap["s_rulename"])
        $('#dpart-edit-name').val(projectmap["s_departname"])
    }

    function saveData() {
        stype = "edit"
        let tmp = projectmap
        tmp["s_entname"] = $('#company-edit-name').val()
        tmp["s_rulename"] = $('#rule-edit-name').val()
        tmp["s_departname"] = $('#dpart-edit-name').val()

        let fieldArr = $('#markFieldSelect').val();
        let m = {}
        if (fieldArr.length > 0) {
            for (const i in fields) {
                if (fieldArr.indexOf(fields[i]["s_code"]) > -1) {
                    m[fields[i]["s_code"]] = fields[i]["s_name"]
                }
            }
        }
        tmp["v_field"] = m
        if (tmp !== projectmap) {
            $.ajax({
                url: "/front/project/save",
                type: 'POST',
                data: projectmap,
                success: function (r) {
                    if (r.rep) {
                        ttable.api().ajax.reload();
                    } else {
                        showTip("保存失败");
                    }
                }
            })
        } else {
            showTip("未做修改");
        }
    }

</script>
