/**
 * 人才津贴配置管理初始化
 */
var AmountStandard = {
    id: "AmountStandardTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
AmountStandard.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '人才类型', field: 'type', visible: true, align: 'center', valign: 'middle',
                formatter:function (value,row,index) {
                    if(value==1){
                        return "晋江市现代产业体系人才";
                    }
                    if(value==2){
                        return "集成电路优秀人才";
                    }
                }
            },
            {title: '津贴类别', field: 'allowanceType', visible: true, align: 'center', valign: 'middle',
                formatter:function (value,row,index) {
                    if(value==1){
                        return "人才津贴";
                    }
                    if(value==2){
                        return "交通津贴";
                    }
                    if(value==3){
                        return "购房补贴";
                    }
                }
            },
            {title: '人才层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle'},
            {title: '金额', field: 'money', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle'}
    ];
};

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

/**
 * 点击添加人才津贴配置
 */
AmountStandard.openAddAmountStandard = function () {
    var index = layer.open({
        type: 2,
        title: '添加人才津贴配置',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/amountStandard/amountStandard_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看人才津贴配置详情
 */
AmountStandard.openAmountStandardDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才津贴配置详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/amountStandard/amountStandard_update/' + AmountStandard.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除人才津贴配置
 */
AmountStandard.delete = function () {
    if (this.check()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/amountStandard/delete", function (data) {
                if(data.code==200){
                    AmountStandard.table.refresh();
                    Feng.success(data.msg);
                }else{
                    Feng.info(data.msg);
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("amountStandardId", this.seItem.id);
            ajax.start();
        };
        Feng.confirm("确定要删除吗?", operation);
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
AmountStandard.formParams = function() {
    var queryData = {};
    queryData['type'] = $("#type").val();
    queryData['allowanceType'] = $("#allowanceType").val();
    return queryData;
}

/**
 * 查询批次管理列表
 */
AmountStandard.search = function () {
    AmountStandard.table.refresh({query: AmountStandard.formParams()});
};

/**
 * 重置
 */
AmountStandard.reset = function (){
    $("#type").val("");
    $("#allowanceType").val("");
}


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