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

/**
 * 初始化表格的列
 */
ChannelplanFile.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '海峡申报计划ID', field: 'cpId', visible: true, align: 'center', valign: 'middle'},
            {title: '成员ID', field: 'memberTypeId', visible: true, align: 'center', valign: 'middle'},
            {title: '附件类别ID', field: 'typeId', visible: true, align: 'center', valign: 'middle'},
            {title: '附件原名', field: 'oldName', visible: true, align: 'center', valign: 'middle'},
            {title: '附件新名', field: 'url', 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'}
    ];
};

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

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

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

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

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

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