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

/**
 * 初始化表格的列
 */
DataCheck.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'},
    ];
};

//模板下载
DataCheck.download_wuxian_template = function () {
    window.location.href = Feng.ctxPath + "/static/downloadFile/data_check_wuxian_template.xlsx";
}

DataCheck.download_yibao_template = function () {
    window.location.href = Feng.ctxPath + "/static/downloadFile/data_check_yibao_template.xlsx";
}

DataCheck.import_wuxian = function () {
    $("#wuxian-import-form")[0].reset();
    $("#wuxianImportModal").modal("show");
}

DataCheck.wuxianImportSubmit = function () {
    $("#wuxian-import-form")[0].submit();
}


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


$(function () {

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

    //批量加载时间控件
    $(".date").each(function () {
        laydate.render({
            elem: this
            , type: 'year'
            , trigger: 'click'
        });
    });

});