/**
 * ${context.bizChName}管理初始化
 */
var ${context.bizEnBigName} = {
    id: "${context.bizEnBigName}Table",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
${context.bizEnBigName}.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加${context.bizChName}
 */
${context.bizEnBigName}.openAdd${context.bizEnBigName} = function () {
    var index = layer.open({
        type: 2,
        title: '添加${context.bizChName}',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/${context.bizEnName}/${context.bizEnName}_add'
    });
    this.layerIndex = index;
};

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

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

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

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