/**
 * scoreManage管理初始化
 */
var Score = {
    id: "ScoreTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Score.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '唯一标志', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '父级Id', field: 'parentId', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'sname', visible: true, align: 'center', valign: 'middle'},
            {title: '评审阶段(1-函审，2-现场评审）', field: 'stage', visible: true, align: 'center', valign: 'middle'},
            {title: '分值（父级分值=子类分值总和）', field: 'score', visible: true, align: 'center', valign: 'middle'},
            {title: '层级', field: 'level', visible: true, align: 'center', valign: 'middle'},
            {title: '排序', field: 'sort', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建用户', field: 'createUser', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'},
            {title: '创建用户', field: 'updateUser', visible: true, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加scoreManage
 */
Score.openAddScore = function () {
    var index = layer.open({
        type: 2,
        title: '添加scoreManage',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/score/score_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看scoreManage详情
 */
Score.openScoreDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'scoreManage详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/score/score_update/' + Score.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除scoreManage
 */
Score.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/score/delete", function (data) {
            Feng.success("删除成功!");
            Score.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("scoreId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询scoreManage列表
 */
Score.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Score.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Score.initColumn();
    var table = new BSTable(Score.id, "/score/list", defaultColunms);
    table.setPaginationType("client");
    Score.table = table.init();
});
