/**
 * 初始化commonFileType详情对话框
 */
var UnCommonFiletypeInfoDlg = {
    unCommonFiletypeInfoData: {},
    validateFields: {
        type: {
            validators: {
                notEmpty: {
                    message: '人才类别不能为空'
                }
            }
        },
        project: {
            validators: {
                notEmpty: {
                    message: '申报项目不能为空'
                }
            }
        },
        name: {
            validators: {
                notEmpty: {
                    message: '附件类型名称不能为空'
                }
            }
        },
        must: {
            validators: {
                notEmpty: {
                    message: '是否必传不能为空'
                }
            }
        },
        active: {
            validators: {
                notEmpty: {
                    message: '是否生效不能为空'
                }
            }
        },
        sn: {
            validators: {
                notEmpty: {
                    message: '排序不能为空'
                }
            }
        },
    }
};

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

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
UnCommonFiletypeInfoDlg.set = function (key, val) {
    this.unCommonFiletypeInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
UnCommonFiletypeInfoDlg.get = function (key) {
    return $("#" + key).val();
}

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

/**
 * 收集数据
 */
UnCommonFiletypeInfoDlg.collectData = function () {
    this
            .set('id')
            .set('type')
            .set('source')
            .set('project')
            .set('name')
            .set('api')
            .set('must')
            .set('active')
            .set('checkCompany')
            .set('sn')
            .set('description')
            .set('createUser')
            .set('createTime')
            .set('updateUser')
            .set('updateTime');
}

/**
 * 提交添加
 */
UnCommonFiletypeInfoDlg.addSubmit = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    $('#unCommonFiletypeForm')[0].submit();
}

/**
 * 提交修改
 */
UnCommonFiletypeInfoDlg.editSubmit = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    $('#unCommonFiletypeForm')[0].submit();
}

/**
 * 验证数据
 */
UnCommonFiletypeInfoDlg.validate = function () {
    $('#unCommonFiletypeForm').data("bootstrapValidator").resetForm();
    $('#unCommonFiletypeForm').bootstrapValidator('validate');

    return $("#unCommonFiletypeForm").data('bootstrapValidator').isValid();
}

//回调
UnCommonFiletypeInfoDlg.callBack = function (data) {
    Feng.success(data.msg);
    if (data.code == "200") {
        window.parent.UnCommonFiletype.table.refresh();
        UnCommonFiletypeInfoDlg.close();
    }
}

UnCommonFiletypeInfoDlg.typeChange = function () {
    UnCommonFiletypeInfoDlg.typeAndProjectChange();
}

UnCommonFiletypeInfoDlg.projectChange = function () {
    var project = $("#project").val();
    if(project == 1){
        $(".project1").css("display","");
    }else{
        $(".project1").css("display","none");
    }
    UnCommonFiletypeInfoDlg.typeAndProjectChange();
}

UnCommonFiletypeInfoDlg.typeAndProjectChange = function () {
    var type = $("#type").val();
    var project = $("#project").val();
    if (type == 1 && project == 1) {
        var options = '<option value="">---请选择---</option><option value="1">一、基础资料填报阶段</option><option value="2">二、补充认定材料阶段</option>';
    } else {
        var options = '<option value="">---请选择---</option>';
    }
    $("#step").html(options);
    var step = $("#step").attr("selectVal");
    $("#step").val(step);
}

UnCommonFiletypeInfoDlg.fileChange = function (context) {
    var file = $(context).val();
    var pos = file.lastIndexOf("\\");
    $("#templateUrl").val(file.substring(pos + 1));
}


$(function () {
    Feng.initValidator("unCommonFiletypeForm", UnCommonFiletypeInfoDlg.validateFields);
    $("select").each(function () {
        $(this).val($(this).attr("selectVal"));
    });
    UnCommonFiletypeInfoDlg.projectChange();
});



