/**
 * 初始化租房申请详情对话框
 */
var HouseRentingInfoDlg = {
    houseRentingInfoData : {}
};

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


HouseRentingInfoDlg.checkSbAndTax = function(){
    var pensionDetail = $("#pensionDetail").attr("value");
    var unemploymentDetail = $("#unemploymentDetail").attr("value");
    var medicaDetail = $("#medicaDetail").attr("value");
    var taxDetail = $("#taxDetail").attr("value");
    $("#pensionDetail input").each(function () {
        if(pensionDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#unemploymentDetail input").each(function () {
        if(unemploymentDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#medicaDetail input").each(function () {
        if(medicaDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
    $("#taxDetail input").each(function () {
        if(taxDetail.indexOf($(this).val())!= -1){
            $(this).attr("checked", true);
        }
    })
}


/**
 * 显示初审审核模态框
 */
HouseRentingInfoDlg.showCheckModal = function(process){
    var ajax = new $ax(Feng.ctxPath + "/houseRenting/validateIsCheck", function (data) {
        if(data.code==200){
            layer.open({
                type: 1,
                id:"checkModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade:0,
                maxmin: true,
                content:HouseRentingInfoDlg.createCheckHtml(process),
                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);
                    var obj = data.obj.obj;
                    $("#checkForm")[0].reset();
                    $("#checkStateModal").val(obj.checkState).trigger("change");
                    $("#checkMsg").val(obj.checkMsg);
                },
                yes: function (index, layero) {
                    var checkState = $("#checkStateModal").val();
                    var checkMsg = $("#checkMsg").val();
                    if(process != 2 && (checkState==null||checkState=='')){
                        Feng.info("请选择审核状态");
                        return ;
                    }
                    if(checkMsg == null || checkMsg == ''){
                        Feng.info("请填写审核意见");
                        return ;
                    }
                    var ajax = new $ax(Feng.ctxPath + "/houseRenting/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, "process":process,"companyId":$("#companyId").val()})
                    ajax.start();
                }
            });
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.setData({"id":$("#id").val(),"process":process,"companyId":$("#companyId").val()})
    ajax.start();
}

HouseRentingInfoDlg.createCheckHtml = function(process){
    return process == 2?
        '<form id="checkForm">\n' +
            '<div class="form-group" style="margin: 10px;">\n' +
            '<label for="checkMsg" class="control-label" >核查结果</label>\n' +
            '<textarea class="form-control" id="checkMsg" placeholder="" rows="10"></textarea>\n' +
            '</div>\n' +
        '</form>'
          :
        '<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="checkStateModal" >\n' +
                    '<option value="">请选择</option>\n' +
                    '<option value="3">审核通过</option>\n' +
                    '<option value="2">审核驳回</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" placeholder="" rows="6"></textarea>\n' +
            '</div>\n' +
        '</form>';
}

/**
 * 提交审核
 */
HouseRentingInfoDlg.submitToCheck = function(process){
    var operation = function(){
        var ajax = new $ax(Feng.ctxPath + "/houseRenting/submitCheck", function (data) {
            if(data.code==200){
                Feng.success(data.msg);
                window.parent.HouseRenting.table.refresh();
                HouseRentingInfoDlg.close();
            }else{
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("提交审核失败!" + data.responseJSON.message + "!");
        });
        ajax.setData({"id":$("#id").val(),"process":process,"companyId":$("#companyId").val()});
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
}



$(function() {
    $("select").each(function () {$(this).val($(this).attr("value")).trigger("change");});
    HouseRentingInfoDlg.checkSbAndTax();
    Feng.getCheckLog("logTable",{"type":CONFIG.project_renting,"mainId":$("#id").val(),"typeFileId":"","active":1})
    Feng.showMiniFileModal(CONFIG.project_renting,$("#type").val(),$("#id").val());
});
