/**
 * 表格初始化
 */
var DirectlyIdentify = {
    id: "directlyIdentifyTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DirectlyIdentify.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '任务名称', field: 'task_name', visible: true, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
        {title: '任务结果', field: 'task_status', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (value == 0) {
                    return "<button type=\"button\" style=\"line-height: 1.3\" class=\"btn btn-danger btn-xs\">处理失败</button>";
                }
                if (value == 1) {
                    return "<button type=\"button\" style=\"line-height: 1.3\" class=\"btn btn-primary btn-xs\">处理成功</button>";
                }
                if (value == -1) {
                    return "<button type=\"button\" style=\"line-height: 1.3\" class=\"btn btn-warning btn-xs\">处理中</button>";
                }
            }
        },
        {title: '结果文件', field: 'task_result', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index){
                if(value != ''){
                    return "<a href='/storage/" + value+"' style=\"line-height: 1.3\">下载导入结果</a>";
                }
            }
        },
        {title: '完成时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'},
    ];
};

//模板下载
DirectlyIdentify.download_enterprise_template = function () {
    window.location.href = Feng.ctxPath + "/static/downloadFile/directly_identify_enterprise_template.xlsx";
}

DirectlyIdentify.download_fj_talent_template = function () {
    window.location.href = Feng.ctxPath + "/static/downloadFile/directly_identify_fj_talent_template.xlsx";
}

DirectlyIdentify.download_qz_talent_template = function () {
    window.location.href = Feng.ctxPath + "/static/downloadFile/directly_identify_qz_talent_template.xlsx";
}

DirectlyIdentify.enterprise_import = function () {
    $("#enterprise-import-form")[0].reset();
    $("#enterpriseImportModal").modal("show");
}

DirectlyIdentify.enterpriseImportSubmit = function () {
    $("#enterprise-import-form")[0].submit();
}

DirectlyIdentify.fj_talent_import = function () {
    $("#import_type").val("2");
    $("#talent-import-form")[0].reset();
    $("#talentImportModal").modal("show");
}

DirectlyIdentify.qz_talent_import = function () {
    $("#import_type").val("3");
    $("#talent-import-form")[0].reset();
    $("#talentImportModal").modal("show");
}

DirectlyIdentify.talentImportSubmit = function () {
    $("#talent-import-form")[0].submit();
}

//回调
DirectlyIdentify.callBack = function (data) {
    Feng.info(data.msg);
    if (data.code == 200) {
        $("#enterpriseImportModal").modal("hide");
        $("#talentImportModal").modal("hide");
        DirectlyIdentify.table.refresh();
    }
}

$(function () {

    var defaultColunms = DirectlyIdentify.initColumn();
    var table = new BSTable(DirectlyIdentify.id, "/admin/directly_identify/list", defaultColunms);
    table.setPaginationType("server");
    DirectlyIdentify.table = table.init();
    //下拉框数据动态加载
    Feng.addAjaxSelect({
        "id": "talentLevel",
        "displayCode": "code",
        "displayName": "name",
        "type": "GET",
        "url": "/admin/dict/findChildDictByCode?code=talent_arrange"
    });

});