<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>


<script>
    /* *************************** 自定义模块 ***************************** */

    var repeatDatacollect = {
        dialog:null,
        grid:null,
        init:function(){
            var me = this;

            //控件初始化
            $("#selJob").ligerComboBox({
                dict:true,
                dictName:"RS_JOB_CONFIG",
                onSelected:function(value){
                    me.dataset.set({
                        parms: {jobId:value}
                    });
                    me.dataset.reload();
                }
            });
            me.dataset = $("#selJobDataset").ligerComboBox({
                url:"${contextRoot}/datacollect/getJobDatasetByJobId",
                delayLoad:true
            });

            $("#selJobStatus").ligerComboBox({dict:true,dictName:"JOB_STATUS"});
            $("#txtJobTimeFrom").ligerDateEditor();
            $("#txtJobTimeTo").ligerDateEditor();
            me.grid = $("#div_grid").ligerGrid({
                url: '${contextRoot}/datacollect/getJobLogDetail',
                delayLoad:true,//初始化不加载
                checkbox:true,
                selectRowButtonOnly:true,
                height:'100%',
                columns: [
                    {display:'任务名称',name:'jobId', width: '15%',dict:true,dictName:'RS_JOB_CONFIG'},
                    {display:'数据集名称',name:'jobDatasetName', width: '15%'},
                    {display:'采集开始时间',name:'startTime', width: '15%'},
                    {display:'采集结束时间',name:'endTime', width: '15%'},
                    {display:'采集状态',name:'jobStatus', width: '10%',dict:true,dictName:'JOB_STATUS'},
                    {
                        display:'操作',name:'id',width: '10%',render:function(row){
                            var html = '<div class="m-inline-buttons" style="width:40px;">';
                        if(row.jobStatus == '0'){
                                html += '<a href="javascript:void(0)" onclick="javascript:repeatDatacollect.repeat(\''+row.id+'\')">补采</a>';
                            }else{
                                html += '<span style="color:#ccc;">补采</span>';
                            }

                            return html;
                        }
                    },
                    {display:'信息',name:'jobContent', width: '20%'},
                ]
            });

            var data = {
                jobId:'${jobId}',
                jobDatasetId:'${jobDatasetId}',
                jobStatus:'${jobStatus}',
                jobTimeFrom:'${jobTimeFrom}',
                jobTimeTo:'${jobTimeTo}'
            };
            $("#dataForm").ligerAutoForm({
                data:data
            });

            me.bindEvents();
            me.search();
        },
        //绑定按钮事件
        bindEvents: function () {
            var me = this;
            $('#btnSearch').click(function () {
                me.search();
            });
            $('#div_back').click(function () {
                me.returnTrackJobManage();
            });
            $('#btnRepeat').click(function () {
                debugger
                var selected = me.grid.getSelectedRows();
                if(selected && selected.length>0)
                {
                    var ids ="";
                    for(var i=0;i<selected.length;i++)
                    {
//                        if(selected[i]["jobStatus"] == "1")
//                        {
//                            $.ligerDialog.warn("采集成功记录，无需重采");
//                        }else if(selected[i]["jobStatus"] == "0")
//                        {
//                            ids += selected[i]["id"]+",";
//                        }
                        ids += selected[i]["id"]+",";
                    }
                    if(ids.length>0)
                    {
                        ids=ids.substr(0,ids.length-1);
                        me.repeat(ids);
                    }
                    else{
                        return;
                    }
                }

            });
        },
        //搜索事件
        search:function(){
            var me = this;
            var data =$("#dataForm").ligerAutoForm("getData");
            me.grid.set({
                parms: data
            });
            me.grid.reload();
        },
        returnTrackJobManage: function () {
            indexPage.loadPage('${contextRoot}/datacollect/trackJob'),"","";
        },
        //补采数据
        repeat:function(ids){
            var me = this;
            $.ajax({ //ajax处理
                type: "POST",
                url : "${contextRoot}/datacollect/repeat",
                dataType : "json",
                data:{ids:ids},
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        $.ligerDialog.success(data.message);
                        me.grid.reload();
                    }
                    else{
                        $.ligerDialog.error(data.message);
                    }
                },
                error :function(data){
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                }
            });
        }
    }

    $(function () {
        repeatDatacollect.init();
    });
</script>


