/**
 * 评分标准管理初始化
 */
var ChannelplanScoreStandard = {
    id: "ChannelplanScoreStandardTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ChannelplanScoreStandard.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '唯一标志', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '父id', field: 'parentId', visible: true, align: 'center', valign: 'middle'},
            {title: '评分步骤', field: 'step', visible: true, align: 'center', valign: 'middle',
                formatter: function (value, row, index) {
                    if (value == null || value == '') {
                        return "";
                    } else if (value == 2) {
                        return "函审";
                    } else if (value == 3) {
                        return "现场评审";
                    }
                }
            },
            {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '分值', field: 'score', visible: true, align: 'center', valign: 'middle'},
            {title: '排序', field: 'sn', visible: true, align: 'center', valign: 'middle'},
            {title: '分值说明', field: 'description', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: false, align: 'center', valign: 'middle'},
            {title: '创建用户', field: 'createUser', visible: false, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'updateTime', visible: false, align: 'center', valign: 'middle'},
            {title: '更新用户', field: 'updateUser', visible: false, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加评分标准
 */
ChannelplanScoreStandard.openAddChannelplanScoreStandard = function () {
    var index = layer.open({
        type: 2,
        title: '添加评分标准',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanScoreStandard/channelplanScoreStandard_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看评分标准详情
 */
ChannelplanScoreStandard.openChannelplanScoreStandardDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '评分标准详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/channelplanScoreStandard/channelplanScoreStandard_update/' + ChannelplanScoreStandard.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除评分标准
 */
ChannelplanScoreStandard.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/channelplanScoreStandard/delete", function (data) {
            Feng.success("删除成功!");
            ChannelplanScoreStandard.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("channelplanScoreStandardId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询评分标准列表
 */
ChannelplanScoreStandard.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['step'] = $("#step").val();
    ChannelplanScoreStandard.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ChannelplanScoreStandard.initColumn();
    var table = new BSTable(ChannelplanScoreStandard.id, "/channelplanScoreStandard/list", defaultColunms);
    table.setPaginationType("server");
    ChannelplanScoreStandard.table = table.init();
});
