user.js 7.29 KB
Newer Older
txy committed
1

txy committed
2 3 4
// 加载html结构
loadHtmlJson();

txy committed
5
$(function(){
txy committed
6
    setToken();
txy committed
7 8
    // 获取活动标题
    getActivityTitle();
txy committed
9
    btnBindClick();// 绑定点击事件
txy committed
10
    
胡畅 committed
11 12
    var showTime = new Date(rules.settings.szRule.votingEndTime.replace(/-/g,'/')).getTime() - new Date(currentTime.replace(/-/g,'/')).getTime();
    var endTime = new Date(rules.acActivity.endTime.replace(/-/g,'/')).getTime() - new Date(currentTime.replace(/-/g,'/')).getTime();
胡畅 committed
13 14 15 16
    $.dialog({
        type: "alert",
        contentHtml: "showTime" + showTime + ",endTime:" + endTime,
    });
谭新宇 committed
17
    userCountDown(showTime/1000, endTime/1000, $('#act31142119991744 span'));  //倒计时
txy committed
18
    userTabInfo();
txy committed
19
    voteDialogBindFn();
txy committed
20 21 22 23 24 25
});

// 元素点击事件绑定
function btnBindClick() {
    // 返回首页
    $("#act3110143885264").off("click").on("click",function(){
txy committed
26 27
        var _t = getToken();
        transPage('1',activityCode,_t);
txy committed
28 29 30
    });
    // 拉票
    $('#act31119351441050').off("click").on("click",function(){
txy committed
31 32 33 34 35
        // 设置分享参数
        setWxShare({
            userId: shareUserId,
            userName: shareUserName
        });
txy committed
36 37 38
        $('#html-template-8').fadeIn('normal', function() {
            $(document).scrollTop(0);
        });
txy committed
39 40 41 42
    });

    // 排行榜
    $("#act41612547506702").off('click').on("click", function(){
txy committed
43 44 45
        var _t = getToken();
        var _addParam = 'toRanger=1'
        transPage('1',activityCode,_t,_addParam);
txy committed
46 47 48 49
    });

    // 选手主页    
    $("#act4161336684689").off("click").on("click", function(){
txy committed
50 51 52 53 54
        // 判断关注
        isAttention(function(){
            // 判断是否报名
            isSignUp(function(){
                var _t = getToken();
txy committed
55
                var urlParam = 'userId='+user.id;
txy committed
56
                transPage('3',activityCode,_t,urlParam);
txy committed
57 58 59 60 61 62 63 64
            },function(){
                $.dialog({
                    contentHtml: '<p style="text-align:center;">您还未报名,请到首页报名参加后本次活动!</p>',
                    onClosed: function(){
                        var _t = getToken();
                        transPage('1',activityCode,_t);
                    }
                });
txy committed
65 66
            });
        });
txy committed
67 68 69 70
    });

    // 活动秘籍    
    $("#act41613113951133").off("click").on("click", function(){
txy committed
71 72 73
        $('#html-template-8').fadeIn('normal', function() {
          $(document).scrollTop(0);
        });
txy committed
74 75 76 77
    });

    // 给用户投票
    $("#act31119414834381").off("click").on("click", function(){
78 79
        var _userId = shareUserId;
        var _userName = shareUserName;
txy committed
80
        var params = {
81
            userId: _userId,
txy committed
82
            userName: _userName,
txy committed
83
            orgId: getQueryString('orgId') !== null ? getQueryString('orgId') : ''
txy committed
84
        }
txy committed
85
        
txy committed
86
        isAttention(function(){
txy committed
87
            showLoading('处理中...');
txy committed
88 89 90
            voteClickFn(params, function(data){
                $('#act3932189955 .userVoteNum span').text(data.result.voteNum);
            });
txy committed
91
        });
txy committed
92 93 94
    });
}
// 倒计时
95
function userCountDown(times, endTime ,ids){
胡畅 committed
96 97 98 99 100 101
    var $countDown = $('#act31142119991744')
    if($countDown.attr('c_counttime') == 'yes') {
        $countDown.removeClass('global-none')
        var timer=null;
        var self = this
        var times = times
102
        var endTimes = endTime
胡畅 committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
          timer=setInterval(function(){
            var day=0,
              hour=0,
              minute=0,
              second=0;//时间默认值
            if(times > 0){
              day = Math.floor(times / (60 * 60 * 24));
              hour = Math.floor(times / (60 * 60)) - (day * 24);
              minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60);
              second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (day <= 9) day = '0' + day;
            if (hour <= 9) hour = '0' + hour;
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            ids.html((day != 00 ? day + "天" : '')+hour+"时"+minute+"分"+second+"秒")
            times--;
120 121 122 123 124 125 126 127 128
            endTimes--;
            // 判断活动时间是否结束
            if(endTimes < 0) {
                clearInterval(timer);
                // ids.parent().addClass('global-none');
                ids.parent().html('活动已结束');
            }
            // 判断投票时间是否结束
            else if(times < 0){
胡畅 committed
129
                clearInterval(timer);
130
                // ids.parent().addClass('global-none');
谭新宇 committed
131
                ids.parent().html('投票已结束');
132
            }
胡畅 committed
133 134 135 136
          },1000);
    }else {
        $countDown.addClass('global-none')
    }
txy committed
137 138 139 140
}

// 个人信息展示
function userTabInfo() {
txy committed
141
    var id = getQueryString('userId')?getQueryString('userId'):user.id;
txy committed
142 143 144 145 146 147 148 149
    var params = {
        id: id,
        reviewStatus:1  // 审核状态
    }
    $.ajax({
        type: 'GET',
        url: baseUrl + '/ACTIVITY/sz/search/' + activityCode,
        data: params,
txy committed
150 151 152
        headers: {
            'x-token': getToken()
        },
txy committed
153 154 155 156 157 158 159
        success: function(data) {
            if(data.status == 200) {
                var userInfoObj = data.result && data.result.records && data.result.records[0]
                $('#act3932189955 .user-info .inner-pic').attr('src',userInfoObj.wechatAvatarUrl);
                var innerInfo = $('#act3932189955 .user-info .inner-info')
                innerInfo.find('.userName span').text(userInfoObj.name)
                innerInfo.find('.userNo span').text(userInfoObj.userNumber)
胡畅 committed
160
                innerInfo.find('.userRank span').text(userInfoObj.ranking)   // 排名
txy committed
161 162 163 164
                innerInfo.find('.userVoteNum span').text(userInfoObj.voteNum)
                $('#act3932189955 .userState').val(userInfoObj.declaration)
                $('#act3932189955 .userState').attr('readOnly','readOnly')
                $('#act3932189955 .show-pic').attr('src',userInfoObj.imageUrl);
165 166 167

                shareUserId = userInfoObj.id;
                shareUserName = userInfoObj.name;
txy committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

                // 创建新增项
                var addStr = '';
                var inputStr = '<div class="form-row m-b">'+
                                    '<div class="form-input-group">'+
                                        '<div class="form-input-group-inner">'+
                                            '<input type="text" c_remove="readonly" readonly="readOnly" value="{{value}}">'+
                                        '</div>'+
                                    '</div>'+
                                '</div>';
                if(userInfoObj.x1 !== ''){
                    addStr += inputStr.replace(/{{value}}/g,userInfoObj.x1);
                }
                if(userInfoObj.x2 !== ''){
                    addStr += inputStr.replace(/{{value}}/g,userInfoObj.x2);
                }
                if(userInfoObj.x3 !== ''){
                    addStr += inputStr.replace(/{{value}}/g,userInfoObj.x3);
                }
                if(addStr !== ''){
                    $("#act3932189955 .form-row:last-child").prepend(addStr);
                }
txy committed
190 191 192
            }
        },
        error: function() {
胡畅 committed
193 194 195 196 197
            $.dialog({
                type : 'tips',
                autoClose : 3000,
                infoText : '请求超时,请尝试刷新页面!'
            });
txy committed
198 199 200 201
        }
    })
}