index.js 12.4 KB
Newer Older
txy committed
1

txy committed
2 3 4 5 6 7 8
// 加载html结构
loadHtmlJson();

var gb_player_loaded = false
var gb_rank_loaded = false

$(function(){
txy committed
9
    setToken();
txy committed
10 11
    // 获取活动标题
    getActivityTitle();
txy committed
12 13
    btnBindClick();// 绑定点击事件
    removeAttr();
txy committed
14 15 16 17 18 19 20 21 22 23
    
    // 切换到排行榜
    if(getQueryString("toRanger") === '1') {
      $("#act3152823482970").click();
    }else {
      // 切换到参赛选手
      $("#act31528123692525").click();
    }
    
    // 排行榜列表
txy committed
24
    voteDialogBindFn();
txy committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
});

// 元素点击事件绑定
function btnBindClick() {
    // 参数选手
    $("#act31528123692525").off("click").on("click",tabChange);
    // 排行榜
    $("#act3152823482970").off("click").on("click",tabChange);
    // 搜索按钮
    $("#act3152814816164").off("click").on('click',function(){
        getAjaxListSearch('search',1,function(playerListData){
            getPlayerList(playerListData)
        })
    });

    // 参赛选手上一页
    $('#act3152978551035').off('click').on('click',function(){
txy committed
42
        
txy committed
43 44 45 46 47 48
        var page = parseInt($('#act61214527684747 .curpage').text())
        if(page > 1) {
            page -= 1
            getAjaxListSearch('player',page,function(playerListData){
                getPlayerList(playerListData)
            })  // 参赛选手列表
txy committed
49 50
        }else {
            $.dialog({
txy committed
51
                type:'tips',
txy committed
52 53
                infoText : '当前是第一页',
                autoClose: 2000
txy committed
54
            });
txy committed
55
        }
txy committed
56
    });
txy committed
57 58
    // 参赛选手下一页
    $('#act315291899997').off('click').on('click',function(){
txy committed
59 60 61 62
        var pageSize = parseInt($("#act61214527684747").attr("c_pagesize"));
        var page = parseInt($('#act61214527684747 .curpage').text());
        var total = parseInt($('#act61214527684747 .totalpage').text());
        if(page < Math.ceil(total/pageSize)) {
txy committed
63 64 65
            page = page + 1
            getAjaxListSearch('player',page,function(playerListData){
                getPlayerList(playerListData)
txy committed
66 67 68
            });  // 参赛选手列表
        }else {
            $.dialog({
txy committed
69
                type:'tips',
txy committed
70 71
                infoText : '当前是最后一页',
                autoClose: 2000
txy committed
72
            });
txy committed
73
        }
txy committed
74
    });
txy committed
75 76 77 78 79 80 81 82 83

    // 排行榜上一页
    $('#act514245671026').off('click').on('click',function(){
        var page = parseInt($('#act111398324601 .curpage').text())
        if(page > 1) {
            page -= 1
            getAjaxListSearch('rank',page,function(rankListData){
                getRangeList(rankListData)
            })  // 参赛选手列表
txy committed
84 85
        }else {
            $.dialog({
txy committed
86
                type:'tips',
txy committed
87 88
                infoText : '当前是第一页',
                autoClose: 2000
txy committed
89
            });
txy committed
90 91 92 93
        }
    })
    // 排行榜下一页
    $('#act5142157597939').off('click').on('click',function(){
txy committed
94
        var pageSize = parseInt($("#act111398324601").attr("c_pagesize"));
txy committed
95 96
        var page = parseInt($('#act111398324601 .curpage').text())
        var total = parseInt($('#act111398324601 .totalpage').text())
txy committed
97
        if(page < Math.ceil(total/pageSize)) {
txy committed
98 99 100 101
            page = page + 1
            getAjaxListSearch('rank',page,function(rankListData){
                getRangeList(rankListData)
            })  // 参赛选手列表
txy committed
102 103
        }else {
            $.dialog({
txy committed
104
                type:'tips',
txy committed
105 106
                infoText : '当前是最后一页',
                autoClose: 2000
txy committed
107
            });
txy committed
108 109 110 111 112
        }
    })

    // 报名按钮
    $("#act31527459124456").off("click").on("click",function(){
txy committed
113 114 115 116 117
        // 判断关注
        isAttention(function(){
            // 是否报名
            isSignUp();
        });
txy committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131
    });

    // 查看排行
    $('#act5161526928645').off('click').on('click',function(){
        $('#html-template-5').fadeOut();
        $("#user-list").hide();
        $("#range-list").show();  
    })
    $('#html-template-5 .modal-close').off("click").on('click',function(){
        $('#html-template-5').fadeOut()
    })

    // 排行榜
    $("#act2165045664554").off('click').on("click", function(){
txy committed
132 133 134
        var _t = getToken();
        var _addParam = 'toRanger=1'
        transPage('1',activityCode,_t,_addParam);
txy committed
135 136 137 138
    });

    // 选手主页    
    $("#act21650126678793").off("click").on("click", function(){
txy committed
139 140 141 142 143 144

        // 判断关注
        isAttention(function(){
            // 判断是否报名
            isSignUp(function(){
                var _t = getToken();
txy committed
145
                var urlParam = 'userId='+user.id;
txy committed
146
                transPage('3',activityCode,_t,urlParam);
txy committed
147 148 149 150 151 152 153 154
            },function(){
                $.dialog({
                    contentHtml: '<p style="text-align:center;">您还未报名,请到首页报名参加后本次活动!</p>',
                    onClosed: function(){
                        var _t = getToken();
                        transPage('1',activityCode,_t);
                    }
                });
txy committed
155 156
            });
        });
txy committed
157 158 159 160
    });

    // 活动秘籍
    $("#act21650195017743").off("click").on("click", function(){
txy committed
161 162 163
        $('#html-template-8').fadeIn('normal', function() {
            $(document).scrollTop(0);
        });
txy committed
164 165 166 167 168 169 170 171
    });
}

// 检索参数选手列表
function getAjaxListSearch(type,page,callback) {
    if(type == 'player') {
        var descs = 'createTime'
        var searchVal = ''
胡畅 committed
172
        var pageSize = $('#act41530417882468').text()
胡畅 committed
173
        if(gb_player_loaded) {
txy committed
174 175
            return
        }
胡畅 committed
176 177
        gb_player_loaded = true
    }else if(type == 'rank') {
txy committed
178 179
        var descs = 'voteNum'
        var searchVal = ''
胡畅 committed
180
        var pageSize = $('#act4153123735791').text()
胡畅 committed
181
        if(gb_rank_loaded) {
txy committed
182 183
            return
        }
胡畅 committed
184 185
        gb_rank_loaded = true
    }else if(type == 'search') {
txy committed
186 187
        var searchVal = $('.search-input.c-read-only').val()
        var descs = 'createTime'
txy committed
188 189 190 191 192 193 194 195
        // if(searchVal == '') {
        //     $.dialog({
        //         type : 'tips',
        //         autoClose : 3000,
        //         infoText : '搜索关键词不能为空'
        //     });
        //     return false
        // }
胡畅 committed
196 197 198 199
        if(gb_player_loaded) {
            return
        }
        gb_player_loaded = true
txy committed
200 201 202 203 204
    }
    var params = {
        reviewStatus:1,  // 审核状态
        descs:descs,  // 降序排列
        curPage:page?page:1,
胡畅 committed
205
        pageSize:pageSize,
txy committed
206 207 208
        activityCode:activityCode,  // 活动id
        name: searchVal   // 搜索字段
    }
txy committed
209 210 211

    // 加载loading
    showLoading();
txy committed
212 213 214 215
    $.ajax({
        type: 'GET',
        url: baseUrl + '/ACTIVITY/sz/search/' + activityCode,
        data: params,
txy committed
216 217 218
        headers: {
            'x-token': getToken()
        },
txy committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
        success: function(data) {
            if(data.status == 200) {
                if(type == 'player' || type == 'search') {
                    var playerListData = data.result
                    if(typeof callback == "function") {
                        callback(playerListData)
                    }
                    if(type == 'search') {
                        $("#user-list").show();
                        $("#range-list").hide();
                    }
                    gb_player_loaded = false
                }else if(type == 'rank') {
                    var rankListData = data.result
                    if(typeof callback == "function") {
                        callback(rankListData)
                    }
                    gb_rank_loaded = false
                }
            }
txy committed
239
            hideLoading();
txy committed
240 241 242 243 244 245 246
        },
        error: function() {
            if(type == 'player' || type == 'search') {
                gb_player_loaded = false
            }else if(type == 'rank') {
                gb_rank_loaded = false
            }
txy committed
247
            hideLoading();
txy committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        }
    })
}
// 获取参赛选手列表
function getPlayerList(playerListData) {
    var list = $("#user-list .vote-con");
    list.hide()
    var i = 0
    var item = $(".item",list)[0];
    var tempItem = list.clone();
    // 清空子元素
    tempItem.empty().show();
    if(playerListData.records.length) {
        for(;i < playerListData.records.length; i++){
            // 序号替换
            $('.number-icon',item).text(playerListData.records[i].userNumber);
            // 图片url替换
            $('img',item).attr('src',playerListData.records[i].imageUrl);
            // 名称替换
            $('.user-name',item).text(playerListData.records[i].name);
            // 机构名称替换
谭新宇 committed
269 270 271 272 273 274
            if(rules.acActivityOrgs.length === 0){
              $('.vote-struct',item).remove();
            }else {
              $('.vote-struct',item).text(playerListData.records[i].orgName);
            }
            
txy committed
275 276 277 278
            // 票数替换
            $('.vote-num',item).text(playerListData.records[i].voteNum+'票');
            
            // 投票点击事件
txy committed
279
            var cloneItem = $(item).clone();
280
            cloneItem.find('.act-btn').attr('id',playerListData.records[i].id).attr('username',playerListData.records[i].name).on('click',function(){
txy committed
281
                var id = $(this).attr('id');
282
                var userName = $(this).attr('username');
txy committed
283 284
                var _this = $(this)
                var params = {
285
                    userId: id,
txy committed
286
                    userName: userName,
txy committed
287
                    orgId: getQueryString('orgId') !== null ? getQueryString('orgId') : ''
txy committed
288
                }
txy committed
289
                
txy committed
290
                isAttention(function(){
txy committed
291
                    showLoading('处理中...');
txy committed
292 293 294
                    // 投票
                    voteClickFn(params,function(data){
                        // success
txy committed
295
                        _this.parent('.item-title').prev().find('.vote-num').text(data.result.voteNum + '票');
txy committed
296
                    });
txy committed
297 298 299
                });
            });
            
txy committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
            // 参数选手点击事件
            cloneItem.find('.item-photo').attr('id',playerListData.records[i].id).on('click',playPageFn);
            tempItem.append(cloneItem);
        }
        $("#user-list").find('.vote-con').remove().end().prepend(tempItem);
        $('#user-list .list-empty').hide()
        $('#act61214527684747').parent('.navigation').show();
        $('#act61214527684747 .curpage').text(playerListData.current)
        $('#act61214527684747 .totalpage').text(playerListData.total)
    }else {
        $('#user-list .list-empty').show()
        $('#act61214527684747').parent('.navigation').hide();
    }
}

// 获取排行榜列表    
function getRangeList(rankListData){
   var list = $("#range-list tbody");
   list.hide()
   var tr = $("tr", list)[0];
   var i = 0
   var tempItem = list.clone();
   // 清空子元素
   tempItem.empty().show();
   if(rankListData.records.length) {
    for(;i < rankListData.records.length; i++){
        // 替换序号 badge-no1
        $('.number',tr).text(i+1);
        // 前三名有特殊图标
        if(i < 3) {
        $('.number',tr).removeClass().addClass('number ' + ('badge-no'+(i+1)));
        } else {
        $('.number',tr).removeClass().addClass('number');
        }
        // 替换名字,图片
        $('.table-info img',tr).attr('src',rankListData.records[i].imageUrl);
        $('.cell-info h4', tr).text(rankListData.records[i].name);
        // $('.cell-info small', tr).text(rankListData.records[i].userNumber);
        // 票数
        $('.ticket-total .text-red', tr).text(rankListData.records[i].voteNum);

txy committed
341 342
        // 编号
        $('.cell-info small', tr).text('编号:'+ rankListData.records[i].userNumber +'号');    
txy committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
        // 添加点击事件
        var cloneItem = $(tr).clone();
        tempItem.append(cloneItem);
    }
    $("#range-list table").find('tbody').remove().end().prepend(tempItem);
    $('#act111398324601').parent('.navigation').show();
    $('#act111398324601 .curpage').text(rankListData.current)
    $('#act111398324601 .totalpage').text(rankListData.total)
   }else {
    $('#act111398324601').parent('.navigation').hide();
   }
}

// tab切换
function tabChange(){
   var c_typename = $(this).attr("c_typename");
   if(c_typename === 'rangerListBtn') {
txy committed
360 361 362 363 364 365 366
     // 排行榜列表
     getAjaxListSearch('rank',1,function(rankListData){
        getRangeList(rankListData);
        $("#user-list").hide();
        $("#range-list").show(); 
     }); 
       
txy committed
367
   } else {
txy committed
368 369 370 371 372 373
       // 参赛选手列表
     getAjaxListSearch('player',1,function(playerListData){
        getPlayerList(playerListData);
        $("#user-list").show();
        $("#range-list").hide();
     });
txy committed
374 375 376 377 378 379
   }
}

// 选手主页
function playPageFn() {
  var id = $(this).attr('id');
txy committed
380
  var urlParam = 'userId='+id;
txy committed
381 382
  var _t = getToken();
  transPage('3',activityCode,_t,urlParam);
txy committed
383
}