/**
 * 优秀人才津补贴管理初始化
 */
var TalentAllowanceInfo = {
    id: "TalentAllowanceInfoTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};
/**
 * 检查是否选中
 */
TalentAllowanceInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length != 1) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        TalentAllowanceInfo.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加优秀人才津补贴
 */
TalentAllowanceInfo.openCheckTalentAllowanceInfo = function () {
    if (this.check()) {
        var index = null;
        var process = $("#process").val();
        if (process == 1) {
            index = layer.open({
                type: 2,
                title: '津补贴初级审核',
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/talentAllowanceInfo/toCheckPage/' + TalentAllowanceInfo.seItem.id + "/" + $("#process").val() + "/" + TalentAllowanceInfo.seItem.companyId,
                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;
                    obj.TalentAllowanceInfoDlg.showCheckModal();
                },
                btn2: function (index, layero) {
                    var obj = layero.find("iframe")[0].contentWindow;
                    obj.TalentAllowanceInfoDlg.submitCheck();
                    return false;
                },
                end: function () {
                    layer.closeAll('tips');
                    TalentAllowanceInfo.table.refresh();
                }
            });
        } else if (process == 2) {
            index = layer.open({
                type: 2,
                title: '津补贴走访核查',
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/talentAllowanceInfo/toCheckPage/' + TalentAllowanceInfo.seItem.id + "/" + $("#process").val() + "/null",
                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.TalentAllowanceInfoDlg.submitCheck();
                    return false;
                },
                end: function () {
                    layer.closeAll('tips');
                    TalentAllowanceInfo.table.refresh();
                }
            });
        } else if (process == 3) {
            index = layer.open({
                type: 2,
                title: '津补贴复核',
                fix: false, //不固定
                maxmin: true,
                shadeClose: false,
                content: Feng.ctxPath + '/talentAllowanceInfo/toCheckPage/' + TalentAllowanceInfo.seItem.id + "/" + $("#process").val() + "/null",
                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;
                    obj.TalentAllowanceInfoDlg.showCheckModal();
                },
                btn2: function (index, layero) {
                    var obj = layero.find("iframe")[0].contentWindow;
                    obj.TalentAllowanceInfoDlg.submitCheck();
                    return false;
                },
                end: function () {
                    layer.closeAll('tips');
                    TalentAllowanceInfo.table.refresh();
                }
            });
        }
        layer.full(index);
        TalentAllowanceInfo.layerIndex = index;
    }
};

/**
 * 查看
 */
TalentAllowanceInfo.select = function () {
    if (this.check()) {
        var process = $("#process").val();
        var url = Feng.ctxPath + '/talentAllowanceInfo/toSelectPage/' + TalentAllowanceInfo.seItem.id + "/" + $("#process").val() + "/null";
        if (process == 1) {
            url = Feng.ctxPath + '/talentAllowanceInfo/toSelectPage/' + TalentAllowanceInfo.seItem.id + "/" + $("#process").val() + "/" + TalentAllowanceInfo.seItem.companyId;
        }
        var index = layer.open({
            type: 2,
            title: '津补贴查看',
            fix: false, //不固定
            maxmin: true,
            shadeClose: false,
            content: url,
            btn: ['<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            btnAlign: 'c',
        });
        layer.full(index);
        TalentAllowanceInfo.layerIndex = index;
    }
}

TalentAllowanceInfo.showDataModal = function (type) {
    switch (type) {
        case 1:                             //批量提交审核(社保局)
            $("#exportCommonModalLabel").text("批量提交审核");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.submitBatch()").text("提交");
            break;
        case 2:                             //导出社保录入模板
            $("#exportCommonModalLabel").text("导出社保录入模板");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(1)").text("导出");
            break;
        case 3:                             //导出社保核查结果
            $("#exportCommonModalLabel").text("导出社保核查结果");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(3)").text("导出");
            break;
        case 4:                             //导出项目核查结果(初审)
            $("#exportCommonModalLabel").text("导出项目核查结果");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(5)").text("导出");
            break;
        case 5:                             //批量提交审核(走访核查)
            $("#exportCommonModalLabel").text("批量提交审核");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.submitBatchVisit()").text("提交");
            break;
        case 6:                             //导出项目录入模板(走访核查)
            $("#exportCommonModalLabel").text("导出项目录入模板");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(2)").text("导出");
            break;
        case 7:                             //导出项目核查结果(走访核查)
            $("#exportCommonModalLabel").text("导出项目核查结果");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(4)").text("导出");
            break;
        case 8:                             //导出项目核查结果(复核)
            $("#exportCommonModalLabel").text("导出项目核查结果");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(5)").text("导出");
            break;
        case 9:                             //导出项目核查结果(预备库)
            $("#exportCommonModalLabel").text("导出项目核查结果");
            $("#exportButton").attr("onclick", "TalentAllowanceInfo.export(5)").text("导出");
            break;
    }
    $('#dataTable').bootstrapTable('destroy');
    $('#dataTable').bootstrapTable({
        url: Feng.ctxPath + "/talentAllowanceInfo/selectNeedData?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: 'year', visible: true, align: 'center', valign: 'middle', width: "10%"},
                {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', width: "10%"},
                {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle', width: "30%"},
                {
                    title: '企业名称',
                    field: 'enterpriseName',
                    visible: true,
                    align: 'center',
                    valign: 'middle',
                    width: "35%"
                },
                {
                    title: '审核状态',
                    field: 'checkState',
                    visible: true,
                    align: 'center',
                    valign: 'middle',
                    'class': 'uitd_showTip',
                    width: "15%",
                    formatter(value, row, index) {
                        switch (type) {
                            case 1:                             //批量提交审核(社保局)
                            case 2:                             //导出社保录入模板
                            case 3:                             //导出社保核查结果
                                if (value == -2) {
                                    return "<span class='label'>待提交</span>";
                                } else if (value == -1) {
                                    return "<span class='label label-warning-light'>审核不通过</span>";
                                } else if (value == 1) {
                                    return "<span class='label label-success'>待审核</span>";
                                } else if (value == 2) {
                                    return "<span class='label label-danger'>已驳回</span>";
                                } else if (value == 3) {
                                    return "<span class='label label-primary'>已通过</span>"
                                } else if (value == 4) {
                                    return "<span class='label label-success'>上级驳回</span>";
                                } else if (value == 9) {
                                    return "<span class='label label-success'>重新提交</span>";
                                }
                                break;
                            case 4:                             //导出项目核查结果(初审)
                                if (value == -1) {
                                    return "<span class='label label-warning-light'>审核不通过</span>";
                                } else if (value == 1) {
                                    return "<span class='label'>待提交</span>"
                                } else if (value == 5) {
                                    return (Feng.isNotEmptyStr(row.highProcess) && row.highProcess > 1) ? "<span class='label label-success'>重新提交</span>" : "<span class='label label-success'>待审核</span>";
                                } else if (value == 13) {
                                    return "<span class='label label-success'>上级驳回</span>";
                                } else if (value == 10) {
                                    return "<span class='label label-danger'>已驳回</span>";
                                } else if (value == 15 || value == 20 || value == 25 || value == 30) {
                                    return "<span class='label label-primary'>已通过</span>";
                                }
                                break;
                            case 5:                             //批量提交审核(走访核查)
                            case 6:                             //导出项目录入模板(走访核查)
                            case 7:                             //导出项目核查结果(走访核查)
                                if (value == -1) {
                                    return "<span class='label label-warning-light'>审核不通过</span>";
                                } else if (value == 1 || value == 5 || value == 10) {
                                    return "<span class='label label-danger'>已驳回</span>";
                                } else if (value == 15) {
                                    return (Feng.isNotEmptyStr(row.highProcess) && row.highProcess >= 2) ? "<span class='label label-success'>重新提交</span>" : "<span class='label label-success'>待审核</span>";
                                } else if (value == 20 || value == 30) {
                                    return "<span class='label label-primary'>已通过</span>"
                                } else if (value == 25) {
                                    return "<span class='label label-success'>上级驳回</span>";
                                }
                                break;
                            case 8:                             //导出项目核查结果(复核)
                                if (value == -1) {
                                    return "<span class='label label-warning-light'>审核不通过</span>";
                                } else if (value == 1 || value == 5 || value == 10 || value == 13 || value == 15 || value == 25) {
                                    return "<span class='label label-danger'>已驳回</span>";
                                } else if (value == 20) {
                                    return (Feng.isNotEmptyStr(row.highProcess) && row.highProcess >= 3) ? "<span class='label label-success'>重新提交</span>" : "<span class='label label-success'>待审核</span>";
                                } else if (value == 30) {
                                    return "<span class='label label-primary'>已通过</span>"
                                } else if (value == 35) {
                                    return "<span class='label label-success'>公示驳回</span>";
                                }
                                break;
                            case 9:                             //导出项目核查结果(预备库)
                                if (value == -1) {
                                    return "<span class='label label-warning-light'>审核不通过</span>";
                                }
                                if (value == 30) {
                                    return "<span class='label label-primary'>已通过</span>"
                                }
                                break;
                        }
                    }
                },
            ]

    });
}

/**
 * 刷新检索
 */
TalentAllowanceInfo.commonSearch = function () {
    var name = $("#commonName").val();
    var idCard = $("#commonIdCard").val();
    var year = $("#commonYear").val();
    $('#dataTable').bootstrapTable("refresh", {"query": {"name": name, "idCard": idCard,"year":year}});
}

/**
 * 重置
 */
TalentAllowanceInfo.commonReset = function () {
    $("#commonName").val("");
    $("#commonIdCard").val("");
}


/**
 * 社保局批量提交审核
 */
TalentAllowanceInfo.submitBatch = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择需要提交审核的数据！");
        return false;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/submitCheckBatch", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                TalentAllowanceInfo.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);
}

/**
 * 走访核查批量提交审核
 */
TalentAllowanceInfo.submitBatchVisit = function () {
    var selected = $('#dataTable').bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择需要提交审核的数据！");
        return false;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    var operation = function () {
        var i = layer.msg('提交中，请稍后！', {
            icon: 16
            , shade: 0.3
        });
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/submitBatchVisit", function (data) {
            layer.close(i);
            if (data.code == 200) {
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
                $("#exportCommonModal").modal("hide");
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            layer.close(i);
            Feng.error("提交审核失败!" + data.responseJSON.message + "!");
        });
        ajax.set("ids", ids);
        ajax.start();
    }
    Feng.confirm("一旦提交无法修改，是否审核完毕且无误?", operation);
}

TalentAllowanceInfo.updateFieldsAndFiles = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/findFieldsAndFiles?id=" + TalentAllowanceInfo.seItem.id, function (data) {
            var obj = data.obj.obj;
            if (data.code == 200) {
                layer.open({
                    type: 1,
                    id: "neewFieldFormModel",
                    title: '修改',
                    area: ['800px', '450px'], //宽高
                    fix: false, //不固定
                    shade: 0,
                    maxmin: true,
                    content: '<form id="checkForm">\n' +
                        '                    <div class="form-group" id="field" style="margin: 10px">\n' +
                        '                        <label for="field_concat" class="control-label">可修改合同时间</label>\n' +
                        '                        <div id="field_concat">\n' +
                        '                        </div>\n' +
                        '                        <label for="field_project" class="control-label">可修改字段</label>\n' +
                        '                        <div id="field_field">\n' +
                        '                           <ul><li style="width: 100%"><input type="checkbox" value="wage"><span>上一年度年薪(元)</span></li></ul>'+
                        '                        </div>\n'+
                        '                        <label for="field_project" class="control-label">可修改项目</label>\n' +
                        '                        <div id="field_project">\n' +
                        '                        </div>\n' +
                        '                        <label for="field_file" 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="TalentAllowanceInfoSupple.checkAll(\'field\')">全选</button>\n' +
                        '                            <button type="button" class="btn btn-success" onclick="TalentAllowanceInfoSupple.unCheckAll(\'field\')">反选</button>\n' +
                        '                        </div>\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) {
                        var projectList = data.obj.projects;
                        var fileList = data.obj.files;
                        var concatList = data.obj.concats;
                        var files = data.obj.info.files;
                        var projects = data.obj.info.projects;
                        var concats = data.obj.info.concats;
                        var fields = data.obj.fields;
                        //初始化附件、核查项目、合同
                        if (projectList != null && projectList.length != 0) {
                            var html = '<ul>';
                            for (var key in projectList) {
                                html = html + '<li style="width: 100%"><input type="checkbox" class="icheckbox" value="' + projectList[key].id + '"><span>' + projectList[key].projectName + '</span></li>';
                            }
                            html = html + "</ul>";
                            $("#field_project").empty().append(html);
                        }
                        if (fileList != null && fileList.length != 0) {
                            var html = '';
                            for (var key in fileList) {
                                html = html + '<ul><li style="width: 100%"><input type="checkbox" class="icheckbox" value="' + fileList[key].id + '"><span>' + fileList[key].name + '</span></li></ul>';
                            }
                            $("#field_file").empty().append(html);
                        }
                        if (concatList != null && concatList.length != 0) {
                            var html = '';
                            for (var key in concatList) {
                                html = html + '<ul><li style="width: 100%"><input type="checkbox" class="icheckbox" value="' + concatList[key].id + '"><span>' + concatList[key].enterpriseName + '</span></li></ul>';
                            }
                            $("#field_concat").empty().append(html);
                        }
                        TalentAllowanceInfoSupple.initICheck();
                        if (Feng.isNotEmptyStr(projects)) {
                            $("#field_project input").each(function () {
                                if (projects.indexOf($(this).val()) != -1) {
                                    $(this).iCheck("check");
                                }
                            });
                        }
                        if (files != null && files != '') {
                            $("#field_file input").each(function () {
                                if (files.indexOf($(this).val()) != -1) {
                                    $(this).iCheck("check");
                                }
                            });
                        }
                        if (concats != null && concats != '') {
                            $("#field_concat input").each(function () {
                                if (concats.indexOf($(this).val()) != -1) {
                                    $(this).iCheck("check");
                                }
                            });
                        }
                        if(Feng.isNotEmptyStr(fields) && fields == "wage"){
                            $("#field_field ul input[value='wage']").iCheck("check");
                        }
                    },
                    yes: function (index, layero) {
                        var projects = '', files = '', concats = '' ,fields = '';
                        $("#field_project li input").each(function (index) {
                            if ($(this).is(":checked")) {
                                projects = projects + $(this).val() + ",";
                            }
                        });
                        $("#field_file li input").each(function (index) {
                            if ($(this).is(":checked")) {
                                files = files + $(this).val() + ",";
                            }
                        });
                        $("#field_concat li input").each(function (index) {
                            if ($(this).is(":checked")) {
                                concats = concats + $(this).val() + ",";
                            }
                        });
                        $("#field_field li input").each(function(index){
                            if($(this).is(":checked")){
                                fields = fields + $(this).val() + ",";
                            }
                        });
                        fields  = fields.substring(0,fields.length-1);
                        if (Feng.isEmptyStr(projects) && Feng.isEmptyStr(files) && Feng.isEmptyStr(concats) && Feng.isEmptyStr(fields)) {
                            Feng.info("请选择可修改的字段、附件或合同！");
                            return;
                        }
                        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/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": TalentAllowanceInfo.seItem.id,
                            "projects": projects,
                            "files": files,
                            "concats": concats,
                            "fields" : fields
                        })
                        ajax.start();
                    }
                });
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("查询失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
}

/**
 * 撤销审核
 */
TalentAllowanceInfo.firstCancleCheck = 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="cancleMsg" 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 = $("#cancleMsg").val();
                if (Feng.isEmptyStr(cancleMsg)) {
                    Feng.error("撤销原因不能为空");
                    return;
                }
                var operation = function () {
                    var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/cancleFirstCheck", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            TalentAllowanceInfo.table.refresh();
                            layer.close(index);
                        } else {
                            Feng.error(data.msg);
                        }
                        locked = false;
                    }, function (data) {
                        Feng.error("撤销审核失败!" + data.responseJSON.message + "!");
                        locked = false;
                    });
                    ajax.setData({
                        "id": TalentAllowanceInfo.seItem.id,
                        "companyId": TalentAllowanceInfo.seItem.companyId,
                        "checkMsg": cancleMsg
                    })
                    ajax.start();
                };
                Feng.confirm("一旦提交无法修改，确定要撤销吗?", operation);
            }
        });
    }
}

/**
 * 撤销复核
 */
TalentAllowanceInfo.reviewCancleCheck = 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="cancleMsg" 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 = $("#cancleMsg").val();
                if (Feng.isEmptyStr(cancleMsg)) {
                    Feng.error("撤销原因不能为空");
                    return;
                }
                var operation = function () {
                    var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/reviewCancleCheck", function (data) {
                        if (data.code == 200) {
                            Feng.success(data.msg);
                            TalentAllowanceInfo.table.refresh();
                            layer.close(index);
                        } else {
                            Feng.error(data.msg);
                        }
                        locked = false;
                    }, function (data) {
                        Feng.error("撤销复核失败!" + data.responseJSON.message + "!");
                        locked = false;
                    });
                    ajax.setData({"id": TalentAllowanceInfo.seItem.id, "checkMsg": cancleMsg})
                    ajax.start();
                };
                Feng.confirm("一旦提交无法修改，确定要撤销吗?", operation);
            }
        });
    }
}

TalentAllowanceInfo.repair = function (){
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/talentAllowanceInfo/repairTalentType", function (data) {
            if (data.code == 200) {
                Feng.success(data.msg);
                TalentAllowanceInfo.table.refresh();
            } else {
                Feng.error(data.msg);
            }
        }, function (data) {
            Feng.error("修复失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    };
    Feng.confirm("一旦修复无法修改，确定要修复吗?", operation);
}


/**
 * 导出基础信息
 */
TalentAllowanceInfo.exportBasicInfo = function () {
    var process = $("#process").val();
    var queryData = TalentAllowanceInfo.formParams();
    queryData['process'] = process;
    var url = Feng.setUrlParam(Feng.ctxPath + "/talentAllowanceInfoExport/exportBasicInfo", queryData);
    window.hiddenIframe.location.href = url;
}

/**
 * 导出项目数据
 */
TalentAllowanceInfo.exportProjectData = function () {
    var selected = $("#dataTable").bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择需要导出的数据！");
        return false;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExport/exportProjectData?ids=" + ids + "&process=" + $("#process").val();
}

/**
 * 导出
 */
TalentAllowanceInfo.export = function (type) {
    var selected = $("#dataTable").bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选择需要导出的数据！");
        return false;
    }
    var ids = "";
    for (var i = 0; i < selected.length; i++) {
        ids = ids + selected[i].id + ",";
    }
    switch (type) {
        case 1:         //导出社保录入模板
            var operation = function () {
                window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExportProject/exportProject?type=1&projectType=1&ids=" + ids + "&process=" + $("#process").val();
            }
            Feng.confirm("请确认所选数据为未录入社保的数据，确认导出吗?", operation);
            break;
        case 2:         //导出项目录入模板(走访核查)
            var operation = function () {
                window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExportProject/exportProject?type=1&projectType=2&ids=" + ids + "&process=" + $("#process").val();
            }
            Feng.confirm("请确认所选数据为未录入走访核查项目的数据，确认导出吗?", operation);
            break;
        case 3:         //导出社保核查结果
            var operation = function () {
                window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExportProject/exportProject?type=2&projectType=1&ids=" + ids + "&process=" + $("#process").val();
            }
            Feng.confirm("确认导出吗?", operation);
            break;
        case 4:         //导出项目核查结果(走访核查)
            var operation = function () {
                window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExportProject/exportProject?type=2&projectType=2&ids=" + ids + "&process=" + $("#process").val();
            }
            Feng.confirm("确认导出吗?", operation);
            break;
        case 5:         //导出项目核查结果(所有)
            var operation = function () {
                window.hiddenIframe.location.href = Feng.ctxPath + "/talentAllowanceInfoExportProject/exportProject?type=2&projectType=3&ids=" + ids + "&process=" + $("#process").val();
            }
            Feng.confirm("确认导出吗?", operation);
            break;
    }
}

/**
 * 显示导入模态框
 */
TalentAllowanceInfo.showImportModal = function (type) {
    if (type == 1) {
        $("#importModalLabel").html("社保核查情况导入");
    } else if (type == 2) {
        $("#importModalLabel").html("走访核查情况导入");
    }
    $("#file,#fileName").val("");
    $("#importModal").modal("show");
}

/**
 * 导入附件提交
 */
TalentAllowanceInfo.importSubmit = function () {
    var operation = function () {
        $("#import-form")[0].submit();
    }
    Feng.confirm("导入前请确认仔细确认所选文件，一旦导入无法修改，确认导入吗?", operation);
}

/**
 * 回调
 */
TalentAllowanceInfo.callBack = function (data) {
    if (data.code == 200) {
        $("#importModal").modal("hide");
        Feng.success(data.msg);
    } else {
        Feng.error(data.msg);
    }
}
/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
TalentAllowanceInfo.formParams = function () {
    var queryData = {};
    queryData['year'] = $("#year").val();
    queryData['enterpriseName'] = $("#enterpriseName").val();
    queryData['name'] = $("#name").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['talentType'] = $("#talentType").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['address'] = $("#address").val();
    queryData['identifyCondition'] = $("#identifyCondition").val();
    queryData['isSupple'] = $("#isSupple").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['isPublicCheck'] = $("#isPublicCheck").val();
    queryData['publicState'] = $("#publicState").val();
    queryData['recommendAllowanceType'] = $("#recommendAllowanceType").val();
    queryData['companyName'] = $("#companyName").val();
    queryData['introductionMode'] = $("#introductionMode").val();
    queryData['firstJJStartTime'] = $("#firstJJStartTime").val();
    queryData['firstJJEndTime'] = $("#firstJJEndTime").val();
    return queryData;
}
/**
 * 查询人才认定申报列表
 */
TalentAllowanceInfo.search = function () {
    TalentAllowanceInfo.table.refresh({
        query: TalentAllowanceInfo.formParams()
    });
};
/**
 * 重置
 */
TalentAllowanceInfo.reset = function () {
    $("#year").val("");
    $("#enterpriseName").val("");
    $("#name").val("");
    $("#idCard").val("");
    $("#talentType").val("");
    $("#talentArrange").val("");
    $("#address").val("");
    $("#identifyCondition").val("");
    $("#isSupple").val("");
    $("#checkState").val("");
    $("#isPublicCheck").val("");
    $("#publicState").val("");
    $("#recommendAllowanceType").val("");
    $("#companyName").val("");
    $("#introductionMode").val("");
    $("#firstJJStartTime").val("");
    $("#firstJJEndTime").val("");
}
/**
 * 获取人才认定
 */
TalentAllowanceInfo.getIdentifyCondition = function () {
    var level = $("#talentArrange").val();
    if (level == null || level == '') {
        $("#identifyCondition").empty();
        $("#identifyCondition").trigger('chosen:updated');
        return;
    }
    Feng.addAjaxSelect({
        "id": "identifyCondition",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/api/common/findIdentifyConditionByLevel?talentLevel=" + level + "&type=1"
    });
    $("#identifyCondition").trigger('chosen:updated');
}


$(function () {
    var process = $("#process").val();
    var defaultColunms = TalentAllowanceInfoSupple.initColumn(process);
    var table = new BSTable(TalentAllowanceInfo.id, "/talentAllowanceInfo/list/" + process, defaultColunms);
    table.setPaginationType("server");
    table.setOnDblClickRow(function () {
        TalentAllowanceInfo.openCheckTalentAllowanceInfo();
    });
    table.setSingleSelect(false);
    // table.setHeaderStyle(function headerStyle(column) {
    //     return {
    //         name: {
    //             css: {background: 'yellow'}
    //         }
    //     }[column.field]
    // });
    TalentAllowanceInfo.table = table.init();
    //批量加载字典表数据
    var arr = [{
        "name": "address",
        "code": "un_street"
    }, {
        "name": "talentArrange",
        "code": "un_talentLevel"
    }, {
        "name": "nationality",
        "code": "un_nationality"
    }, {
        "name": "talentType",
        "code": "un_jbt_talentType"
    }, {"name": "introductionMode", "code": "un_introduction_mode"}];
    Feng.findChildDictBatch(JSON.stringify(arr));
    $("#identifyCondition").on('chosen:ready', function (e, params) {
        $(".chosen-container-single .chosen-single").css("padding", "4px 0px 0px 4px");
    });
    $("#identifyCondition").chosen({
        search_contains: true,
        //关键字模糊搜索。设置为true，只要选项包含搜索词就会显示；设置为false，则要求从选项开头开始匹配
        disable_search: false,
        width: "100%",
        enable_split_word_search: true
    });
    $('#checkAll').click(function () {
        $("#dataTable").bootstrapTable('togglePagination').bootstrapTable('checkAll').bootstrapTable('togglePagination');
    })
    $('#uncheckAll').click(function () {
        $("#dataTable").bootstrapTable('togglePagination').bootstrapTable('uncheckAll').bootstrapTable('togglePagination')
    })
    $('#checkAllPrepare').click(function () {
        $("#prepareTable").bootstrapTable('togglePagination').bootstrapTable('checkAll').bootstrapTable('togglePagination');
    })
    $('#uncheckAllPrepare').click(function () {
        $("#prepareTable").bootstrapTable('togglePagination').bootstrapTable('uncheckAll').bootstrapTable('togglePagination')
    })
    $(".time").each(function(){
        laydate.render({
            elem: "#"+$(this).attr("id")
            ,type: "date"
            ,trigger: 'click'
        });
    });
});
