/**
 * 初始化培训补贴详情对话框
 */
var TrainingSubsidyInfoDlg = {
    trainingSubsidyInfoData : {}
};

/**
 * 清除数据
 */
TrainingSubsidyInfoDlg.clearData = function() {
    this.trainingSubsidyInfoData = {};
}

/**
 * 关闭此对话框
 */
TrainingSubsidyInfoDlg.close = function() {
    parent.layer.close(window.parent.TrainingSubsidy.layerIndex);
}

/**
 * 显示审核
 */
TrainingSubsidyInfoDlg.showCheckModal = function(type){
    var ajax = new $ax(Feng.ctxPath + "/trainingSubsidy/validateIsCheck", function (data) {
        if(data.code==200){
            layer.open({
                type: 1,
                id:"neewFieldFormModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade:0,
                maxmin: true,
                content: TrainingSubsidyInfoDlg.createCheckModal(),
                btn: ['<i class="fa fa-save"></i>&nbsp;&nbsp;提交' ,'<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
                btnAlign: 'c',
                zIndex: layer.zIndex,
                success:function(layero, index){
                    layer.setTop(layero);
                    $("#checkStateModel").val(data.obj.checkState);
                    $("#checkMsg").val(data.obj.checkMsg);
                },
                yes: function (index, layero) {
                    var checkState = $("#checkStateModel").val();
                    var checkMsg = $("#checkMsg").val();
                    var enjoyYear = $("#enjoyYear").val();
                    if(Feng.isEmptyStr(checkState)){
                        Feng.info("请选择审核状态");
                        return ;
                    }
                    if(checkState == 5 && Feng.isEmptyStr(enjoyYear)){
                        Feng.info("请填写享受第几年度");
                        return ;
                    }
                    if(Feng.isEmptyStr(checkMsg)){
                        Feng.info("请填写审核意见");
                        return ;
                    }
                    var ajax = new $ax(Feng.ctxPath + "/trainingSubsidy/check", function (data) {
                        if(data.code==200){
                            layer.close(index);
                            Feng.success(data.msg);
                        }else{
                            Feng.error(data.msg);
                        }
                    }, function (data) {
                        Feng.error("审核失败!" + data.responseJSON.message + "!");
                    });
                    ajax.setData({"id":$("#id").val(),"checkState":checkState,"checkMsg":checkMsg,"enjoyYear":enjoyYear,"process":type});
                    ajax.start();
                }
            });
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.set("id",$("#id").val());
    ajax.set("type",type)
    ajax.start();
}


TrainingSubsidyInfoDlg.createCheckModal = function(){
    return '<form id="checkForm">\n' +
        '                    <div class="form-group" style="margin: 10px;">\n' +
        '                        <label for="checkState" class="control-label">审核状态</label>\n' +
        '                        <select class="form-control" id="checkStateModel" >\n' +
        '                            <option value="">请选择</option>\n' +
        '                            <option value="5">审核通过</option>\n' +
        '                            <option value="4">审核驳回</option>\n' +
        '                            <option value="-1">审核不通过</option>\n' +
        '                        </select>\n' +
        '                    </div>\n' +
        '                    <div class="form-group" style="margin: 10px;">\n' +
        '                        <label for="checkMsg" class="control-label" >享受第几年度</label>\n' +
        '                        <select class="form-control" id="enjoyYear" >\n' +
        '                            <option value="">请选择</option>\n' +
        '                            <option value="1">1</option>\n' +
        '                            <option value="2">2</option>\n' +
        '                            <option value="3">3</option>\n' +
        '                            <option value="4">4</option>\n' +
        '                            <option value="5">5</option>\n' +
        '                        </select>\n' +
        '                    </div>\n' +
        '                    <div class="form-group" style="margin: 10px;">\n' +
        '                        <label for="checkMsg" class="control-label" >审核意见</label>\n' +
        '                        <textarea class="form-control" id="checkMsg"  rows="6"></textarea>\n' +
        '                    </div>\n' +
        '                </form>';
}


/**
 * 提交审核
 */
TrainingSubsidyInfoDlg.submitToCheck = function(type){
    var checkState = $("#checkState").val();
    // if(checkState != 2 && checkState != 3){
    //     Feng.info("不在审核范围内");
    //     return ;
    // }
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/trainingSubsidy/submitCheck", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                window.parent.TrainingSubsidy.table.refresh();
                TrainingSubsidyInfoDlg.close();
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("提交审核失败!" + data.responseJSON.message + "!");
        });
        ajax.setData({"id":$("#id").val(),"process":type});
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
}


$(function() {
    var arr = [{"name":"nationality","code":"un_nationality"},
        {"name":"cardType","code":"un_cardType"}];
    Feng.findChildDictBatch(JSON.stringify(arr))
    $("select").each(function () {
        $(this).val($(this).attr("value")).trigger("change");
    });
    Feng.getCheckLog("logTable",{"type":CONFIG.project_training,"mainId":$("#id").val(),"typeFileId":"","active":1})
    Feng.showMiniFileModal(CONFIG.project_training,$("#type").val(),$("#id").val());
    $("#trainingInfoForm input,select").attr("style","pointer-events: none;background-color: #eee;");
});
