/**
 * 医共体
 */
var MedicalCommunityInfo = {
    infoData: {},
    validateFields: {
        name: {
            validators: {
                notEmpty: {
                    message: '医共体名称不能为空'
                }
            }
        },
        status: {
            validators: {
                notEmpty: {
                    message: '启用状态不能为空'
                }
            }
        },
        num: {
            validators: {
                notEmpty: {
                    message: '排序不能为空'
                },
                regexp: {
                    regexp: /^\d+$/,
                    message: '只能输入数字'
                }
            }
        }
    }
};

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

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

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

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

/**
 * 收集数据
 */
MedicalCommunityInfo.collectData = function () {
    this.set('id')
            .set('name')
            .set('status')
            .set('num')
            .set('description');
}

/**
 * 验证数据是否为空
 */
MedicalCommunityInfo.validate = function () {
    $('#medicalCommunityInfoForm').data("bootstrapValidator").resetForm();
    $('#medicalCommunityInfoForm').bootstrapValidator('validate');
    return $("#medicalCommunityInfoForm").data('bootstrapValidator').isValid();
}

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

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

$(function () {
    //下拉框数据回显
    $("select").each(function () {
        $(this).val($(this).attr("selectVal"));
    });
    Feng.initValidator("medicalCommunityInfoForm", MedicalCommunityInfo.validateFields);
});
