// 职级add
function addRank(){
    $('#addRankDialog').load("/follow/rankLimit/add",function(){
        $("#myModal-addRank").modal("show");
    })
};

// 职级修改
function updateRank(id){
    $('#updateRankDialog').load("/follow/rankLimit/update?id="+id,function(){
        $("#myModal-updateRank").modal("show");
    })
};


$(function(){

    tablefunction('#rankList');

    // 平台常量-列表操作列
    function operateRank(cellValue,options,rowObject){
        var paramCode = "'"+rowObject.paramCode+"'";
        var name = "'"+rowObject.paramName+"'";
        var btnstr = '';
        //if($("#updatePlatformConstant").length > 0) {//有修改权限
        btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateRank('+rowObject.id+')"></i></p>';
        //}

        return '<div class="operateIcon noHover">'+btnstr+'</div>';
    };

    //金额显示处理
    function showAmount(cellValue, options, rowObject) {
        if(cellValue !== undefined) {
            return commaDelimiter(cellValue, 'need')
        }else {
            return ''
        }

    }

    function tablefunction(tableid){
        var tipword = '',pageid = '',pageNo = 1,postData = {},url = '',colNamesArray = [],colModelArray = [];
        switch( tableid ){
            case '#rankList':tipword ='职级设置';pageid = '#rankListPage';
                url = '/follow/rankLimit/do_list';
                colNamesArray = ['ID','职级','一般跟投上限','强制跟投上限','操作'];
                colModelArray = [
                    {name: 'id', label: 'ID', hidedlg:true, hidden:true,sortable:false,title:false},
                    {name: 'rank', label: '职级', sortable:false,title:false},
                    {name: 'commonFollowAmountLimit', label: '一般跟投上限',sortable:false,align:'left',title:false,formatter:showAmount},
                    {name: 'constraintFollowAmountLimit', label: '强制跟投上限',sortable:false,width:100,align:'left',title:false,formatter:showAmount},
                    {name: 'operate', label: '操作',sortable:false,align:'center',width:60,title:false,formatter:operateRank}
                ];
                break;
        };
        sxUtil.jqGrid(tableid,{
            colNames:colNamesArray,
            colModel:colModelArray,
            height:'auto',
            mtype:'GET',
            url: url,
            pager : pageid,
            multiselect: false,
            rownumbers:false,
            postData: postData,
            page:pageNo,
            loadError:function(){
                new $.zui.Messager(tipword+'列表加载失败', {
                    type: 'warning'
                }).show();
            }
        },true);
        $(tableid).trigger('reloadGrid');
    };

    function loadData() {
        var postPara = {};

        $('#rankList').setGridParam({
            mtype:'GET',
            url : '/follow/rankLimit/do_list',
            datatype : 'json',
            postData: postPara,
            page : 1
        });
        $('#rankList').trigger('reloadGrid');
    }

    //添加职级按钮点击
    $("#addRank").click(function () {
        addRank();
    })

    //刷新
    $("#refresh").click(function () {
        loadData()
    })

})