/**
 * 购房补贴管理初始化
 */
var Housepurchase = {
    id: "housepurchaseTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};

Housepurchase.formParams = function () {
    var queryData = {};
    queryData['companyName'] = $("#companyName").val();
    queryData['year'] = $("#year").val();
    queryData['name'] = $("#name").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['spouseName'] = $("#spouseName").val();
    queryData['spouseIdcard'] = $("#spouseIdcard").val();
    queryData['childName'] = $("#childName").val();
    queryData['childIdCard'] = $("#childIdCard").val();
    queryData['marryStatus'] = $("#marryStatus").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['isConflict'] = $("isConflict").val();
    queryData['isRecover'] = $("isRecover").val()
    return queryData;
}

/**
 * 查询购房补贴列表
 */
Housepurchase.search = function () {
    Housepurchase.table.refresh({query: Housepurchase.formParams()});
};

/**
 * 重置
 */
Housepurchase.reset = function () {
    $("#companyName").val("");
    $("#year").val("");
    $("#name").val("");
    $("#idCard").val("");
    $("#talentArrange").val("");
    $("#spouseName").val("");
    $("#spouseIdcard").val("");
    $("#childName").val("");
    $("#childIdCard").val("");
    $("#marryStatus").val("");
    $("#checkState").val("");
    $("isConflict").val("");
    $("isRecover").val("");
}


/**
 * 初始化表格的列
 */
Housepurchase.initColumn = function () {
    var process = $("#process").val();
    var type = $("#type").val();
    return [
        {field: 'selectItem', radio: true},
        {title: '审核单位', field: 'companyName', visible: process == 2, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "130px"},
        {title: '申报年度', field: 'year', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
        {title: '申报企业', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '申报类型', field: 'declareType', visible: type == 1, align: 'center', valign: 'middle', width: "80px",
            formatter(value, row, index) {
                if (value == 1) {
                    return "购房补贴";
                } else if (value == 2) {
                    return "免租入住";
                }
            }
        },
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "150px"},
        {title: '人才标签', field: 'talentTypeName', visible: type == 1, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '人才层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
        {title: '认定条件', field: 'identifyConditionCH', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '联系电话', field: 'phone', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '婚姻状态', field: 'marryStatusName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '配偶姓名', field: 'spouseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
        // {title: '配偶证件类型', field: 'spouseCardTypeName', visible: true, align: 'center', valign: 'middle'},
        {title: '配偶证件号码', field: 'spouseIdcard', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "150px"},
        {title: '享受第几次购房补贴', field: 'number', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "140px"},
        // {title: '房产编号', field: 'houseCode', visible: process != 2, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"100px"},
        {title: '房屋坐落地址', field: 'houseAddress', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '房屋建筑面积', field: 'houseArea', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        // {title: '商品房购房合同备案时间', field: 'recordTime', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"150px"},
        {title: '房屋成交金额', field: 'houseMoney', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '兑现状态', field: "cashType", visible: process == 4, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px",
            formatter: function (value, row, index) {
                if (Feng.isEmptyStr(value))
                    return "<span style='color: black'>未判定</span>";
                if (value == 1)
                    return "<span style='color: green'>兑现</span>";
                if (value == 2)
                    return "<span style='color: red'>不予兑现</span>";
            }
        },
        // {title: '兑现对象', field: 'cashIdCards', visible: process ==4 , align: 'center', valign: 'middle','class': 'uitd_showTip',width:"100px"},
        {title: '计算结果', field: 'realEnjoyMoney', visible: process == 4, 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) +
                            "</br>11.判定说明：" + row.decideDetail;
                    return "<span class='label label-success' onclick=\"layer.alert('" + html + "', {title:'计算结果', skin: 'layui-layer-molv',closeBtn: 0,area: ['500px', '500px']})\" >" +
                            "<i class=\"fa fa-book\"></i>查看" +
                            "</span>";
                } else {
                    return "无";
                }
            }
        },
        {title: '审核状态', field: process == 2 ? 'state' : 'checkState', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px",
            formatter: function (value, row, index) {
                if (process == 1) {
                    if (value == -1) {
                        return "<span class='label label-danger'>审核不通过</span>";
                    }
                    if (value == 1) {
                        return "<span class='label'>待提交</span>"
                    }
                    if (value == 5) {
                        return (Feng.isNotEmptyStr(row.highProcess) && row.highProcess >= 1) ? "<span class='label label-success'>重新提交</span>" : "<span class='label label-success'>待审核</span>";
                    }
                    if (value == 10) {
                        return "<span class='label label-danger'>已驳回</span>"
                    }
                    if (value == 15 || value == 25) {
                        return "<span class='label label-success'>上级驳回</span>"
                    }
                    if (value == 20 || value >= 30) {
                        return "<span class='label label-primary'>已通过</span>"
                    }
                } else if (process == 2) {
                    if (value == 1) {
                        return "<span class='label label-success'>待审核</span>"
                    }
                    if (value == 2) {
                        return "<span class='label label-danger'>已驳回</span>"
                    }
                    if (value == 3) {
                        return "<span class='label label-primary'>已通过</span>"
                    }
                    if (value == 4) {
                        return "<span class='label label-warning'>上级驳回</span>"
                    }
                    if (value == 9) {
                        return "<span class='label label-success'>重新提交</span>"
                    }
                } else if (process == 3) {
                    if (value == -1) {
                        return "<span class='label label-danger'>审核不通过</span>"
                    } else if (value <= 30) {
                        return "<span class='label label-danger'>已驳回</span>"
                    } else if (value == 35) {
                        return (Feng.isNotEmptyStr(row.highProcess) && row.highProcess >= 3) ? "<span class='label label-success'>重新提交</span>" : "<span class='label label-success'>待审核</span>";
                    } else if (value == 40) {
                        return "<span class='label label-primary'>已通过</span>";
                    }
                } else if (process == 4) {
                    if (value == -1) {
                        return "<span class='label label-danger'>审核不通过</span>";
                    } else if (value == 40) {
                        return "<span class='label label-primary'>已通过</span>";
                    }
                }
            }
        },
        {title: '公示状态', field: "publicState", visible: process == 4, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px",
            formatter: function (value, row, index) {
                if (value == 1)
                    return "<span class='label label-warning'>待核查征信</span>";
                if (value == 2)
                    return "<span class='label label-warning'>待公示</span>";
                if (value == 3)
                    return "<span class='label label-success'>公示中</span>";
                if (value == 4)
                    return "<span class='label label-info'>待兑现</span>";
                if (value == 5)
                    return "<span class='label label-primary'>已兑现</span>";
            }
        },
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle', width: "80px",
            formatter: function (value, row, index) {
                return "<span class='label label-success' onclick=\"Feng.getCheckLogModel('" + value + "','" + CONFIG.project_house + "',null)\" >" +
                        "<i class=\"fa fa-book\"></i>日志" +
                        "</span>";
            }
        }
    ];
};

/**
 * 检查是否选中
 */
Housepurchase.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Housepurchase.seItem = selected[0];
        return true;
    }
};

/**
 * 修改驳回字段
 */
Housepurchase.updateFieldsAndFiles = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/findFieldsAndFiles?id=" + Housepurchase.seItem.id, function (data) {
            if (data.code == 200) {
                var obj = data.obj.obj;
                layer.open({
                    type: 1,
                    id: "neewFieldFormModel",
                    title: '修改',
                    area: ['800px', '450px'], //宽高
                    fix: false, //不固定
                    shade: 0,
                    maxmin: true,
                    content: Housepurchase.creatFieldCheckModal(obj),
                    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) {
                        var fileList = data.obj.files;
                        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);
                        if (obj.fields != null && 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 (obj.files != null && obj.files != '') {
                            $("#field_file input").each(function () {
                                if (obj.files.indexOf($(this).val()) != -1) {
                                    this.checked = true;
                                }
                            });
                        }
                    },
                    yes: function (index, layero) {
                        var fields = '';
                        var 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 (Feng.isEmptyStr(fields) && Feng.isEmptyStr(files)) {
                            Feng.info("请选择可修改的字段或附件！");
                            return;
                        }
                        var ajax = new $ax(Feng.ctxPath + "/admin/house/updateFieldsAndFiles", 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": Housepurchase.seItem.id, "fields": fields, "files": files})
                        ajax.start();
                    }
                });
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("查询失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
}

Housepurchase.creatFieldCheckModal = function (obj) {
    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';
    if (obj.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="firstCheckForm">\n' +
            '                    <div class="form-group" style="margin: 10px;">\n' +
            '                        <div id="field">\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>';
}



/**
 * 点击添加购房补贴
 */
Housepurchase.openCheckHousepurchase = function () {
    if (this.check()) {
        var companyId = Feng.isEmptyStr(Housepurchase.seItem.companyId) ? null : Housepurchase.seItem.companyId;
        var process = $("#process").val();
        var index = layer.open({
            type: 2,
            title: '购房补贴审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/house/toCheckPage/id/' + Housepurchase.seItem.id + '/process/' + $("#process").val() + "/companyId/" + companyId + "/hand/1",
            btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            btnAlign: 'c',
            btn1: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                if (process == 1) {
                    obj.HousepurchaseInfoDlg.showFirstCheckModal();
                }
                if (process == 2) {
                    // obj.HousepurchaseInfoDlg.showDepCheckModal();
                    obj.HousepurchaseInfoDlg.saveDepCheckData();
                }
                if (process == 3) {
                    obj.HousepurchaseInfoDlg.showThirdCheckModal();
                }
                if (process == 4) {
                    obj.HousepurchaseInfoDlg.afterCheckEdit();
                }
            }, btn2: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                if (process == 4) {
                    obj.HousepurchaseInfoDlg.showAfterCheckModal();
                } else {
                    obj.HousepurchaseInfoDlg.submitCheck();
                }
                return false;
            }, end: function () {
                Housepurchase.table.refresh();
            }
        });
        layer.full(index);
        Housepurchase.layerIndex = index;
    }
};


Housepurchase.openHousepurchaseDetail = function () {
    if (this.check()) {
        var companyId = Feng.isEmptyStr(Housepurchase.seItem.companyId) ? null : Housepurchase.seItem.companyId;
        var process = $("#process").val();
        var index = layer.open({
            type: 2,
            title: '购房补贴查看',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/house/toCheckPage/id/' + Housepurchase.seItem.id + '/process/' + $("#process").val() + "/companyId/" + companyId + "/hand/2",
        });
        layer.full(index);
        Housepurchase.layerIndex = index;
    }
}


/**
 * 点击添加购房补贴
 */
Housepurchase.openAfterCheckHousepurchase = function () {
    if (this.check()) {
        var companyId = Feng.isEmptyStr(Housepurchase.seItem.companyId) ? null : Housepurchase.seItem.companyId;
        var index = layer.open({
            type: 2,
            title: '购房补贴审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/house/toCheckPage/id/' + Housepurchase.seItem.id + '/process/' + $("#process").val() + "/companyId/" + companyId,
            btn: ['<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            btnAlign: 'c',
            btn1: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.HousepurchaseInfoDlg.showAfterCheckModal();
            }, end: function () {
                Housepurchase.table.refresh();
            }
        });
        layer.full(index);
        Housepurchase.layerIndex = index;
    }
};

/**
 * 撤销复核
 */
Housepurchase.cancleReview = function () {
    if (this.check()) {
        var index = layer.open({
            type: 1,
            title: '撤销复核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: '<form >\n' +
                    '                    <div class="form-group" style="margin: 10px;">\n' +
                    '                        <label for="checkMsg" class="control-label">撤销原因</label>\n' +
                    '                        <textarea class="form-control" id="msg" rows="6"></textarea>\n' +
                    '                    </div>\n' +
                    '                </form>',
            btn: ['<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;提交', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            yes: function (index, layero) {
                var cancleMsg = $("#msg").val();
                if (Feng.isEmptyStr(cancleMsg)) {
                    Feng.error("撤销原因不能为空");
                    return;
                }
                var operation = function () {
                    var ajax = new $ax(Feng.ctxPath + "/admin/house/cancleThirdCheck", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            Housepurchase.table.refresh();
                            layer.close(index);
                        } else {
                            Feng.error(data.msg);
                        }
                    }, function (data) {
                        Feng.error("撤销复核失败!" + data.responseJSON.message + "!");
                    });
                    ajax.setData({"id": Housepurchase.seItem.id, "checkMsg": cancleMsg})
                    ajax.start();
                };
                Feng.confirm("一旦提交无法修改，确定要撤销吗?", operation);
            }
        });
    }
}

/**
 * 显示需要审核的数据（公示/公式通过/兑现）
 * @param type
 */
Housepurchase.showDataCheckModal = function (type) {
    $("#hczxForm").css("display", "none");
    switch (type) {
        case - 1:             //核查征信
            $("#hczxButton").attr("onclick", "Housepurchase.exportHczx()").text("导出");
            $("#exportCommonModalLabel").text("待核查征信导出");
            break;
        case 0:             //征信通过
            $("#hczxButton").attr("onclick", "Housepurchase.hczxPass()").text("提交");
            $("#exportCommonModalLabel").text("批量征信通过");
            break;
        case 1:                     //待公示名单(兑现)
            $("#hczxButton").attr("onclick", "Housepurchase.public(1)").text("公示");
            $("#exportCommonModalLabel").text("待公示名单(兑现)");
            $("#hczxForm").css("display", "block");
            $(".time").each(function () {
                laydate.render({
                    elem: "#" + $(this).attr("id")
                    , type: 'date'
                    , format: 'yyyy年MM月dd日'
                });
            });
            break;
        case 2:                     //待公示名单(不予兑现)
            $("#hczxButton").attr("onclick", "Housepurchase.public(2)").text("公示");
            $("#exportCommonModalLabel").text("待公示名单(不予兑现)");
            $("#hczxForm").css("display", "block");
            $(".time").each(function () {
                laydate.render({
                    elem: "#" + $(this).attr("id")
                    , type: 'date'
                    , format: 'yyyy年MM月dd日'
                });
            });
            break;
        case 3:                     //公示通过（批量）
            $("#hczxButton").attr("onclick", "Housepurchase.publicPass()").text("提交");
            $("#exportCommonModalLabel").text("公示通过名单");
            break;
        case 4:                     //待兑现名单
            $("#hczxButton").attr("onclick", "Housepurchase.cash()").text("提交");
            $("#exportCommonModalLabel").text("待兑现名单");
            break;
        case 5:                     //公示预览(兑现)
            $("#hczxButton").attr("onclick", "Housepurchase.publicExport(1)").text("导出");
            $("#exportCommonModalLabel").text("公示预览(兑现)");
            break;
        case 6:                     //待公示名单(不予兑现)
            $("#hczxButton").attr("onclick", "Housepurchase.publicExport(2)").text("导出");
            $("#exportCommonModalLabel").text("公示预览(不予兑现)");
            break;
    }
    $('#dataTable').bootstrapTable('destroy');
    $('#dataTable').bootstrapTable({
        url: Feng.ctxPath + "/admin/house/selectNeedCheckData?type=" + type,
        method: 'POST',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端
        showRefresh: false, // 是否显示刷新按钮
        clickToSelect: true, // 是否启用点击选中行
        singleSelect: false, // 设置True 将禁止多选
        striped: true, // 是否显示行间隔色
        pagination: true, // 设置为 true 会在表格底部显示分页条
        paginationHAlign: "left",
        paginationDetailHAlign: "right",
        sidePagination: "client", // 设置在哪里进行分页，可选值为 'client' 或者 'server'
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageSize: 10, //每页的记录行数（*）
        pageList: [10, 25, 50, 100, 500, 1000, 1500], //可供选择的每页的行数（*）
        maintainSelected: true, //全表全选需要开启
        showColumns: false,
        responseHandler: function (res) {
            $("#exportCommonModal").modal("show");
            return res.obj.rows;
        },
        columns:
                [
                    {field: "selectItem", checkbox: true},
                    {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', width: "20%"},
                    {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle', width: "30%"},
                    {title: '企业名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', width: "50%"},
                ]

    });
}

/**
 * 核查征信导出
 * @returns {undefined}
 */
Housepurchase.exportHczx = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0, ids.length - 1);
    var operation = function () {
        window.location.href = Feng.ctxPath + "/admin/house/exportHczx?ids=" + ids;
    }
    Feng.confirm("确定导出吗?", operation);
}

/**
 * 征信通过
 */
Housepurchase.hczxPass = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    ids = ids.substring(0, ids.length - 1);
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/hczxPass", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                Housepurchase.table.refresh();
                $("#exportCommonModal").modal("hide");
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("核查征信失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，确定核查征信通过吗?", operation);
}

/***
 * 显示核查征信失信
 */
Housepurchase.showHczxRejectModal = function () {
    if (this.check()) {
        if (Housepurchase.seItem.publicState != 1) {
            Feng.info("当前记录不是待核查征信状态，无法核查");
            return;
        }
        layer.open({
            type: 1,
            id: "neewFieldFormModel",
            title: '征信失信',
            area: ['800px', '450px'], //宽高
            fix: false, //不固定
            shade: 0,
            maxmin: true,
            content: '<form id="hczxRejectForm" class="form-horizontal">\n' +
                    '                    <input type="hidden" name="hczxId" id="hczxId" >\n' +
                    '                    <div class="form-group" style="margin: 10px;">\n' +
                    '                            <label class=" control-label">失信原因</label>\n' +
                    '                                <textarea id="hczxMsg" name="hczxMsg" class="form-control"></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) {
                $("#hczxId").val(Housepurchase.seItem.id);
                $("#hczxMsg").val("");
            },
            yes: function (index, layero) {
                var id = $("#hczxId").val();
                var msg = $("#hczxMsg").val();
                if (msg == null || msg == '') {
                    Feng.info("请填写失信原因");
                    return;
                }
                var operation = function () {
                    var ajax = new $ax(Feng.ctxPath + "/admin/house/hczxReject", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            Housepurchase.table.refresh();
                            layer.close(index);
                        } else {
                            Feng.error(data.msg);
                        }
                    }, function (data) {
                        Feng.error("核查征信失败!" + data.responseJSON.message + "!");
                    });
                    ajax.setData({"id": id, "outMsg": msg});
                    ajax.start();
                }
                Feng.confirm("一旦提交无法修改，确定提交吗?", operation);
            }
        });
    }
}

/**
 * 公示预览
 * @param type 1-需要兑现，2-不予兑现
 */
Housepurchase.publicExport = function (type) {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var operation = function () {
        $("#exportCommonModal").modal("hide");
        window.location.href = encodeURI(encodeURI(Feng.ctxPath + "/admin/house/exportPublic?ids=" + ids + "&type=" + type));
    }
    Feng.confirm("确定要预览吗?", operation);
}


/**
 * 公示
 * @param type 1-需要兑现，2-不予兑现
 */
Housepurchase.public = function (type) {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var isMessage = $("input[name='isSend']:checked").val();
    var typeName = $("#typeName").val();
    var address = $("#web").val();
    var publicStartTime = $("#publicStartTime").val();
    var publicEndTime = $("#publicEndTime").val();
    var dep = $("#dep").val();
    var phone = $("#fyphone").val();
    var email = $("#fyemail").val();
    if (isMessage == 1) {
        if (typeName == null || typeName == '') {
            Feng.info("请填写公示类型");
            return;
        }
        if (address == null || address == '') {
            Feng.info("请填写公示平台");
            return;
        }
        if (publicStartTime == null || publicStartTime == '') {
            Feng.info("请填写公示开始时间");
            return;
        }
        if (publicEndTime == null || publicEndTime == '') {
            Feng.info("请填写公示截止时间");
            return;
        }
        if (dep == null || dep == '') {
            Feng.info("请填写反映单位");
            return;
        }
        if (phone == null || phone == '') {
            Feng.info("请填写联系电话");
            return;
        }
        if (email == null || email == '') {
            Feng.info("请填写联系邮箱");
            return;
        }
    }

    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/publicBatch", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                Housepurchase.table.refresh();
                $("#exportCommonModal").modal("hide");
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("公示失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.set("typeName", typeName);
        ajax.set("address", address);
        ajax.set("publicStartTime", publicStartTime);
        ajax.set("publicEndTime", publicEndTime);
        ajax.set("dep", dep);
        ajax.set("phone", phone);
        ajax.set("email", email);
        ajax.set("isMessage", isMessage);
        ajax.start();
    }
    Feng.confirm("一旦公示，无法恢复，确定公示吗?", operation);
}


/**
 * 批量公示通过
 * @param type
 */
Housepurchase.publicPass = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/publicPass", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                Housepurchase.table.refresh();
                $("#exportCommonModal").modal("hide");
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("公示通过失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，确定公示通过吗?", operation);
}


/**
 * 兑现
 */
Housepurchase.cash = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (!selected || selected.length < 1) {
        Feng.info("请至少选择一行数据!");
        return;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/cash", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                Housepurchase.table.refresh();
                $("#exportCommonModal").modal("hide");
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("兑现失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.start();
    }
    Feng.confirm("一旦确认无法修改,确定要兑现吗?", operation);
}


/**
 * 部门批量提交审核
 */
Housepurchase.depSubmitBatch = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择提交审核的名单！");
        return false;
    }
    var ids = "";
    for (var key in selected) {
        ids = ids + selected[key].id + ",";
    }
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/admin/house/depSubmitBatch", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                Housepurchase.table.refresh();
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("提交审核失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.set("companyId", selected[0].companyId);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
}

/**
 * 显示导出模态框
 */
Housepurchase.showExportModal = function () {
    $("#exportForm")[0].reset();
    $("#exportModal").modal('show');
}

/**
 * 导出
 */
Housepurchase.export = function () {
    var names = '';
    var values = '';
    $("#field_info li input").each(function (index) {
        if ($(this).is(":checked")) {
            values = values + $(this).val() + ",";
            names = names + $(this).next().text() + ",";
        }
    });
    var queryData = Housepurchase.formParams();
    queryData['names'] = names;
    queryData['values'] = values;
    queryData['process'] = $("#process").val();
    $("#exportModal").modal('hide');
    var url = Feng.setUrlParam(Feng.ctxPath + "/admin/house/basicDataExport", queryData);
    window.hiddenIframe.location.href = url;
}

/**
 * 导出录入模板
 * @param type  模板类型
 */
Housepurchase.exportTemplate = function (type) {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择名单！");
        return false;
    }
    var ids = "";
    for (var key in selected) {
        ids = ids + selected[key].id + ",";
    }
    window.hiddenIframe.location.href = Feng.ctxPath + "/admin/house/exportTemplate?type=" + type + "&ids=" + ids;
}

/**
 * 导入核查结果
 * @param type
 */
Housepurchase.import = function (type) {
    $("#import-form")[0].reset();
    $('#importModal').on('show.bs.modal', function () {
        $("#type").val(type);
    });
    $("#importModal").modal("show");
}

/**
 * 导入核查结果提交
 */
Housepurchase.importSubmit = function () {
    var file = $("#file").val();
    if (Feng.isEmptyStr(file)) {
        Feng.info("请选择需要导入的文件");
        return;
    }
    $("#import-form")[0].submit();
}

/**
 * 回调
 * @param data
 */
Housepurchase.callBack = function (data) {
    Feng.info(data.msg);
}

/**
 * 是否发送短信
 */
Housepurchase.toggleMessage = function () {
    var isMessage = $("input[name='isSend']:checked").val();
    if (isMessage == 1) {
        $("#messageEdit").css("display", "block");
    } else if (isMessage == 2) {
        $("#messageEdit").css("display", "none");
    }
}


/**
 * 刷新检索
 */
Housepurchase.prepareSearch = function () {
    var name = $("#preName").val();
    var idCard = $("#preIdCard").val();
    $('#dataTable').bootstrapTable("refresh", {"query": {"name": name, "idCard": idCard}});
}

/**
 * 重置
 */
Housepurchase.prepareReset = function () {
    $("#preName").val("");
    $("#preIdCard").val("");
}


$(function () {
    var arr = [
        {"name": "marryStatus", "code": "marry_status"},
        {"name": "talentArrange", "code": "talent_arrange"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    var defaultColunms = Housepurchase.initColumn();
    var table = new BSTable(Housepurchase.id, "/admin/house/list/process/" + $("#process").val(), defaultColunms);
    table.setPaginationType("server");
    table.setOnDblClickRow(function () {
        Housepurchase.openCheckHousepurchase();
    });
    table.setRowStyle(function (row, index) {
        if (row.isConflict == 1) {
            return {classes: 'danger'}
        }
        if (row.isRecover == 1) {
            return {classes: 'info'};
        }
        return {};
    });
    Housepurchase.table = table.init();
    $('#checkAll').click(function () {
        $("#dataTable").bootstrapTable('togglePagination').bootstrapTable('checkAll').bootstrapTable('togglePagination');
    })
    $('#uncheckAll').click(function () {
        $("#dataTable").bootstrapTable('togglePagination').bootstrapTable('uncheckAll').bootstrapTable('togglePagination')
    })
});
