/**
 * 初始化购房补贴详情对话框
 */
var HousepurchaseInfoDlg = {
    housepurchaseInfoData: {}
};
var locked = false;
/**
 * 关闭此对话框
 */
HousepurchaseInfoDlg.close = function () {
    parent.layer.close(window.parent.Housepurchase.layerIndex);
}

/**
 * 显示初审审核模态框
 */
HousepurchaseInfoDlg.showFirstCheckModal = function () {
    var process = $("#process").val();
    var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "checkModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content: HousepurchaseInfoDlg.createFirstCheckHtml(data.obj.number),
                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;
                    var fileList = data.obj.fileTypeList;
                    var html = '';
                    for (var key in fileList) {
                        html = html + '<ul><li style="width: 100%"><input type="checkbox" value="' + fileList[key].id + '"><span>' + fileList[key].name + '</span></li></ul>';
                    }
                    $("#field_file").empty().append(html);
                    $("#checkForm")[0].reset();
                    $("#checkStateFirstModal").val(obj.checkState).trigger("change");
                    $("#checkMsgFirst").val(obj.checkMsg);
                    if (Feng.isNotEmptyStr(obj.fields)) {
                        $("#field_info input").each(function () {
                            var arr = obj.fields.split(",");
                            for (var key in arr) {
                                if ($(this).val() == arr[key]) this.checked = true;
                            }
                        });
                    }
                    if (Feng.isNotEmptyStr(obj.files)) {
                        $("#field_file input").each(function () {
                            if (obj.files.indexOf($(this).val()) != -1) this.checked = true;
                        });
                    }
                },
                yes: function (index, layero) {
                    var checkState = $("#checkStateFirstModal").val();
                    var checkMsg = $("#checkMsgFirst").val();
                    if (checkState == null || checkState == '') {
                        Feng.info("请选择审核状态");
                        return;
                    }
                    if (checkMsg == null || checkMsg == '') {
                        Feng.info("请填写审核意见");
                        return;
                    }
                    var fields = '', files = '';
                    $("#field_info li input").each(function (index) {
                        if ($(this).is(":checked")) {
                            fields = fields + $(this).val() + ",";
                        }
                    });
                    $("#field_file li input").each(function (index) {
                        if ($(this).is(":checked")) {
                            files = files + $(this).val() + ",";
                        }
                    });
                    if (checkState == 2 && fields == '' && files == '') {
                        Feng.info("请选择可修改的字段或附件！");
                        return;
                    }
                    if (locked) return;
                    locked = true;
                    var ajax = new $ax(Feng.ctxPath + "/housepurchase/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,
                        "process": $("#process").val(), "fields": fields, "files": files
                    })
                    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();
}

/**
 * 显示各单位审核页面
 */
HousepurchaseInfoDlg.showDepCheckModal = function () {
    var process = $("#process").val();
    var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
        if (data.code == 200) {
            var company = data.obj.company;
            var obj = data.obj.obj;
            layer.open({
                type: 1,
                id: "checkModel",
                title: company.name + '核查结果录入',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content:
                    "<form id=\"depForm\" class=\"form-horizontal\">\n" +
                    '<div class="form-group" style="margin: 10px;">\n' +
                    '<label for="checkMsg" class="control-label" >核查结果备注</label>\n' +
                    '<textarea class="form-control" id="hcMsg" placeholder="" rows="6"></textarea>\n' +
                    "</div>\n" +
                    "</form>",
                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);
                    if (company.code = CONFIG.COM_ZJJ) $("#hcMsg").val(obj.zjjCheckDetail);
                    if (company.code = CONFIG.COM_ZRZYJ) $("#hcMsg").val(obj.zrzzjCheckDetail);
                    if (company.code = CONFIG.COM_MZJ) $("#hcMsg").val(obj.mzjCheckDetail);
                },
                yes: function (index, layero) {
                    var msg = $("#hcMsg").val();
                    if (Feng.isEmptyStr(msg)) {
                        Feng.info("请填写核查结果!");
                        return;
                    }
                    var ajax = new $ax(Feng.ctxPath + "/housepurchase/depCheck", 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(), "description": msg, "companyId": company.id})
                    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();
}

/**
 * 显示复核审核页面
 */
HousepurchaseInfoDlg.showThirdCheckModal = function () {
    var process = $("#process").val();
    var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "checkModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content: HousepurchaseInfoDlg.createThirdCheckHtml(),
                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);
                    $('#toDep').chosen({width: '100%',placeholder_text_multiple: '请选择兑现对象'});
                    $("#checkStateFirstModal").val(data.obj.obj.checkState);
                    $("#checkMsgFirst").val(data.obj.obj.checkMsg);
                    $("#toProcess").val(data.obj.obj.toProcess);
                    $("#cashType").val(data.obj.obj.cashType).trigger("change");
                    if (Feng.isNotEmptyStr(data.obj.obj.toDep)) {
                        $("#toDep").val(data.obj.obj.toDep.split(",")).trigger("chosen:updated");
                    }

                },
                yes: function (index, layero) {
                    var checkState = $("#checkStateFirstModal").val();
                    var checkMsg = $("#checkMsgFirst").val();
                    var toProcess = $("#toProcess").val();
                    var toDep = $("#toDep").val();
                    var cashType = $("#cashType").val();
                    if (checkState == null || checkState == '') {
                        Feng.info("请选择审核状态");
                        return;
                    }
                    if (checkMsg == null || checkMsg == '') {
                        Feng.info("请填写审核意见");
                        return;
                    }
                    if (checkState == 2) {
                        if (Feng.isEmptyStr(toProcess)) {
                            Feng.info("请选择驳回至流程");
                            return;
                        }
                        if (toProcess == 2 && Feng.isEmptyStr(toDep)) {
                            Feng.info("请选择驳回单位");
                            return;
                        }
                    }
                    if (checkState == 3 && Feng.isEmptyStr(cashType)) {
                        Feng.info("请选择兑现状态");
                        return;
                    }
                    var companyCodes = "", cashObjs = "";
                    for (var key in toDep) {
                        if (Feng.isNotEmptyStr(top[key])) {
                            companyCodes = companyCodes + toDep[key] + ",";
                        }
                    }
                    companyCodes = companyCodes.substring(0, companyCodes.length - 1);
                    cashObjs = cashObjs.substring(0, cashObjs.length - 1);
                    var ajax = new $ax(Feng.ctxPath + "/housepurchase/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,
                        "cashType": cashType,
                        "process": $("#process").val(),
                        "companyId": $("#companyId").val(),
                        "toProcess": $("#toProcess").val(),
                        "toDep": companyCodes
                    });
                    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();
}

/**
 * 公示再审核保存数据
 */
HousepurchaseInfoDlg.saveDepDataAtAfter = function () {


}

/**
 *  公示再审核提交
 */
HousepurchaseInfoDlg.showAfterCheckModal = function () {
    var process = $("#process").val();
    var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
        if (data.code == 200) {
            layer.open({
                type: 1,
                id: "checkModel",
                title: '审核',
                area: ['800px', '450px'], //宽高
                fix: false, //不固定
                shade: 0,
                maxmin: true,
                content: HousepurchaseInfoDlg.createAfterCheckHtml(),
                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 housepurchase = data.obj.housepurchase;
                    $("#decideMoneyDetail").val(housepurchase.decideMoneyDetail);
                    $("#realEnjoyMoney").val(housepurchase.realEnjoyMoney);
                },
                yes: function (index, layero) {
                    var declareType = $("#declareType").val();
                    var checkState = $("#checkStateFirstModal").val();
                    var checkMsg = $("#checkMsgFirst").val();
                    var cashType = $("#cashType").val();
                    var decideMoneyDetail = $("#decideMoneyDetail").val();
                    var shouldEnjoyMoney = $("#shouldEnjoyMoney").val();
                    if (checkState == null || checkState == '') {
                        Feng.info("请选择审核状态");
                        return;
                    }
                    if (checkMsg == null || checkMsg == '') {
                        Feng.info("请填写审核意见");
                        return;
                    }
                    if (checkState == 3) {
                        if (Feng.isEmptyStr(cashType)) {
                            Feng.info("请选择兑现状态");
                            return;
                        }
                        if (cashType == 1) {
                            if (declareType == 1 && Feng.isEmptyStr(shouldEnjoyMoney)) {
                                Feng.info("请填写应享受金额");
                                return;
                            }
                        }
                    }
                    var cashObjs = "";
                    cashObjs = cashObjs.substring(0, cashObjs.length - 1);
                    var operation = function () {
                        var ajax = new $ax(Feng.ctxPath + "/housepurchase/afterCheck", function (data) {
                            if (data.code == 200) {
                                Feng.success(data.msg);
                                layer.close(index);
                                HousepurchaseInfoDlg.close();
                                window.parent.Housepurchase.table.refresh();
                            } else {
                                Feng.error(data.msg);
                            }
                        }, function (data) {
                            Feng.error("审核失败!" + data.responseJSON.message + "!");
                        });
                        ajax.setData({
                            "id": $("#id").val(),
                            "checkState": checkState,
                            "checkMsg": checkMsg,
                            "cashType": cashType,
                            "decideMoneyDetail": decideMoneyDetail,
                            "shouldEnjoyMoney": shouldEnjoyMoney
                        });
                        ajax.start();
                    }
                    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
                }
            });
        } else {
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("校验失败!" + data.responseJSON.message + "!");
    });
    ajax.setData({"id": $("#id").val(), "process": process, "companyId": $("#companyId").val()})
    ajax.start();
}

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

HousepurchaseInfoDlg.createFirstCheckHtml = function () {
    var declareType = $("#declareType").val();
    var field =
        // '<li style="width:10%"><input type="checkbox" value="phone"/><span>手机号码</span></li>\n' +
        '<li style="width:10%"><input type="checkbox" value="marryStatus"/><span>婚姻状态</span></li>\n' +
        '<li style="width:10%"><input type="checkbox" value="spouseName"/><span>配偶姓名</span></li>\n' +
        '<li style="width:20.5%"><input type="checkbox" value="spouseCardType"/><span>配偶证件类型</span></li>\n' +
        '<li style="width:20.5%"><input type="checkbox" value="spouseIdcard"/><span>配偶证件号码</span></li>\n'+
        '<li style="width:20.5%"><input type="checkbox" value="spouseIsLibrary"/><span>配偶是否在库人才</span></li>\n';
    if (declareType == 1) {
        field = field +
            '<li style="width:20.5%"><input type="checkbox" value="realEstateNo"/><span>不动产权证编号</span></li>\n' +
            '<li style="width:20.5%"><input type="checkbox" value="recordNo"/><span>备案合同编号</span></li>\n' +
            '<li style="width:20.5%"><input type="checkbox" value="houseAddress"/><span>房屋坐落地址</span></li>\n' +
            '<li style="width:20.5%"><input type="checkbox" value="houseArea"/><span>房屋建筑面积</span></li>\n' +
            '<li style="width:63%"><input type="checkbox" value="recordTime"/><span>商品房购房合同备案时间/不动产权证书办理时间</span></li>\n' +
            '<li style="width:20.5%"><input type="checkbox" value="houseMoney"/><span>房屋成交金额</span></li>\n' +
            '<li style="width:20.5%"><input type="checkbox" value="isEnjoyOther"/><span>是否享受我市其他政策</span></li>\n';
    }
    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="checkStateFirstModal" onchange="HousepurchaseInfoDlg.toggleField()">\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="checkMsgFirst" placeholder="" rows="6"></textarea>\n' +
        '                        <div id="field" style="padding-top: 5px;display: none">\n' +
        '                            <label for="checkMsg" class="control-label">可修改字段</label>\n' +
        '                            <div id="field_info">\n' +
        '                                <ul>\n' +
        field +
        '                                </ul>\n' +
        '                            </div>\n' +
        '                            <label for="checkMsg" class="control-label">可修改附件</label>\n' +
        '                            <div id="field_file">\n' +
        '                            </div>\n' +
        '                            <div class="form-group" style="text-align: center">\n' +
        '                                <button type="button" class="btn btn-primary" onclick="Feng.checkAll(\'field\')">全选</button>\n' +
        '                                <button type="button" class="btn btn-success" onclick="Feng.unCheckAll(\'field\')">反选</button>\n' +
        '                            </div>\n' +
        '                        </div>\n' +
        '                    </div>\n' +
        '                </form>';
}

/**
 * 公示在审核
 */
HousepurchaseInfoDlg.createAfterCheckHtml = function () {
    var idCard = $("#idCard").val();
    var name = $("#name").val();
    var spouseName = $("#spouseName").val();
    var spouseIdcard = $("#spouseIdcard").val();
    var options = "<option value='" + idCard + "'>" + name + "</option>";
    if (Feng.isNotEmptyStr(spouseIdcard)) {
        options = options + "<option value='" + spouseIdcard + "'>" + spouseName + "</option>";
    }
    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="checkStateFirstModal" onchange="HousepurchaseInfoDlg.afterToggleField(this)">\n' +
        '<option value="">请选择</option>\n' +
        '<option value="3">审核通过</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="checkMsgFirst" placeholder="" rows="4"></textarea>\n' +
        '</div>\n' +
        '<div class="form-group" style="margin: 10px;" >\n' +
        '<label for="processLable" class=" control-label">兑现状态</label>\n' +
        '<select class="form-control" id="cashType" onchange="HousepurchaseInfoDlg.afterCashTypeChange()">\n' +
        '<option value="">请选择</option>\n' +
        '<option value="1">兑现</option>\n' +
        '<option value="2">不予兑现</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '<div class="form-group" style="display: none;margin: 10px;" id="descideDesc">\n' +
        '<label for="processLable" class=" control-label">计算说明</label>\n' +
        '<textarea class="form-control" id="decideMoneyDetail" rows="4"></textarea>\n' +
        '</div>\n' +
        '<div class="form-group" style="display: none;margin: 10px;" id="moneyDiv">\n' +
        '<label for="processLable" class=" control-label">应该享受金额(不扣除其他政策金额前)</label>\n' +
        '<input class="form-control" id="shouldEnjoyMoney">\n' +
        '</div>\n' +
        '</form>';
}

HousepurchaseInfoDlg.afterToggleField = function (context) {
    var checkState = $(context).val();
    if (checkState == -1) {
        $("#cashType").attr("style", "pointer-events: none;background-color: #eee;").val(2).trigger("change");
    } else {
        $("#cashType").removeAttr("style").val("");
    }
}

HousepurchaseInfoDlg.afterCashTypeChange = function () {
    var declareType = $("#declareType").val();
    var cashType = $("#cashType").val();
    if (cashType == 1) {
        if (declareType == 1) {
            $("#descideDesc,#moneyDiv").css("display", "block");
        } else {
            $("#descideDesc,#moneyDiv").css("display", "none");
        }
    } else {
        $("#descideDesc,#moneyDiv").css("display", "none");
        $("#descideDesc,#moneyDiv").val("");
    }
}


/**
 * 复核页面
 */
HousepurchaseInfoDlg.createThirdCheckHtml = function () {
    var idCard = $("#idCard").val();
    var name = $("#name").val();
    var spouseName = $("#spouseName").val();
    var spouseIdcard = $("#spouseIdcard").val();
    var options = "<option value='" + idCard + "'>" + name + "</option>";
    if (Feng.isNotEmptyStr(spouseIdcard)) {
        options = options + "<option value='" + spouseIdcard + "'>" + spouseName + "</option>";
    }
    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="checkStateFirstModal" onchange="HousepurchaseInfoDlg.thirdToggleField()">\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="checkMsgFirst" placeholder="" rows="6"></textarea>\n' +
        '</div>\n' +
        '<div class="form-group" style="display: none;margin: 10px;" id="cashTypeDiv">\n' +
        '<label for="processLable" class=" control-label">兑现状态</label>\n' +
        '<select class="form-control" id="cashType" onchange="HousepurchaseInfoDlg.cashTypeChange()">\n' +
        '<option value="">请选择</option>\n' +
        '<option value="1">兑现</option>\n' +
        '<option value="2">不予兑现</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '<div class="form-group" style="display: none;margin: 10px;" id="toProcessDiv" >\n' +
        '<label for="processLable" class=" control-label">驳回至</label>\n' +
        '<select class="form-control" id="toProcess" >\n' +
        '<option value="">请选择</option>\n' +
        '<option value="1">初级审核</option>\n' +
        '<option value="2">部门审核</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '<div class="form-group" style="display: none;margin: 10px;" id="toDepDiv" >\n' +
        '<label for="processLable" class=" control-label">驳回单位</label>\n' +
        '<select class="form-control" id="toDep" multiple>\n' +
        '<option value="">请选择</option>\n' +
        '<option value="' + CONFIG.COM_MZJ + '">民政局</option>\n' +
        '<option value="' + CONFIG.COM_ZRZYJ + '">自然资源局</option>\n' +
        '<option value="' + CONFIG.COM_ZJJ + '">住建局</option>\n' +
        '</select>\n' +
        '</div>\n' +
        '</form>';
}


/**
 * 显示字段或者隐藏字段选择
 */
HousepurchaseInfoDlg.toggleField = function () {
    var checkState = $("#checkStateFirstModal").val();
    var process = $("#process").val();
    var checkMsgFirst = $("#checkMsgFirst").val();
    if (checkState == 2 && process == 1) {
        $("#field").show();
        $("#checkMsgFirst").val("");
    } else if (checkState == 3) {
        $("#field").hide();
        $("#field").find("input[type=checkbox]").removeAttr("checked");
        if (Feng.isEmptyStr(checkMsgFirst)) {
            $("#checkMsgFirst").val("审核通过");
        }
    } else if (checkState == -1) {
        $("#field").hide();
        $("#checkMsgFirst").val("审核不通过");
    }
}

/**
 * 复核状态变更
 */
HousepurchaseInfoDlg.thirdToggleField = function () {
    var checkState = $("#checkStateFirstModal").val();
    if (checkState == -1) {
        $("#checkMsgFirst").val("审核不通过");
        $("#toProcess,#toDep,#cashType").val("");
        $("#toProcessDiv,#toDepDiv,#cashTypeDiv,#cashObjDiv").css("display", "none");
    }
    if (checkState == 2) {
        $("#checkMsgFirst").val("");
        $("#cashType").val("");
        $("#cashTypeDiv,#cashObjDiv").css("display", "none");
        $("#toProcessDiv,#toDepDiv").css("display", "block");
    }
    if (checkState == 3) {
        $("#checkMsgFirst").val("审核通过");
        $("#toProcess,#toDep").val("");
        $("#toProcessDiv,#toDepDiv").css("display", "none");
        $("#cashTypeDiv").css("display", "block");
    }
}


/**
 * 删除享受其他政策
 * @param context
 */
HousepurchaseInfoDlg.deleteEnjoyOther = function (context) {
    var id = $(context).parent().next().find("input[name='id']").val()
    var pId = $(context).parent().next().find("input[name='pId']").val()
    if (Feng.isEmptyStr(id)) {
        $(context).parent().parent().remove();
    } else {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
                if (data.code == 200) {
                    var ajax1 = new $ax(Feng.ctxPath + "/housepurchase/deleteOtherOrHouse", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            $(context).parent().parent().remove();
                        } else {
                            Feng.info(data.msg);
                        }
                    }, function (data) {
                        Feng.error("删除失败!" + data.responseJSON.message + "!");
                    });
                    ajax1.set("id", id);
                    ajax1.set("type", 1);
                    ajax1.start();
                } else {
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("校验失败!" + data.responseJSON.message + "!");
            });
            ajax.setData({"id": $("#id").val(), "process": $("#process").val(), "companyId": $("#companyId").val()})
            ajax.start();
        }
        Feng.confirm("一旦删除无法恢复，确认删除吗?", operation);
    }
}

/**
 * 删除其他房产信息
 * @param context
 */
HousepurchaseInfoDlg.deleteOtherHouse = function (context) {
    var id = $(context).parent().next().find("input[name='id']").val()
    var pId = $(context).parent().next().find("input[name='pId']").val()
    if (Feng.isEmptyStr(id)) {
        $(context).parent().parent().remove();
    } else {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
                if (data.code == 200) {
                    var ajax1 = new $ax(Feng.ctxPath + "/housepurchase/deleteOtherOrHouse", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            $(context).parent().parent().remove();
                        } else {
                            Feng.info(data.msg);
                        }
                    }, function (data) {
                        Feng.error("删除失败!" + data.responseJSON.message + "!");
                    });
                    ajax1.set("id", id);
                    ajax1.set("type", 2);
                    ajax1.start();
                } else {
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("校验失败!" + data.responseJSON.message + "!");
            });
            ajax.setData({"id": $("#id").val(), "process": $("#process").val(), "companyId": $("#companyId").val()})
            ajax.start();
        }
        Feng.confirm("一旦删除无法恢复，确认删除吗?", operation);
    }
}

/**
 * 删除配偶信息
 * @param context
 */
HousepurchaseInfoDlg.deleteSpouse = function (context) {
    var id = $(context).parent().next().find("input[name='id']").val()
    if (Feng.isEmptyStr(id)) {
        $(context).parent().parent().remove();
    } else {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/validateIsCheck", function (data) {
                if (data.code == 200) {
                    var ajax1 = new $ax(Feng.ctxPath + "/housepurchase/deleteSpouse", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            $(context).parent().parent().remove();
                        } else {
                            Feng.info(data.msg);
                        }
                    }, function (data) {
                        Feng.error("删除失败!" + data.responseJSON.message + "!");
                    });
                    ajax1.set("id", id);
                    ajax1.start();
                } else {
                    Feng.error(data.msg);
                }
            }, function (data) {
                Feng.error("校验失败!" + data.responseJSON.message + "!");
            });
            ajax.setData({"id": $("#id").val(), "process": $("#process").val(), "companyId": $("#companyId").val()})
            ajax.start();
        }
        Feng.confirm("一旦删除无法恢复，确认删除吗?", operation);
    }
}


/***
 * 保存部门内审核录入数据
 */
HousepurchaseInfoDlg.saveDepCheckData = function () {
    var companyCode = $("#companyCode").val();
    var mainId = $("#id").val();
    var declareType = $("#declareType").val();
    var error = "";
    var obj = null;
    switch (companyCode) {
        case CONFIG.COM_ZJJ:
            var enjoyOtherObject = new Array();
            var otherHouseObject = new Array();
            var checkIsTradeRecord = $("#zjjData").find("select[name='checkIsTradeRecord']").val();
            var checkRecordTime = $("#zjjData").find("input[name='checkRecordTime']").val();
            var zjjCheckDetail = $("#zjjData").find("input[name='zjjCheckDetail']").val();
            if (declareType == 1) {
                if (Feng.isEmptyStr(checkIsTradeRecord)) {
                    Feng.info("请选择是否交易备案");
                    return;
                }
                if (checkIsTradeRecord == 1 && Feng.isEmptyStr(checkRecordTime)) {
                    Feng.info("请选填写交易备案时间");
                    return;
                }
            }
            var error = HousepurchaseInfoDlg.getZjjData(enjoyOtherObject, otherHouseObject);
            if (Feng.isNotEmptyStr(error)) {
                Feng.info(error);
                return;
            }
            obj = {
                "id": mainId,
                "companyId": $("#companyId").val(),
                "checkIsTradeRecord": checkIsTradeRecord,
                "checkRecordTime": checkRecordTime,
                "zjjCheckDetail": zjjCheckDetail,
                "otherList": enjoyOtherObject,
                "houseList": otherHouseObject
            };
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/zjjCheck", function (data) {
                if (data.code == 200) {
                    HousepurchaseInfoDlg.initZzj(data.obj.otherList, data.obj.houseList);
                    Feng.success(data.msg);
                } else {
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("提交失败!" + data.responseJSON.message + "!");
            });
            ajax.setcontentType("application/json;charset=utf-8");
            ajax.setData(JSON.stringify(obj));
            ajax.start();
            break;
        case CONFIG.COM_ZRZYJ:
            var otherHouseObject = new Array();
            var isHasBdcCard = $("#isHasBdcCard").val();
            var bdcRegistTime = $("#bdcRegistTime").val();
            var isOwner = $("#isOwner").val();
            var transferMethod = $("#transferMethod").val();
            var transferTime = $("#transferTime").val();
            var zrzzjCheckDetail = $("#zrzzjCheckDetail").val();
            if (declareType == 1) {
                if (Feng.isEmptyStr(isHasBdcCard)) {
                    Feng.info("请选择是否已办理不动产权证");
                    return;
                }
                if (isHasBdcCard == 1 && Feng.isEmptyStr(bdcRegistTime)) {
                    Feng.info("请填写不动产权证书登记时间");
                    return;
                }
                if (Feng.isEmptyStr(isOwner)) {
                    Feng.info("请选择其购置的房屋是否还在名下");
                    return;
                }
                if (isOwner == 2 && Feng.isEmptyStr(transferMethod)) {
                    Feng.info("请填写过户方式");
                    return;
                }
                if (isOwner == 2 && Feng.isEmptyStr(transferTime)) {
                    Feng.info("请填写过户时间");
                    return;
                }
            }
            var error = HousepurchaseInfoDlg.getZrzyjData(otherHouseObject);
            if (Feng.isNotEmptyStr(error)) {
                Feng.info(error);
                return;
            }
            obj = {
                "id": mainId,
                "companyId": $("#companyId").val(),
                "isHasBdcCard": isHasBdcCard,
                "bdcRegistTime": bdcRegistTime,
                "isOwner": isOwner,
                "transferMethod": transferMethod,
                "transferTime": transferTime,
                "zrzzjCheckDetail": zrzzjCheckDetail,
                "houseList": otherHouseObject
            };
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/zrzyjCheck", function (data) {
                if (data.code == 200) {
                    HousepurchaseInfoDlg.initZrzyj(data.obj.houseList);
                    Feng.success(data.msg);
                } else {
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("提交失败!" + data.responseJSON.message + "!");
            });
            ajax.setcontentType("application/json;charset=utf-8");
            ajax.setData(JSON.stringify(obj));
            ajax.start();
            break;
        case CONFIG.COM_MZJ:
            var spouseObj = new Array();
            var mzjCheckDetail = $("#mzjCheckDetail").val();
            $("#mzjMarryData .panel-body").each(function (index) {
                var id = $(this).find("input[name='id']").val();
                var pId = $(this).find("input[name='pId']").val();
                var type = $(this).find("select[name='type']").val();
                var name = $(this).find("input[name='name']").val();
                var registerTime = $(this).find("input[name='registerTime']").val();
                var idCard = $(this).find("input[name='idCard']").val();
                // var description = $(this).find("input[name='description']").val();
                if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(type) || Feng.isNotEmptyStr(name) ||
                    Feng.isNotEmptyStr(registerTime) || Feng.isNotEmptyStr(idCard)) {
                    if (Feng.isEmptyStr(type)) {
                        error = error + "婚姻状况" + (index + 1) + "登记类型为空;\n";
                    }
                    if (Feng.isEmptyStr(name)) {
                        error = error + "婚姻状况" + (index + 1) + "配偶姓名为空;\n";
                    }
                    if (Feng.isEmptyStr(idCard)) {
                        error = error + "婚姻状况" + (index + 1) + "配偶证件号码为空;\n";
                    }
                    if (Feng.isEmptyStr(registerTime)) {
                        error = error + "婚姻状况" + (index + 1) + "登记时间为空;\n";
                    } else if (!/^\d{4}-\d{2}-\d{2}$/.test(registerTime)) {
                        error = error + "房产信息" + (index + 1) + "登记时间格式不正确;\n";
                    }
                    spouseObj.push({
                        "id": id,
                        "type": type,
                        "name": name,
                        "registerTime": registerTime,
                        "idCard": idCard
                    });
                }
            });
            if (Feng.isNotEmptyStr(error)) {
                Feng.info(error);
                return;
            }
            obj = {
                "id": mainId,
                "companyId": $("#companyId").val(),
                "mzjCheckDetail": mzjCheckDetail,
                "spouseList": spouseObj
            };
            var ajax = new $ax(Feng.ctxPath + "/housepurchase/mzjCheck", function (data) {
                if (data.code == 200) {
                    HousepurchaseInfoDlg.initMzj(data.obj.spouseList);
                    Feng.success(data.msg);
                } else {
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("提交失败!" + data.responseJSON.message + "!");
            });
            ajax.setcontentType("application/json;charset=utf-8");
            ajax.setData(JSON.stringify(obj));
            ajax.start();
            break;
            break;
    }
}


HousepurchaseInfoDlg.getZjjData = function (enjoyOtherObject, otherHouseObject) {
    var error = "";
    $("#zzjOtherBody .panel-body").not(".history").each(function (index) {
        var id = $(this).find("input[name='id']").val();
        var pId = $(this).find("input[name='pId']").val();
        var name = $(this).find("input[name='name']").val();
        var idCard = $(this).find("input[name='idCard']").val();
        var houseAddress = $(this).find("input[name='houseAddress']").val();
        var recordNo = $(this).find("input[name='recordNo']").val();
        var enjoyPolicyName = $(this).find("input[name='enjoyPolicyName']").val();
        var money = $(this).find("input[name='money']").val();
        var enjoyTime = $(this).find("input[name='enjoyTime']").val();
        var description = $(this).find("input[name='description']").val();
        if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(name) || Feng.isNotEmptyStr(houseAddress) || Feng.isNotEmptyStr(idCard) ||
            Feng.isNotEmptyStr(recordNo) || Feng.isNotEmptyStr(enjoyPolicyName) || Feng.isNotEmptyStr(money) || Feng.isNotEmptyStr(enjoyTime)) {
            if (Feng.isEmptyStr(name)) {
                error = error + "享受其他政策" + (index + 1) + ")享受人姓名为空;\n";
            }
            if (Feng.isEmptyStr(idCard)) {
                error = error + "享受其他政策" + (index + 1) + ")享受人证件号码为空;\n";
            }
            if (Feng.isEmptyStr(houseAddress)) {
                error = error + "享受其他政策" + (index + 1) + "房屋坐落地址为空;\n";
            }
            if (Feng.isEmptyStr(recordNo)) {
                error = error + "享受其他政策" + (index + 1) + "合同编号为空;\n";
            }
            if (Feng.isEmptyStr(enjoyPolicyName)) {
                error = error + "享受其他政策" + (index + 1) + "享受政策名称为空;\n";
            }
            if (Feng.isEmptyStr(money)) {
                error = error + "享受其他政策" + (index + 1) + "补贴发放金额为空;\n";
            } else if (!/^([1-9][0-9]*)+(\.[0-9]{1,10})?$/.test(money)) {
                error = error + "享受其他政策" + (index + 1) + "金额格式不正确;\n";
            }
            if (Feng.isEmptyStr(enjoyTime)) {
                error = error + "享受其他政策" + (index + 1) + "发放时间为空;\n";
            } else if (!/^\d{4}-\d{2}-\d{2}$/.test(enjoyTime)) {
                error = error + "享受其他政策" + (index + 1) + "发放时间格式不正确;\n";
            }
            enjoyOtherObject.push({
                "id": id,
                "pId": pId,
                "name": name,
                "idCard": idCard,
                "houseAddress": houseAddress,
                "recordNo": recordNo,
                "enjoyPolicyName": enjoyPolicyName,
                "money": money,
                "description": description,
                "enjoyTime": enjoyTime
            });
        }
    });
    if (Feng.isNotEmptyStr(error)) {
        return error;
    }
    $("#zzjOtherHouse .panel-body").each(function (index) {
        var error = "";
        var id = $(this).find("input[name='id']").val();
        var pId = $(this).find("input[name='pId']").val();
        var type = $(this).find("input[name='type']").val();
        var name = $(this).find("input[name='name']").val();
        var idCard = $(this).find("input[name='idCard']").val();
        var number = $(this).find("input[name='number']").val();
        var houseAddress = $(this).find("input[name='houseAddress']").val();
        var area = $(this).find("input[name='area']").val();
        var recordTime = $(this).find("input[name='recordTime']").val();
        var tradeMethod = $(this).find("input[name='tradeMethod']").val();
        var description = $(this).find("input[name='description']").val();
        if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(type) || Feng.isNotEmptyStr(name) || Feng.isNotEmptyStr(number) || Feng.isNotEmptyStr(idCard) ||
            Feng.isNotEmptyStr(houseAddress) || Feng.isNotEmptyStr(area) || Feng.isNotEmptyStr(recordTime) || Feng.isNotEmptyStr(tradeMethod)) {
            if (Feng.isEmptyStr(name)) {
                error = error + "其他房产信息" + (index + 1) + "购房人姓名为空;\n";
            }
            if (Feng.isEmptyStr(idCard)) {
                error = error + "其他房产信息" + (index + 1) + "购房人证件号码为空;\n";
            }
            if (Feng.isEmptyStr(number)) {
                error = error + "其他房产信息" + (index + 1) + "合同编号为空;\n";
            }
            if (Feng.isEmptyStr(houseAddress)) {
                error = error + "其他房产信息" + (index + 1) + "房屋坐落地址为空;\n";
            }
            if (Feng.isEmptyStr(area)) {
                error = error + "其他房产信息" + (index + 1) + "面积为空;\n";
            } else if (!/^([1-9][0-9]*)+(\.[0-9]{0,10})?$/.test(area)) {
                error = error + "其他房产信息" + (index + 1) + "面积格式不正确;\n";
            }
            if (Feng.isEmptyStr(recordTime)) {
                error = error + "其他房产信息记录中第" + (index + 1) + "交易备案时间为空;\n";
            } else if (!/^\d{4}-\d{2}-\d{2}$/.test(recordTime)) {
                error = error + "其他房产信息" + (index + 1) + "交易备案时间格式不正确;\n";
            }
            if (Feng.isEmptyStr(tradeMethod)) {
                error = error + "其他房产信息" + (index + 1) + "交易方式为空;\n";
            }
            otherHouseObject.push({
                "id": id,
                "type": type,
                "name": name,
                "idCard": idCard,
                "number": number,
                "houseAddress": houseAddress,
                "area": area,
                "recordTime": recordTime,
                "tradeMethod": tradeMethod,
                "description": description
            });
        }
    });
    if (Feng.isNotEmptyStr(error)) {
        return error;
    }
    return null;
}

HousepurchaseInfoDlg.getZrzyjData = function (otherHouseObject) {
    var error = "";
    $("#zrzyOtherHouse .panel-body").each(function (index) {
        var id = $(this).find("input[name='id']").val();
        var pId = $(this).find("input[name='pId']").val();
        var type = $(this).find("input[name='type']").val();
        var name = $(this).find("input[name='name']").val();
        var idCard = $(this).find("input[name='idCard']").val();
        var houseAddress = $(this).find("input[name='houseAddress']").val();
        var number = $(this).find("input[name='number']").val();
        var area = $(this).find("input[name='area']").val();
        var recordTime = $(this).find("input[name='recordTime']").val();
        var description = $(this).find("input[name='description']").val();
        if (Feng.isNotEmptyStr(id) || Feng.isNotEmptyStr(pId) || Feng.isNotEmptyStr(type) || Feng.isNotEmptyStr(name) || Feng.isNotEmptyStr(idCard) ||
            Feng.isNotEmptyStr(houseAddress) || Feng.isNotEmptyStr(area) || Feng.isNotEmptyStr(recordTime) || Feng.isNotEmptyStr(number)) {
            if (Feng.isEmptyStr(name)) {
                error = error + "房产信息" + (index + 1) + "产权人姓名为空;\n";
            }
            if (Feng.isEmptyStr(idCard)) {
                error = error + "房产信息" + (index + 1) + "产权人证件号码为空;\n";
            }
            if (Feng.isEmptyStr(houseAddress)) {
                error = error + "房产信息" + (index + 1) + "房屋坐落地址为空;\n";
            }
            if (Feng.isEmptyStr(area)) {
                error = error + "房产信息" + (index + 1) + "面积为空;\n";
            } else if (!/^([1-9][0-9]*)+(\.[0-9]{1,10})?$/.test(area)) {
                error = error + "其他房产信息" + (index + 1) + "面积格式不正确;\n";
            }
            if (Feng.isEmptyStr(recordTime)) {
                error = error + "房产信息" + (index + 1) + "房屋登记时间为空;\n";
            } else if (!/^\d{4}-\d{2}-\d{2}$/.test(recordTime)) {
                error = error + "房产信息" + (index + 1) + "房屋登记时间格式不正确;\n";
            }
            otherHouseObject.push({
                "id": id,
                "type": type,
                "name": name,
                "idCard": idCard,
                "houseAddress": houseAddress,
                "area": area,
                "recordTime": recordTime,
                "number": number,
                "description": description
            });
        }
    });
    if (Feng.isNotEmptyStr(error)) {
        return error;
    }
    return null;
}

/**
 * 公示再审核修改住建局、自然资源局录入数据
 */
HousepurchaseInfoDlg.afterCheckEdit = function () {
    var mainId = $("#id").val();
    var declareType = $("#declareType").val();
    var enjoyOtherObject = new Array();
    var zjjOtherHouseObject = new Array();
    var zrzyjOtherHouseObject = new Array();
    var checkIsTradeRecord = $("#zjjData").find("select[name='checkIsTradeRecord']").val();
    var checkRecordTime = $("#zjjData").find("input[name='checkRecordTime']").val();
    var zjjCheckDetail = $("#zjjData").find("input[name='zjjCheckDetail']").val();
    if (declareType == 1) {
        if (Feng.isEmptyStr(checkIsTradeRecord)) {
            Feng.info("请选择是否交易备案");
            return;
        }
        if (checkIsTradeRecord == 1 && Feng.isEmptyStr(checkRecordTime)) {
            Feng.info("请选填写交易备案时间");
            return;
        }
    }
    var error = HousepurchaseInfoDlg.getZjjData(enjoyOtherObject, zjjOtherHouseObject);
    if (Feng.isNotEmptyStr(error)) {
        Feng.info(error);
        return;
    }
    var isHasBdcCard = $("#isHasBdcCard").val();
    var bdcRegistTime = $("#bdcRegistTime").val();
    var isOwner = $("#isOwner").val();
    var transferMethod = $("#transferMethod").val();
    var transferTime = $("#transferTime").val();
    var zrzzjCheckDetail = $("#zrzzjCheckDetail").val();
    if (declareType == 1) {
        if (Feng.isEmptyStr(isHasBdcCard)) {
            Feng.info("请选择是否已办理不动产权证");
            return;
        }
        if (isHasBdcCard == 1 && Feng.isEmptyStr(bdcRegistTime)) {
            Feng.info("请填写不动产权证书登记时间");
            return;
        }
        if (Feng.isEmptyStr(isOwner)) {
            Feng.info("请选择其购置的房屋是否还在名下");
            return;
        }
        if (isOwner == 2 && Feng.isEmptyStr(transferMethod)) {
            Feng.info("请填写过户方式");
            return;
        }
        if (isOwner == 2 && Feng.isEmptyStr(transferTime)) {
            Feng.info("请填写过户时间");
            return;
        }
    }
    error = HousepurchaseInfoDlg.getZrzyjData(zrzyjOtherHouseObject);
    if (Feng.isNotEmptyStr(error)) {
        Feng.info(error);
        return;
    }
    var obj = {
        "id": mainId,
        "checkIsTradeRecord": checkIsTradeRecord,
        "checkRecordTime": checkRecordTime,
        "zjjCheckDetail": zjjCheckDetail,
        "isHasBdcCard": isHasBdcCard,
        "bdcRegistTime": bdcRegistTime,
        "isOwner": isOwner,
        "transferMethod": transferMethod,
        "transferTime": transferTime,
        "zrzzjCheckDetail": zrzzjCheckDetail,
        "zjjHouseList": zjjOtherHouseObject,
        "zrzyjHouseList":zrzyjOtherHouseObject,
        "otherList": enjoyOtherObject
    };
    var ajax = new $ax(Feng.ctxPath + "/housepurchase/afterCheckEdit", function (data) {
        if (data.code == 200) {
            HousepurchaseInfoDlg.initZzj(data.obj.otherList, data.obj.zjjOtherHouseObject);
            HousepurchaseInfoDlg.initZrzyj(data.obj.zrzyjOtherHouseObject);
            Feng.success(data.msg);
        } else {
            Feng.info(data.msg);
        }
    }, function (data) {
        Feng.error("提交失败!" + data.responseJSON.message + "!");
    });
    ajax.setcontentType("application/json;charset=utf-8");
    ajax.setData(JSON.stringify(obj));
    ajax.start();
}


HousepurchaseInfoDlg.initZzj = function (otherList, houseList) {
    if (otherList != null) {
        var html = "";
        for (var key in otherList) {
            html = html +
                '<div class="panel panel-default" >\n' +
                '        <div class="panel-heading">\n' +
                '            <span class="caret" onclick="$(this).parent().next().toggle()"></span>\n' +
                '            <span class="houseTitle" >' + otherList[key].enjoyPolicyName + '</span>\n' +
                '            <button type="button" class="close" aria-label="Close" style="float: right" onclick="HousepurchaseInfoDlg.deleteEnjoyOther(this)">\n' +
                '                <span aria-hidden="true">&times;</span>\n' +
                '            </button>\n' +
                '        </div>\n' +
                '        <div class="panel-body">\n' +
                '            <div class="col-sm-12">\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <input type="hidden"  name="id" value="' + otherList[key].id + '"/>\n' +
                '                    <input type="hidden"  name="pId" value="' + otherList[key].pId + '"/>\n' +
                '                    <label class="control-label spacing">享受人姓名</label>\n' +
                '                    <input type="text" class="form-control" name="name" value="' + otherList[key].name + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">享受人证件号码</label>\n' +
                '                    <input type="text" class="form-control" name="idCard" value="' + otherList[key].idCard + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">房屋坐落地址</label>\n' +
                '                    <input type="text" class="form-control" name="houseAddress" value="' + otherList[key].houseAddress + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">合同编号</label>\n' +
                '                    <input type="text" class="form-control" name="recordNo" value="' + otherList[key].recordNo + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">享受政策名称(例：XX年度第X批XX购房补助)</label>\n' +
                '                    <input type="text" class="form-control" name="enjoyPolicyName" placeholder="例：XX年度第X批XX购房补助" value="' + otherList[key].enjoyPolicyName + '" onchange="$(this).parent().parent().parent().parent().find(\'.houseTitle\').text($(this).val())"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">补贴发放金额(元)</label>\n' +
                '                    <input type="text" class="form-control" name="money" value="' + otherList[key].money + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">发放时间</label>\n' +
                '                    <input type="text" class="form-control date" name="enjoyTime" value="' + otherList[key].enjoyTime + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">备注</label>\n' +
                '                    <input type="text" class="form-control" name="description" value="' + otherList[key].description + '"/>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>';
        }
        $("#zzjOtherBody .panel-default").not(".history").remove();
        $("#zzjOtherBody").append(html);
    }
    if (houseList != null) {
        var html = "";
        for (var key in houseList) {
            html = html +
                '<div class="panel panel-default">\n' +
                '        <div class="panel-heading">\n' +
                '            <span class="caret" onclick="$(this).parent().next().toggle()"></span>\n' +
                '            <span class="houseTitle" >' + houseList[key].houseAddress + '</span>\n' +
                '            <button type="button" class="close" aria-label="Close" style="float: right" onclick="HousepurchaseInfoDlg.deleteOtherHouse(this)">\n' +
                '                <span aria-hidden="true">&times;</span>\n' +
                '            </button>\n' +
                '        </div>\n' +
                '        <div class="panel-body">\n' +
                '            <div class="col-sm-12">\n' +
                '                <input type="hidden" name="id" value="' + houseList[key].id + '"/>\n' +
                '                <input type="hidden" name="pId" value="' + houseList[key].pId + '"/>\n' +
                '                <input type="hidden" name="type" value="' + houseList[key].type + '"/>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">购房人姓名</label>\n' +
                '                    <input type="text" class="form-control" name="name" value="' + houseList[key].name + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">购房人证件号码</label>\n' +
                '                    <input type="text" class="form-control" name="idCard" value="' + houseList[key].idCard + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">房屋坐落地址</label>\n' +
                '                    <input type="text" class="form-control" name="houseAddress" value="' + houseList[key].houseAddress + '" onchange="$(this).parent().parent().parent().parent().find(\'.houseTitle\').text($(this).val())"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">合同编号</label>\n' +
                '                    <input type="text" class="form-control" name="number" value="' + houseList[key].number + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">面积(m2)</label>\n' +
                '                    <input type="text" class="form-control" name="area" value="' + houseList[key].area + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">交易备案时间</label>\n' +
                '                    <input type="text" class="form-control date" name="recordTime" value="' + houseList[key].recordTime + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">交易方式(购买、出售、签约注销、备案注销等)</label>\n' +
                '                    <input type="text" class="form-control" name="tradeMethod" value="' + houseList[key].tradeMethod + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">备注</label>\n' +
                '                    <input type="text" class="form-control" name="description" value="' + houseList[key].description + '"/>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>';
        }
        $("#zzjOtherHouse").empty().append(html);
    }
}

HousepurchaseInfoDlg.initZrzyj = function (houseList) {
    if (houseList != null) {
        var html = "";
        for (var key in houseList) {
            html = html +
                '<div class="panel panel-default">\n' +
                '        <div class="panel-heading">\n' +
                '            <span class="caret" onclick="$(this).parent().next().toggle()"></span>\n' +
                '            <span class="houseTitle">' + houseList[key].houseAddress + '</span>\n' +
                '            <button type="button" class="close" aria-label="Close" style="float: right" onclick="HousepurchaseInfoDlg.deleteOtherHouse(this)">\n' +
                '                <span aria-hidden="true">&times;</span>\n' +
                '            </button>\n' +
                '        </div>\n' +
                '        <div class="panel-body">\n' +
                '            <div class="col-sm-12">\n' +
                '                <input type="hidden" name="id" value="' + houseList[key].id + '"/>\n' +
                '                <input type="hidden" name="pId" value="' + houseList[key].pId + '"/>\n' +
                '                <input type="hidden" name="type" value="' + houseList[key].type + '"/>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">产权人姓名</label>\n' +
                '                    <input type="text" class="form-control" name="name" value="' + houseList[key].name + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">产权人证件号码</label>\n' +
                '                    <input type="text" class="form-control" name="idCard" value="' + houseList[key].idCard + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">房屋坐落地址</label>\n' +
                '                    <input type="text" class="form-control" name="houseAddress" value="' + houseList[key].houseAddress + '" onchange="$(this).parent().parent().parent().parent().find(\'.houseTitle\').text($(this).val())"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">不动产权号</label>\n' +
                '                    <input type="text" class="form-control" name="number" value="' + houseList[key].number + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">面积(m2)</label>\n' +
                '                    <input type="text" class="form-control" name="area" value="' + houseList[key].area + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">房屋登记时间</label>\n' +
                '                    <input type="text" class="form-control date" name="recordTime" value="' + houseList[key].recordTime + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">备注</label>\n' +
                '                    <input type="text" class="form-control" name="description" value="' + houseList[key].description + '"/>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>'
        }
        $("#zrzyOtherHouse").empty().append(html);
    }
}

HousepurchaseInfoDlg.initMzj = function (spouseList) {
    if (spouseList != null) {
        var html = "";
        for (var key in spouseList) {
            html = html +
                '<div class="panel panel-default">\n' +
                '        <div class="panel-heading">\n' +
                '            <span class="caret" onclick="$(this).parent().next().toggle()"></span>\n' +
                '            <span class="houseTitle">' + spouseList[key].registerTime + '</span>\n' +
                '            <button type="button" class="close" aria-label="Close" style="float: right" onclick="HousepurchaseInfoDlg.deleteSpouse(this)">\n' +
                '                <span aria-hidden="true">&times;</span>\n' +
                '            </button>\n' +
                '        </div>\n' +
                '        <div class="panel-body">\n' +
                '            <div class="col-sm-12">\n' +
                '                <input type="hidden" name="id" />\n' +
                '                <input type="hidden" name="pId" />\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">登记类型</label>\n' +
                '                    <select type="text" class="form-control" name="type" value="' + spouseList[key].type + '">\n' +
                '                        <option value="">请选择</option>\n' +
                '                        <option value="1">初婚</option>\n' +
                '                        <option value="2">复婚</option>\n' +
                '                        <option value="3">再婚</option>\n' +
                '                        <option value="4">离婚</option>\n' +
                '                    </select>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">登记时间</label>\n' +
                '                    <input type="text" class="form-control date" name="registerTime" value="' + spouseList[key].registerTime + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">配偶姓名</label>\n' +
                '                    <input type="text" class="form-control" name="name" value="' + spouseList[key].name + '"/>\n' +
                '                </div>\n' +
                '                <div class="rowGroup col-sm-3">\n' +
                '                    <label class="control-label spacing">配偶证件号码</label>\n' +
                '                    <input type="text" class="form-control" name="idCard" value="' + spouseList[key].idCard + '"/>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>'
        }
        $("#mzjMarryData").empty().append(html);
        $("select").each(function () {
            $(this).val($(this).attr("value"));
        });
    }
}

HousepurchaseInfoDlg.initDate = function () {
    $(".date").removeAttr('lay-key');
    $(".date").each(function () {
        laydate.render({
            elem: this
            , type: 'date'
            , trigger: 'click'
        });
    });
}

$(function () {
    $("select").each(function () {
        $(this).val($(this).attr("value"));
    });
    Feng.getCheckLog("logTable", {
        "type": CONFIG.project_house,
        "mainId": $("#id").val(),
        "typeFileId": "",
        "active": 1
    })
    HousepurchaseInfoDlg.initDate();
    Feng.showMiniFileModal(CONFIG.project_house,$("#type").val(),$("#id").val());
    initNoBtnFileTable(CONFIG.project_house,'fileTable');
    var declareType = $("#declareType").val();
    if (declareType == 1) {
        $('#historyTable').bootstrapTable({
            url: Feng.ctxPath + "/housepurchase/getHistoryRecord?id=" + $("#id").val(),
            method: 'POST',
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            search: false,					// 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
            showRefresh: false,				// 是否显示刷新按钮
            clickToSelect: true,			// 是否启用点击选中行
            singleSelect: true,				// 设置True 将禁止多选
            striped: true,  				// 是否显示行间隔色
            pagination: false,   			// 设置为 true 会在表格底部显示分页条
            paginationHAlign: "left",
            paginationDetailHAlign: "right",
            sidePagination: "server",   	// 设置在哪里进行分页，可选值为 'client' 或者 'server'
            showColumns: false,
            rowStyle: function (row, index) {
                return {
                    css: {
                        "word-break": "break-word",
                        "white-space": "inherit"
                    }
                }
            },
            columns:
                [
                    {
                        title: '年度',
                        field: 'year',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "80px",
                        'class': 'uitd_showTip',
                    },
                    {
                        title: '姓名',
                        field: 'name',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '证件号码',
                        field: 'idCard',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "150px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '婚姻状态',
                        field: 'marryStatusName',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '配偶姓名',
                        field: 'spouseName',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '配偶证件号码',
                        field: 'spouseIdcard',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '房屋地址',
                        field: 'houseAddress',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '房屋建筑面积',
                        field: 'houseArea',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '房源成交金额',
                        field: 'houseMoney',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        width: "100px",
                        'class': 'uitd_showTip'
                    },
                    {
                        title: '计算结果',
                        field: 'realEnjoyMoney',
                        visible: true,
                        align: 'center',
                        valign: 'middle',
                        'class': 'uitd_showTip',
                        width: "100px",
                        formatter: function (value, row, index) {
                            if (row.cashType == 1 && row.declareType == 1) {
                                var html = "1.可享受总金额(首套房产金额)：" + (parseFloat(row.totalMoney) / 10000).toFixed(2) +
                                    "万元</br>2.个人余额(未扣除本次)：" + (parseFloat(row.balanceMoney) / 10000).toFixed(2) +
                                    "万元</br>3.房产余额(未扣除本次)：" + (parseFloat(row.houseBalanceMoney) / 10000).toFixed(2) +
                                    "万元</br>4.上一年度未扣除其他政策金额：" + (parseFloat(row.lastOtherMoney) / 10000).toFixed(2) +
                                    "万元</br>5.本年度新增享受其他政策金额：" + (parseFloat(row.nowOtherMoney) / 10000).toFixed(2) +
                                    "万元</br>6.本年度人才层次可享受金额：" + (parseFloat(row.talentArrangeMoney) / 10000).toFixed(2) +
                                    "万元</br>7.本年度应享受金额(2,3,6比较得到)：" + (parseFloat(row.shouldEnjoyMoney) / 10000).toFixed(2) +
                                    "万元</br>8.本年度扣除享受其他政策金额：" + (parseFloat(row.nowSubOtherMoney) / 10000).toFixed(2) +
                                    "万元</br>9.本年度未扣除享受其他政策金额：" + (parseFloat(row.nowNotSubOtherMoney) / 10000).toFixed(2) +
                                    "万元</br>10.本年度最终可到账金额：" + (parseFloat(row.realEnjoyMoney) / 10000).toFixed(2) + "万元";
                                return "<span class='label label-success' onclick=\"layer.alert('" + html + "', {title:'计算结果', skin: 'layui-layer-molv',closeBtn: 0})\" >" +
                                    "<i class=\"fa fa-book\"></i>查看" +
                                    "</span>";
                            } else {
                                return "无";
                            }
                        }
                    }
                ]
            ,
            onPostBody: function () {
                $('#' + id + "td.uitd_showTip").bind("mouseover", function () {
                    var htm = $(this).html();
                    $(this).webuiPopover({title: '详情', content: htm, trigger: 'hover'}).webuiPopover('show');
                });
            }
        });
    }
});
