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

<script src="${contextRoot}/develop/lib/plugin/steps/jquery.steps.min.js"></script>

<script>
    var editorJob={
        flowTempId:'${model.flowTempId}',
        flowArrays:[],
        beforeServeTime:false,
        archiveCollect:"0",
        crawlerFlowUpload:"1",
        $form:$("#div_form"),
        $listPlan:null,//适配方案列表
        $listDataset:null,//数据集列表
        $crawlerFlowDataset:null,//任务编排数据集列表
        $conditionDialog:null,//数据集配置条件弹窗
        $condition:null,//条件选择控件
        needReload:true, //需要刷新关联数据集
        needReloadCrawlerDst:false,//判断是否类名为任务编排上传类
        actionUrl:"${contextRoot}/datacollect/addJob",
        //初始化
        init: function ()
        {
            var me = this;
            me.getFlowList();
            //表单向导
            $("#div_form").show().steps({
                //transitionEffect: "fade",
                onStepChanging:function(d,from,to){

                    if(from>to){
                        return true;
                    }
                    else{
                        return me.verify(to);
                    }
                },
                onStepChanged:function(b,to,from){
                    if(to==1){
                        me.$listPlan._setData($.parseJSON('${schemeList}'));
                        me.$listPlan.reRender();
                    }
                    else if(to==2){
                        //接口为档案上传时，数据集不可编辑

                        me.$listDataset.set("columns", [
                            { display: '数据集代码', name: 'jobDatasetCode' },
                            { display: '数据集名称', name: 'jobDatasetName' },
                            { display: '执行条件', name: 'jobDatasetCondition', render: function (row,rowIndex) {
                                var html = '<div class="m-inline-buttons" style="width:55px;">';

                                html += "<a href=\"javascript:void(0)\" onclick=\"javascript:editorJob.setCondition("+rowIndex+");\">设置筛选</a>";
                                return html;
                            } }
                        ]);
                        $("#listDataset").show();
                        $("#crawlerListDataset").hide();
                        //刷新数据集
                        if(me.needReload)
                        {
                            me.$listDataset.set({
                                parms: {jobId:$('#txtId').val(),schemeId:$("#txtSchemeId").val(),schemeVersion:$("#txtSchemeVersion").val()}
                            });

                            me.$listDataset.reload();
                            me.needReload=false;
                        }
                        if(me.needRender)
                        {
                            me.$listDataset.setData($("#txtJobDataset").val());
                            me.$listDataset.reRender();
                        }
                    }
                    else if(to==3)
                    {
                        me.setAchiveUploadType();
                    }else{
                        liger.get("jobContentClass").selectValue(me.flowTempId);

                    }
                },
                onFinishing:function(c,a){
                    editorJob.setCheckVal();
                    return me.verify(4);
                },
                onFinished:function(c,a){
                    me.save();
                },
                onCanceled:function(){
                    if(parent.trackJob != undefined)
                        parent.trackJob.dialog.close();
                    else
                        parent.configJob.dialog.close();
                }
            });

            $("#divCondition").show();
            me.initForm();
            $("#divCondition").hide();
        },
        //初始化表单控件
        initForm:function(){
            var me = this;

            //按钮控件
            $("a[href='#finish']").addClass("l-button-green");
            $("a[href='#cancel']").addClass("l-button-no");

            //业务类型
//            $('#jobContentClass').ligerComboBox({
//                dict:true,
//                dictName:'JOB_CONTENT_CLASS',
//                onChange:function(){
//                    me.needRender = true;
//                }
//            });


            $("#jobContentClass").ligerComboBox({data : editorJob.flowArrays,
                cancelable:false,
                onSuccess:function(data){
                }});

            $('input[name="jobContentType"]').ligerRadio();

            $(document).on('click','input[name="jobContentType"]',function(){
                var value = $(this).val();
                me.setJobContentType(value,"");
            });

            //适配方案列表
            me.$listPlan = $("#listPlan").ligerGrid({
                data: $.parseJSON('${schemeList}'),
                columns: [
                    { display: '版本号', name: 'name' }
                ],
                groupColumnName:'schemeName',
                groupColumnDisplay:'方案',
                alternatingRow:true,
                selectRowButtonOnly:true,
                rownumbers:false,
                usePager:false,
                isSingleCheck:true,
                checkbox:true,
                height:340,
                width:360,
                hideHeader:true,
                isChecked:function(row){
                    if($("#txtSchemeVersion").val()==row.version)
                    {
                        if(me.needReloadCrawlerDst && $('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload){//类名为任务编排上传类
                            me.$crawlerFlowDataset.setOptions({parms: [{ name: 'version', value:row.id}],checkbox:false});
                            me.$crawlerFlowDataset.loadData(true);
                            me.needReloadCrawlerDst = false;
                        }
                        return true;
                    }
                    else{
                        return false;
                    }
                },
                onCheckRow:function(checked,data,rowid,rowdata)
                {
                    var selected = me.$listPlan.getSelectedRow();
                    if(selected!=null)
                    {
                        $("#txtSchemeId").val(selected.schemeId);
                        $("#txtSchemeVersion").val(selected.version);
                    }
                    else{
                        $("#txtSchemeId").val("");
                    }
                    me.needReload=true;
                }
            });

            //数据集列表
            $("#jobDatasetKey").ligerComboBox({
                textField:"text",
                extendField:"type",
                onSelected:function(value,text,row){
                    if(row!=null)
                    {
                        $("#jobDatasetKeytype").ligerComboBox("setValue",row.type);
                    }

                }
            });
            $("#jobDatasetKeytype").ligerComboBox({data:[{value:"字符串",code:"VARCHAR"},{value:"数值",code:"NUMERIC"},{value:"时间",code:"DATE"}]});
            me.$listDataset = $("#listDataset").ligerGrid({
                url:"${contextRoot}/datacollect/getSchemeDataset",
                dataType : "json",
                cache:false,
                columns: [
                    { display: '数据集代码', name: 'jobDatasetCode' },
                    { display: '数据集名称', name: 'jobDatasetName' },
                    { display: '执行条件', name: 'jobDatasetCondition', render: function (row,rowIndex) {
                        var html = '<div class="m-inline-buttons" style="width:55px;">';

                        html += "<a href=\"javascript:void(0)\" onclick=\"javascript:editorJob.setCondition("+rowIndex+");\">设置筛选</a>";
                        return html;
                    } }
                ],
                delayLoad:true,//初始化不加载
                alternatingRow:true,
                selectRowButtonOnly:true,
                rownumbers:false,
                usePager:false,
                checkbox:true,
                height:340,
                width:360,
                //默认选中
                isChecked:function(row){
                    if(row.checked=="1")
                    {
                        return true;
                    }
                    else{
                        return false;
                    }
                },
                //选中修改值
                onCheckRow:function(checked,data,rowid,rowdata)
                {
                    //修改行checked值
                    if(checked)
                        data.checked ="1";
                    else
                        data.checked ="0";
                    editorJob.setCheckVal();
                },
                //全选事件
                onCheckAllRow:function(){
                    me.setCheckVal();
                },
                //加载完成后赋值$("#txtJobDataset")
                onAfterShowData:function(grid)
                {
                    editorJob.setCheckVal();
                }
            });

            //任务编排上传类的数据集列表
            me.$crawlerFlowDataset = $("#crawlerListDataset").ligerGrid({
                url: '${contextRoot}/crawler/savedJobData',
                dataType : "json",
                cache:false,
                columns: [
                    { display: '数据集代码', name: 'jobDatasetCode' },
                    { display: '数据集名称', name: 'jobDatasetName' }
                ],
                delayLoad:true,//初始化不加载
                alternatingRow:true,
                selectRowButtonOnly:true,
                rownumbers:false,
                usePager:false,
                checkbox:false,
                height:340,
                width:360
            });

            //初始化条件选择控件
            $('#jobDatasetCondition').ligerCondition({
                stdDictUrl:"${contextRoot}/std/getDictByScheme"
            });
            $('#btnCancelCondition').click(function () {
                $("#divCondition").hide();
            });
            $('#btnSaveCondition').click(function () {
                $("#divCondition").hide();

                var key = $("#jobDatasetKey").ligerComboBox("getValue");
                var dataType = $("#jobDatasetKeytype").ligerComboBox("getValue");
                var dataKey = $("#jobDatasetKeyvalue").val();
                var condition = $('#jobDatasetCondition').ligerCondition("getValue");
                me.callbackCondition(key,dataType,dataKey,condition);
            });


            //执行计划
            $("#dateNextTime").ligerDateEditor({
                width: 240,
                showTime: true
            });
            $('input[name="jobType"]').ligerRadio();
            $('input[name="interval_type"]').ligerRadio();
            $(document).on('click','input[name="jobType"]',function(){
                var value = $(this).val();
                me.setAchiveUploadType(value);
            });
            $(document).on('click','input[name="interval_type"]',function(){
                //清空数据
                $("#txtCronExpression").val("");
                me.initInterval();

                $(".divIntervalOption").hide();
                $("#divIntervalOption"+$(this).val()).show();
            });
            $("#txtM").ligerSpinner({width: 208,type: 'int',minValue:1});
            $("#txtH").ligerSpinner({width: 208,type: 'int',minValue:1});
            $("#txtD").ligerSpinner({width: 208,type: 'int',minValue:1});
            $("#txtMD").ligerSpinner({width: 160,type: 'int',minValue:1});

            $('input[name="week_day"]').ligerCheckBox();
            $('input[name="month_day"]').ligerRadio();

            $(document).on('click','input[name="month_day"]',function(){
                var val = $(this).val();
                if(val=="2")
                {
                    $("#txtMD").removeAttr("disabled");
                }
                else
                {
                    $("#txtMD").attr("disabled",true);
                }
            });

            /** 档案上传参数 **/
            $("#txtDelayTime").ligerSpinner({width: 240,type: 'int',minValue:1});
            $("#repeatStartTime").ligerDateEditor({
                width: 240,
                showTime: true
            });
            $("#repeatEndTime").ligerDateEditor({
                width: 240,
                showTime: true
            });

            me.initData();
        },
        //初始化数据
        initData:function(){
            var me = this;
            var modelString = "${model.id}";
            if(modelString!=undefined && modelString!=null && modelString.length>0)
            {
                me.actionUrl = "${contextRoot}/datacollect/updateJob";
                flowTempId = "${model.flowTempId}";
                liger.get("jobContentClass").selectValue(flowTempId);
                $('#flowId').val( '${model.flowId}');
                var model ={
                    id:'${model.id}',
                    jobName: '${model.jobName}',
                    jobInfo: '${model.jobInfo}',
                    jobContent: '${model.jobContent}',
                    jobContentType: '${model.jobContentType}',
                    jobType:'${model.jobType}',
                    schemeId: '${model.schemeId}',
                    schemeVersion: '${model.schemeVersion}',
                    valid: '${model.valid}',
                    flowId: '${model.flowId}',
                    flowTempId: '${model.flowTempId}',
                    cronExpression: '${cronExpression}',
                    jobNextTime: '${model.jobNextTime}',
                    repeatStartTime:'${model.repeatStartTime}',
                    repeatEndTime:'${model.repeatEndTime}',
                    delayTime:'${model.delayTime}',
                    jobCron:'${model.jobCron}',
                };

                $('#txtId').val(model.id);
                $('#txtJobName').val(model.jobName);
                $('#txtJobInfo').val(model.jobInfo);

                $("#jobDatasetKeyvalue").val();
                $('input[name="jobContentType"]').ligerRadio('setValue',model.jobContentType);
                me.setJobContentType(model.jobContentType,model.jobContent);

                $('input[name="jobType"]').ligerRadio('setValue',model.jobType);

                //非档案上传时隐藏

                if($('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload) {
                    $("#divDelayTime").show();
                    $("#divRepeat").show();
                }

                if(model.jobType=="0")//单次执行
                {
                    $("#divTimeInterval").hide();
                    //接口为档案上传时
                    if( $('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload) {
                        $("#divDelayTime").show();
                        $("#divRepeat").show();
                        $("#repeatStartTime").ligerDateEditor("setValue",model.repeatStartTime);
                        $("#repeatEndTime").ligerDateEditor("setValue",model.repeatEndTime);
                    }
                }
                else{
                    $("#divTimeInterval").show();
                    //接口为档案上传时
                    if( $('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload) {
                        $("#divDelayTime").show();
//                        $("#divRepeat").hide();
                        $("#repeatStartTime").ligerDateEditor("setValue",model.repeatStartTime);
                        $("#txtDelayTime").val(model.delayTime);
                    }
                }
                $('#txtSchemeId').val(model.schemeId);
                $('#txtSchemeVersion').val(model.schemeVersion);
                $('#txtCronExpression').val(model.jobCron);
                $('#txtValid').val(model.valid);
                $("#dateNextTime").ligerDateEditor('setValue',model.jobNextTime);

                me.skip(3);//跳到最后面板
                //赋值执行计划
                me.initInterval();
            }
        },
        //获取数据
        getData:function(){
            var me = this;
            var type = $('input[name="jobContentType"]').ligerRadio('getValue');
            var content = $("#jobContentClass").ligerComboBox("getValue");


//            if($('input[name="jobContentType"]').ligerRadio("getValue")==me.crawlerFlowUpload) {//任务编排上传类，不需要选择数据集,直接设值
//                $("#txtJobDataset").val(JSON.stringify(me.$crawlerFlowDataset.getData()));
//            }

            var model ={
                id:$('#txtId').val(),
                jobName: $('#txtJobName').val(),
                jobInfo: $('#txtJobInfo').val(),
                jobContent: content,
                jobContentType: type,
                jobType: $('input[name="jobType"]').ligerRadio('getValue'),
                schemeId:  $('#txtSchemeId').val(),
                schemeVersion: $('#txtSchemeVersion').val(),
                valid:  $('#txtValid').val(),
                cronExpression: $('#txtCronExpression').val(),
                jobNextTime: $("#dateNextTime").ligerDateEditor('getValue'),
                jobDataset: $('#txtJobDataset').val(),
                flowTempId: $('#jobContentClass').ligerDateEditor('getValue'),
                flowId: $('#flowId').val(),
                repeatStartTime: $("#repeatStartTime").ligerDateEditor('getValue'),
                repeatEndTime: $("#repeatEndTime").ligerDateEditor('getValue'),
                delayTime: $('#txtDelayTime').val(),
                jobCron:$('#txtCronExpression').val(),
                dataKey:$('#jobDatasetKeyvalue').val()
            };

            return model;
        },
        //改变为档案上传接口，执行方式修改时触发,清空数据
        setAchiveUploadType:function(jobType){

            var me = this;
            if(jobType==undefined)
            {
                jobType = $('input[name="jobType"]').ligerRadio("getValue");
            }

            if( $('input[name="jobContentType"]').ligerComboBox("getValue")!=me.crawlerFlowUpload) {
                $("#divDelayTime").hide();
                $("#divRepeatStart").hide();
                $("#divRepeatEnd").hide();
                $("#txtM").val("");
                $("#repeatStartTime").ligerDateEditor("setValue","");
                $("#repeatEndTime").ligerDateEditor("setValue","");
            }

            if(jobType=="0")//单次执行
            {
                $("#divTimeInterval").hide();
                //接口为档案上传时
                if($('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload) {
                    $("#divDelayTime").show();
                    $("#divRepeatStart").show();
                    $("#divRepeatEnd").show();
                    $("#txtDelayTime").val("");
                }
            }
            else{
                $("#divTimeInterval").show();
                //接口为档案上传时
                if( $('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload) {
                    $("#divDelayTime").show();
                    $("#repeatEndTime").ligerDateEditor("setValue","");
                    $("#divRepeatStart").show();
                    $("#divRepeatEnd").show();
                }
            }
        },
        //设置任务执行类型
        setJobContentType:function(jobContentType,jobContent){
            $("#lbJobContent").html("关联流程模板：")
            $("#txtJobContent").val("").hide();
            $("#jobContentClass").parent().parent().show();
            $("#jobContentClass").ligerComboBox("setValue",jobContent);
        },
        //设置数据集条件
        setCondition:function(rowIndex)
        {

            var me = this;
            //获取选中行
            var row = me.$listDataset.getRow(rowIndex);
            if(row == null)
            {
                return;
            }

            me.rowIndex = rowIndex;
            var schemeId = $("#txtSchemeId").val();
            var schemeVersion = $("#txtSchemeVersion").val();

            var condition="",key="",type = "",dataKey="",datasetId=row.jobDatasetId;
            if(row.jobDatasetKey!=undefined&&row.jobDatasetKey.length>0)
            {
                key = row.jobDatasetKey;
            }
            if(row.jobDatasetKeytype!=undefined&&row.jobDatasetKeytype.length>0)
            {
                type=row.jobDatasetKeytype;
            }
            if(row.jobDatasetCondition!=undefined&&row.jobDatasetCondition.length>0)
            {
                condition=row.jobDatasetCondition;
            }
            if(row.jobDatasetKeyvalue!=undefined&&row.jobDatasetKeyvalue.length>0){
                dataKey = row.jobDatasetKeyvalue;
            }

            $("#jobDatasetKey").ligerComboBox("setValue",key);
            $("#jobDatasetKeytype").ligerComboBox("setValue",type);
            $("#jobDatasetKeyvalue").val(dataKey);

            $.ajax({ //获取表的字段列表
                type: "POST",
                url : "${contextRoot}/datacollect/getSchemeDatasetCol",
                dataType : "json",
                data:{schemeId:schemeId,schemeVersion:schemeVersion,datasetId:datasetId},
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        //展示条件设置面板
                        $("#divCondition").show();
                        //设置下拉控件数据
                        $("#jobDatasetKey").ligerComboBox("setData",data.detailModelList);
                        //设置条件选择控件值
                        $("#jobDatasetCondition").ligerCondition("setFields",data.detailModelList);
                        $('#jobDatasetCondition').ligerCondition("setDictParms",{version:schemeVersion});
                        if(condition.length>0)
                        {
                            $("#jobDatasetCondition").ligerCondition("setValue",condition);
                        }
                    }
                    else{
                        $.ligerDialog.error(data.message);
                    }
                },
                error :function(data){
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                }
            });

        },
        //条件选择配置返回事件
        callbackCondition:function(key,type,dataKey,condition){
            var me= this;
            var rowIndex = me.rowIndex;
            me.$listDataset.updateRow(rowIndex,{
                jobDatasetKey:key,
                jobDatasetKeytype:type,
                jobDatasetKeyvalue:dataKey,
                jobDatasetCondition:condition
            });
            me.setCheckVal();
        },
        //表单校验
        verify:function(tabIndex)
        {
            var me = this;
            var data = me.getData();
            switch (tabIndex)
            {

                case 0:
                {
                    return true;
                }
                case 4:
                {
                    debugger
                    //任务类型不能为空
                    if(data.jobType == null)
                    {
                        $.ligerDialog.error("请选择任务类型！");
                        return false;
                    }

                    //下次执行时间不能为空
                    if(data.jobNextTime == null || data.jobNextTime == 0)
                    {
                        $.ligerDialog.error("请输入任务触发时间！");
                        return false;
                    }

                    if(data.jobType != "0") {
                        me.setInterval();
                        var interval = $("#txtCronExpression").val();
                        //执行周期不能为空
                        if (interval == "" || interval.length == 0) {
                            $.ligerDialog.error("请输入执行周期！");
                            return false;
                        }
                    }
                    else{
                        $("#txtCronExpression").val("");
                    }

                    //档案上传接口值校验
                    if($('input[name="jobContentType"]').ligerComboBox("getValue")==me.crawlerFlowUpload)
                    {
                        if(data.jobType == "1" && $("#repeatStartTime").ligerDateEditor("getValue")=="") {
                            $.ligerDialog.error("请输采集上传开始时间！");
                            return false;
                        }
                    }
                }
                case 1:
                {
                    //任务名称不能为空
                    if(data.jobName == null || data.jobName.length==0)
                    {
                        $.ligerDialog.error("请输入任务名称！");
                        return false;
                    }
                    if(data.jobContent == null || data.jobContent.length==0)
                    {
                        $.ligerDialog.error("请选择关联的流程！");
                        return false;
                    }
                    return true;

                }
                case 2:
                {
                    var schemeVersion = $("#txtSchemeId").val();
                    //适配方案不能为空
                    if(schemeVersion == null || schemeVersion.length==0)
                    {
                        $.ligerDialog.error("请选择适配方案！");
                        return false;
                    }
                    else
                        return true;
                }
                case 3:
                {
//                    if($('input[name="jobContentType"]').ligerComboBox("getValue")!=me.crawlerFlowUpload) {//不是任务编排上传类
                        var dataset = $("#txtJobDataset").val();
                        //数据集不能为空
                        if(dataset == null || dataset =="[]")
                        {
                            me.setCheckVal();
                            dataset = $("#txtJobDataset").val();
                            if(dataset == null || dataset =="[]") {
                                $.ligerDialog.error("请选择数据集！");
                                return false;
                            }

                        }
                        //判断是否设置轮询字段和字段类型   档案上传不校验 @modify by cyj
//                        if($('input[name="jobContentType"]').ligerComboBox("getValue")!=me.archiveCollect) {
                            var selected = me.$listDataset.getSelectedRows();
                            for(var i=0;i<selected.length;i++)
                            {
                                if(selected[i].jobDatasetKey!= undefined && selected[i].jobDatasetKey.length>0 && selected[i].jobDatasetKeytype!= undefined && selected[i].jobDatasetKeytype.length>0)
                                {

                                }
                                else{
                                    $.ligerDialog.error(selected[i].jobDatasetName+"未设置轮询字段！");
                                    return false;
                                }
                            }
//                        }
//                    }

                    return true;
                }
                default :
                    return true;
            }
        },
        //根据周期类型显示周期面板
        showInterval:function(tab){
            $('input[name="interval_type"]').ligerRadio("setValue", tab);
            $(".divIntervalOption").hide();
            $("#divIntervalOption"+tab).show();
        },
        //初始化时间间隔
        initInterval:function(){
            var me = this;
            var val= $("#txtCronExpression").val();
            if(val!=null&&val.length>0)
            {
                try {
                    //反解析cron表达式
                    var arry = val.split(' ');
                    if (arry[5] !="?") //周
                    {
                        $('input[name="interval_type"]').ligerRadio("setValue", "3");
                        me.showInterval(3);
                        $('input[name="week_day"]').ligerCheckBox("setValue", arry[5]);
                    }
                    else{
                        if (arry[3] !="*")
                        {
                            var v = arry[3];
                            if(v.indexOf('/')>0) //天
                            {
                                me.showInterval(2);
                                var varry = v.split('/');
                                $("#txtD").val(varry[1]);
                            }
                            else{//月
                                me.showInterval(4);
                                if(v=="1")
                                {
                                    $('input[name="month_day"]').ligerRadio("setValue", "0");
                                }
                                else if(v=="L"){
                                    $('input[name="month_day"]').ligerRadio("setValue", "1");
                                }
                                else{
                                    $('input[name="month_day"]').ligerRadio("setValue", "2");
                                    $("#txtMD").val(v);
                                }
                            }
                        }
                        else{
                            var v1 = arry[1];
                            var v2 = arry[2];
                            if(v1.indexOf('/')>0) //分
                            {
                                me.showInterval(0);
                                var varry = v1.split('/');
                                $("#txtM").val(varry[1]);
                            }
                            else{ //时
                                me.showInterval(1);
                                var varry = v2.split('/');
                                $("#txtH").val(varry[1]);
                            }
                        }
                    }

                }
                catch(e){
                    return;
                }
            }
            else{
//                //清空数据
//                $("#txtM").val("");
//                $("#txtH").val("");
//                $("#txtD").val("");
//                $("#txtMD").val("");
//                $('input[name="week_day"]').ligerCheckBox("setValue",null);
//                $('input[name="month_day"]').ligerRadio("setValue",null);
            }
        },
        //设置时间间隔
        setInterval:function(){
            var val = "";
            //解析cron表达式
            var interval_type =  $('input[name="interval_type"]').ligerRadio("getValue");
            var cronTime  = new Date($("#dateNextTime").ligerDateEditor('getValue'));
            var minute = cronTime.getMinutes(),hour = cronTime.getHours();

            if(interval_type =="0") //分钟
            {
                var num = $("#txtM").val();
                if(num!=null && num.length>0) {
                    val = "0 0/" + num + " * * * ?";
                }
            }
            else if(interval_type =="1"){ //时钟
                var num = $("#txtH").val();
                if(num!=null && num.length>0) {
                    val = "0 "+ minute +" 0/" + num + " * * ?";
                }
            }
            else if(interval_type =="2"){ //天
                var num = $("#txtD").val();
                if(num!=null && num.length>0) {
                    val = "0 "+ minute +" "+ hour +" 1/" + num + " * ?";
                }
            }
            else if(interval_type =="3"){ //周
                var week_day = $('input[name="week_day"]').ligerCheckBox("getValue");
                if(week_day!=null && week_day.length>0) {
                    val = "0 "+ minute +" "+ hour +" ? * " + week_day;
                }
            }
            else if(interval_type =="4"){ //月
                var month_day = $('input[name="month_day"]').ligerRadio("getValue");
                if(month_day == "0") //每月第一天
                {
                    val = "0 "+ minute +" "+ hour +" 1 * ?";
                }
                else if(month_day == "1") //每月最后一天
                {
                    val = "0 "+ minute +" "+ hour +" L * ?";
                }
                else{
                    var num = $("#txtMD").val();
                    if(num!=null && num.length>0)
                    {
                        val = "0 "+ minute +" "+ hour +" "+num+" * ?";
                    }
                }
            }

            $("#txtCronExpression").val(val);
        },
        //设置数据集选中值
        setCheckVal:function(){
            var me = this;
            var selected = me.$listDataset.getSelectedRows();
            if(selected!=null)
            {
                $("#txtJobDataset").val(JSON.stringify(selected));
            }
            else{
                $("#txtJobDataset").val("");
            }
        },
        //保存操作
        save:function(){
            var me = this;
            me.setCheckVal();
            var data = me.getData();
            console.log(data);
            //按钮失效
            $("a[href='#finish']").unbind("click");
            $.ajax({ //ajax处理
                type: "POST",
                url : me.actionUrl,
                dataType : "json",
                data:data,
                cache:false,
                success :function(data){
                    if(data.successFlg) {
                        if(parent.trackJob != undefined)
                            parent.trackJob.callbackDialog(data.message);
                        else
                            parent.configJob.callbackDialog(data.message);
                    }
                    else{
                        $.ligerDialog.error(data.message);
                        //按钮恢复
                        $("a[href='#finish']").bind("click",function(){editorJob.save();});
                    }
                },
                error :function(data){
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
                    //按钮恢复
                    $("a[href='#finish']").bind("click",function(){editorJob.save();});
                }
            });
        },
        //跳转步骤
        skip:function(to){
            var me = this;
            var index = me.$form.steps("getCurrentIndex");
            if(index>to)
            {
                for(var i =index-to;i>0;i--)
                {
                    if(!me.$form.steps("previous"))
                    {
                        return;
                    }
                }
            }
            else{
                for(var i =to-index;i>0;i--)
                {
                    if(!me.$form.steps("next"))
                    {
                        return;
                    }
                }
            }
        },

        compareServeTime:function(time){
            $.ajax({ //获取表的字段列表
                type: "POST",
                url : "${contextRoot}/datacollect/compareServeTime",
                dataType : "json",
                data:{time:time},
                cache:false,
                async:false,
                success :function(data){
                    if(data.successFlg) {
                        editorJob.beforeServeTime=true;
                        $.ligerDialog.error("采集时间不能小于当前时间！");

                    }
                    else{

                    }
                },
                error :function(data){
                    editorJob.beforeServeTime=true;
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");

                }
            });

        },
        getFlowList:function(){
            $.ajax({ //获取表的字段列表
                type: "POST",
                url : "${contextRoot}/flow/flowTempList",
                dataType : "json",
                data:{type:'java'},
                cache:false,
                async:false,
                success :function(data){
                    if(data.successFlg) {
                        editorJob.flowArrays=data.data;
                    }
                    else{
                        alert("获取流程列表错误");
                    }
                },
                error :function(data){
                    editorJob.beforeServeTime=true;
                    $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");

                }
            });

        },
    }

    //轮回最大值只能输入正整数
    $("#jobDatasetKeyvalue").on("keyup afterpaste",function(){
        if(this.value.length==1){
            this.value=this.value.replace(/[^1-9]/g,'')
        }else{
            this.value=this.value.replace(/\D/g,'')
        }
    })

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

