var examine = {};
var locked = false;

examine.save = function (submit) {
    var id = $("#id").val();
    var checkState = $("#checkState").val();
    var checkMsg = $("#checkMsg").val();
    if (checkState == null || checkState == '') {
        Feng.info("请选择审核状态!");
        return;
    }
    if (checkMsg == null || checkMsg == '') {
        Feng.info("请填写审核意见!");
        return;
    }
    if (checkState == 3 && $("#field input[type=checkbox]:checked").length == 0) {
        Feng.info("请选择驳回修改的字段或者附件");
        return;
    }
    var fieldCount = $("#field_info input[type=checkbox]:checked").length;
    var fields = new Array();
    for (var i = 0; i < fieldCount; i++) {
        fields.push($("#field_info input[type=checkbox]:checked").eq(i).val());
    }
    var fileCount = $("#field_file input[type=checkbox]:checked").length;
    var files = new Array();
    for (var i = 0; i < fileCount; i++) {
        files.push($("#field_file input[type=checkbox]:checked").eq(i).val());
    }
    var da = {"id": id, "checkState": checkState, "checkMsg": checkMsg, fields: fields, files: files, submit: submit};
    if (locked)
        return;
    locked = true;
    var ajax = new $ax(Feng.ctxPath + "/admin/enterpriseChangeRecord/doExamine", function (data) {
        if (data.code == 200) {
            if (submit) {
                window.parent.parent.EpChange.table.refresh();
                parent.layer.closeAll();
            }
        }
        Feng.info(data.msg);
        locked = false;
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
        locked = false;
    });
    ajax.set(da);
    ajax.start();
}
examine.addSubmit = function () {
    examine.save(0);
};

examine.submitToCheck = function () {
    examine.save(1);
};

examine.checkAll = function () {
    $("#field input[type=checkbox]").prop("checked", true);
}
examine.unCheckAll = function () {
    $("#field input[type=checkbox]").removeAttr("checked");
}

examine.toggleField = function () {
    var checkState = $("#checkState").val();
    var checkMsg = $("#checkMsg").val();
    if (checkState == 4) {
        $("#field").css("display", "none");
        if (checkMsg == null || checkMsg == '') {
            $("#checkMsg").val("机构信息变更审核通过。");
        }
    } else if (checkState == 3) {
        $("#checkMsg").val("");
        $("#field").css("display", "block");
    } else {
        $("#field").css("display", "none");
    }
}
