/**
 * 认定条件管理管理初始化
 */
var IntegralItemMgr = {
    id: "IntegralItemMgrTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};
/**
 * 初始化表格的列
 */
IntegralItemMgr.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: 'name', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip'},
        {title: '所属项目', field: 'projectName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip'},
        {title: '项目类别', field: 'projectType', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                switch (value) {
                    case 1:
                        return "基础分";
                    case 2:
                        return "贡献分";
                    case 3:
                        return "资历分";
                }
            }
        },
        {title: '首次积分规则', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip',
            formatter: function (value, row, index) {
                return "首次达成" + row.fstNeedAmount + row.unit + "可获得" + row.fstGainPoints + "积分";
            }
        },
        {title: '增量积分规则', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip',
            formatter: function (value, row, index) {
                if (row.stepNeedAmount > 0) {
                    return "每新增" + row.stepNeedAmount + row.unit + "可获得" + row.stepGainPoints + "积分";
                } else {
                    return "未设置";
                }
            }
        },
        {title: '上限设置', field: 'limit', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                switch (value) {
                    case 1:
                        var limitStr = "上限" + row.max;
                        switch (row.yearly) {
                            case 1:
                                limitStr += "(年度重置)";
                                break;
                            case 2:
                                limitStr += "(不重置)";
                                break;
                        }
                        return "";
                    default:
                        return "";
                }
            }
        },
        {title: '是否启用', field: 'active', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "";
                }
                if (value == 2) {
                    return "";
                }
            }
        }
    ];
};
/**
 * 检查是否选中
 */
IntegralItemMgr.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录!");
        return false;
    } else {
        IntegralItemMgr.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加积分项目
 */
IntegralItemMgr.openAddIntegralItem = function () {
    var index = layer.open({
        type: 2,
        title: '添加积分标准',
        area: ['1126px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/admin/integral_mgr/addItem'
    });
    this.layerIndex = index;
};
/**
 * 打开编辑积分项目
 */
IntegralItemMgr.openEditIntegralItem = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑积分标准',
            area: ['1126px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/integral_mgr/editItem/id/' + IntegralItemMgr.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 删除积分项目
 */
IntegralItemMgr.delete = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/admin/integral_mgr/deleteItem/id/", function (data) {
                Feng.success("删除成功!");
                IntegralItemMgr.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", IntegralItemMgr.seItem.id);
            ajax.start();
        }
        Feng.confirm("是否刪除该积分标准?", operation);
    }
};
/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
IntegralItemMgr.formParams = function () {
    var queryData = {};
    queryData['type'] = $("#type").val();
    queryData['name'] = $("#name").val();
    queryData['projectType'] = $("#projectType").val();
    queryData['active'] = $("#active").val();
    return queryData;
}
/**
 * 查询认定条件管理列表
 */
IntegralItemMgr.search = function () {
    IntegralItemMgr.table.refresh({query: IntegralItemMgr.formParams()});
};
/**
 * 重置
 */
IntegralItemMgr.reset = function () {
    $("#type").val("");
    $("#name").val("");
    $("#projectType").val("");
    $("#active").val("");
}
//回调
IntegralItemMgr.callBack = function (data) {
    Feng.info(data.msg);
    if (data.code == 200) {
        $("#importModal").modal("hide");
        IntegralItemMgr.table.refresh();
    }
}
$(function () {
    var defaultColunms = IntegralItemMgr.initColumn();
    var table = new BSTable(IntegralItemMgr.id, "/admin/integral_mgr/itemList", defaultColunms);
    table.setPaginationType("server");
    IntegralItemMgr.table = table.init();
});