/**
 * 初始化学杂费补助详情对话框
 */
var ChildschoolFeesInfoDlg = {
    childschoolFeesInfoData : {}
};


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

/**
 *
 */
ChildschoolFeesInfoDlg.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="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' +
        '                        <textarea class="form-control" id="checkMsg"  rows="6"></textarea>\n' +
        '                    </div>\n' +
        '                </form>';
}

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

/**
 * 审核
 * @param index
 */
ChildschoolFeesInfoDlg.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 + "/childschoolFees/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});
    ajax.start();
}


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

/**
 * 回显社保及个税
 */
ChildschoolFeesInfoDlg.checkSbAndTax = function(){
    var pensionDetail = $("#pensionDetail").attr("data-month");
    var unemploymentDetail = $("#unemploymentDetail").attr("value");
    var medicaDetail = $("#medicaDetail").attr("value");
    var taxDetail = $("#taxDetail").attr("value");
    $("#pensionDetail input").each(function () {
        $(this).attr("style","pointer-events: none;background-color: #eee;");
        if(pensionDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#unemploymentDetail input").each(function () {
        $(this).attr("style","pointer-events: none;background-color: #eee;");
        if(unemploymentDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#medicaDetail input").each(function () {
        $(this).attr("style","pointer-events: none;background-color: #eee;");
        if(medicaDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#taxDetail input").each(function () {
        $(this).attr("style","pointer-events: none;background-color: #eee;");
        if(taxDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
}

$(function() {
    var arr = [{"name":"talentArrange","code":"un_talentLevel"},
        {"name":"cRelation","code":"un_education_relation"},
        {"name":"nowGrade","code":"un_grade"},
        {"name":"pCardType","code":"un_cardType"},
        {"name":"cCardType","code":"un_cardType"}];
    Feng.findChildDictBatch(JSON.stringify(arr))
    $("select").each(function () {
        $(this).val($(this).attr("value")).trigger("change");
    });
    var id = $("#id").val();
    Feng.getCheckLog("logTable",{"type":CONFIG.project_schoolFees,"mainId":id,"typeFileId":"","active":1})
    ChildschoolFeesInfoDlg.checkSbAndTax();
    Feng.showMiniFileModal(CONFIG.project_schoolFees,$("#type").val(),$("#id").val());
});
