/**
 * 初始化子女就学详情对话框
 */
var EducationSchoolInfoDlg = {
    educationSchoolInfoData: {},
};

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

/**
 * 项目选择变更
 * @param content
 */
EducationSchoolInfoDlg.projectChange = function (content) {
    var project = $(content).val();
    if (Feng.isEmptyStr(project)) {
        $("#applySchool").parent().css("display", "none");
    }
    if (project == CONFIG.education_school) {
        $("#applySchool").parent().css("display", "block");
    }
    if (project == CONFIG.education_score) {
        $("#applySchool").parent().css("display", "none");
    }
}

/**
 * 显示审核
 */
EducationSchoolInfoDlg.showCheckModal = function () {
    var ajax = new $ax(Feng.ctxPath + "/admin/education_school/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "neewFieldFormModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content: EducationSchoolInfoDlg.creatFieldCheckModal(),
                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) {
                    EducationSchoolInfoDlg.check(index);
                }
            });
        } else {
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.setData({"id": $("#id").val()})
    ajax.start();
}

/**
 * 审核
 * @param index
 */
EducationSchoolInfoDlg.check = function (index) {
    var checkState = $("#checkStateModel").val();
    var checkMsg = $("#checkMsg").val();
    if (checkState == null || checkState == '') {
        Feng.info("请选择审核状态");
        return;
    }
    if (checkMsg == null || checkMsg == '') {
        Feng.info("请填写审核意见");
        return;
    }
    var ajax = new $ax(Feng.ctxPath + "/admin/education_school/check", function (data) {
        if (data.code == 200) {
            layer.close(index);
            Feng.success(data.msg);
        } else {
            Feng.error(data.msg);
        }
        locked = false;
    }, function (data) {
        Feng.error("审核失败!" + data.responseJSON.message + "!");
        locked = false;
    });
    ajax.setData({"id": $("#id").val(), "checkState": checkState, "checkMsg": checkMsg});
    ajax.start();
}


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

/**
 *
 */
EducationSchoolInfoDlg.creatFieldCheckModal = 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="3">审核通过</option>\n' +
            '                            <option value="2">审核驳回</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>';
}

$(function () {
    Feng.initValidatorTip("educationSchoolForm", EducationSchoolInfoDlg.validateFields);
    //批量加载字典表数据
    var arr = [
        {"name": "companyStreet", "code": "street"},
        {"name": "houseStreet", "code": "street"},
        {"name": "talentArrange", "code": "talent_arrange"},
        {"name": "cRelation", "code": "education_relation"},
        {"name": "nowGrade", "code": "education_grade"},
        {"name": "project", "code": "education_project"},
        {"name": "applySchool", "code": "education_school_pool"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    $("#applySchool").on('chosen:ready', function (e, params) {
        $(".chosen-container-single .chosen-single").css("padding", "4px 0px 0px 4px");
    });
    $("#applySchool").chosen({
        search_contains: true,       //关键字模糊搜索。设置为true，只要选项包含搜索词就会显示；设置为false，则要求从选项开头开始匹配
        disable_search: false,
        width: "100%",
        enable_split_word_search: true
    });
    $("select").each(function () {
        $(this).val($(this).attr("value")).trigger("change").trigger("chosen:updated");
    });
    var id = $("#id").val();
    Feng.getCheckLog("logTable", {"type": CONFIG.project_school, "mainId": id, "typeFileId": "", "active": 1})
    Feng.showMiniFileModal(CONFIG.project_school, $("#type").val(), $("#id").val());
});
