/**
 * 初始化购房补助详情对话框
 */
var HouseRentingPurchaseFeesInfoDlg = {
    houseRentingPurchaseFeesInfoData : {}
};


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


/**
 *
 */
HouseRentingPurchaseFeesInfoDlg.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>';
}

/**
 * 显示审核模态框
 */
HouseRentingPurchaseFeesInfoDlg.showCheckModal = function(){
    var ajax = new $ax(Feng.ctxPath + "/houseRentingPurchaseFees/validateIsCheck", function (data) {
        if(data.code==200){
            layer.open({
                type: 1,
                id:"neewFieldFormModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade:0,
                maxmin: true,
                content: HouseRentingPurchaseFeesInfoDlg.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) {
                    HouseRentingPurchaseFeesInfoDlg.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
 */
HouseRentingPurchaseFeesInfoDlg.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 + "/houseRentingPurchaseFees/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();
}

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

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