user.js 7.84 KB
Newer Older
txy committed
1 2
var gb_vote_loaded = false

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

txy committed
6
$(function(){
txy committed
7
    setToken();
txy committed
8
    btnBindClick();// 绑定点击事件
胡畅 committed
9
    var showTime = new Date(rules.acActivity.endTime).getTime() - new Date(currentTime).getTime()
txy committed
10 11 12 13 14
    userCountDown(showTime/1000,$('#act31142119991744 span'));  //倒计时
    userTabInfo();
});

// 微信鉴权
txy committed
15
function wxpermission(userId,userName) {
txy committed
16 17
    wx.ready(function(){
        var shareData = {
txy committed
18 19 20
            title: rules.settings.szText.shareTitile,
            imgUrl: rules.settings.szText.shareIcon,
            desc: rules.settings.szText.shareSubtitle,
txy committed
21 22
            link: ""
        }
txy committed
23 24 25
    
        // 已报名
        if (user.status) {
txy committed
26 27
          shareData.title = rules.settings.szText.pullTitile;
          shareData.desc = rules.settings.szText.pullSubtitle.replace("{{姓名}}", userName);
txy committed
28 29 30 31
          shareData.link = "/ACTIVITY/view/" + activityCode + "/3?UserId="+userId;
    
        }else {
          // 分享首页
txy committed
32 33
          shareData.title = rules.settings.szText.shareTitile;
          shareData.desc = rules.settings.szText.shareSubtitle;
txy committed
34 35 36
          shareData.link = "/ACTIVITY/view/" + activityCode + "/1";
        }
    
txy committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        /**
         *分享给朋友
        */
        wx.onMenuShareAppMessage({
            title: shareData.title, // 分享标题
            desc: shareData.desc, // 分享描述
            link: shareData.link, // 分享链接
            imgUrl: shareData.imgUrl, // 分享图标
            type: 'link', // 分享类型,music、video或link,不填默认为link
            dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
            success: function () {
                // 用户确认分享后执行的回调函数
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });
        /**
         *分享到朋友圈
        */
        wx.onMenuShareTimeline({
            title: shareData.title, // 分享标题
            desc: shareData.desc, // 分享描述
            link: shareData.link, // 分享链接
            imgUrl: shareData.imgUrl, // 分享图标
            success: function () {
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });
    });
}

// 元素点击事件绑定
function btnBindClick() {
    // 返回首页
    $("#act3110143885264").off("click").on("click",function(){
txy committed
75 76
        var _t = getToken();
        transPage('1',activityCode,_t);
txy committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    });
    // 拉票
    $('#act31119351441050').off("click").on("click",function(){
        $('#html-template-8').fadeIn()
    });
    // 分享弹框关闭
    $(document).on('click','#html-template-8 .modal-close',function(){
        $('#html-template-8').fadeOut()
    });
    // 投票
    $('#act31119414834381').off("click").on("click",function(){
        voteClickFn()
    });
    // 我要拉票
    $('#act2172989331265').off("click").on("click",function(){
        $('#html-template-8').fadeIn()
    });
    // 继续投票
    $('#act21728433893489').off("click").on("click",function(){
        voteClickFn()
    });
    // 投票弹框关闭
    $(document).on('click','#html-template-4 .modal-close',function(){
        $('#html-template-4').fadeOut()
    });

    // 排行榜
    $("#act41612547506702").off('click').on("click", function(){
txy committed
105 106 107
        var _t = getToken();
        var _addParam = 'toRanger=1'
        transPage('1',activityCode,_t,_addParam);
txy committed
108 109 110 111
    });

    // 选手主页    
    $("#act4161336684689").off("click").on("click", function(){
txy committed
112 113 114 115 116 117 118 119 120
        // 判断关注
        isAttention(function(){
            // 判断是否报名
            isSignUp(function(){
                var _t = getToken();
                var urlParam = 'UserId='+user.id;
                transPage('3',activityCode,_t,urlParam);
            });
        });
txy committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    });

    // 活动秘籍    
    $("#act41613113951133").off("click").on("click", function(){
        $('#html-template-8').fadeIn()
    });
}
// 倒计时
function userCountDown(times,ids){
  var timer=null;
  var self = this
  var times = times
  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--;
    if(times<0){
        clearInterval(timer);
        ids.parent().addClass('global-none')
      }
  },1000);
}

// 个人信息展示
function userTabInfo() {
    var id = getQueryString('UserId')?getQueryString('UserId'):user.id;
    var params = {
        id: id,
        reviewStatus:1  // 审核状态
    }
    $.ajax({
        type: 'GET',
        url: baseUrl + '/ACTIVITY/sz/search/' + activityCode,
        data: params,
        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
175
                innerInfo.find('.userRank span').text(userInfoObj.ranking)   // 排名
txy committed
176 177 178 179 180
                innerInfo.find('.userVoteNum span').text(userInfoObj.voteNum)
                $('#act3932189955 .userState').val(userInfoObj.declaration)
                $('#act3932189955 .userState').attr('readOnly','readOnly')
                $('#act3932189955 .show-pic').attr('src',userInfoObj.imageUrl);
            }
txy committed
181
            wxpermission(id,userInfoObj.name);
txy committed
182 183
        },
        error: function() {
胡畅 committed
184 185 186 187 188
            $.dialog({
                type : 'tips',
                autoClose : 3000,
                infoText : '请求超时,请尝试刷新页面!'
            });
txy committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
        }
    })
}  

// 投票按钮
function voteClickFn(){
  var id = getQueryString('UserId')?getQueryString('UserId'):user.id;
  var _this = $(this)
  var params = {
    userId: id
  }
  if(gb_vote_loaded) {
    return
  }
  gb_vote_loaded = true
  $.ajax({
    type: 'PUT',
    url: baseUrl + '/ACTIVITY/sz/vote/' + activityCode,
    data: params,
    success: function(data) {
        gb_vote_loaded = false
        if(data.status == 200) {
            $('#act1185354268270 span').text(data.result.voteNumDay)
            $('#act3932189955 .user-info .inner-info').find('.userVoteNum span').text(data.result.voteNum)
            if(user.status) {
                $('#html-template-4').fadeIn()
            }else {
                $('#html-template-6').fadeIn()
            }
        }else if(data.status == 201) {
            $('#act51626389412499 span').text(rules.szRule.voteNumDay)    // 模板参数中获取
            if(user.status) {
                $('#html-template-5').fadeIn()
            }else {
                $('#html-template-7').fadeIn()
            }
txy committed
225 226 227 228 229
        }else if (data.status >= 400) {
            // 异常处理
            $.dialog({
                contentHtml : '<p style="text-align:center;">'+ data.message +'</p>'
            });
txy committed
230 231
        }
    },
txy committed
232
    error: function(data) {
txy committed
233
        gb_vote_loaded = false
txy committed
234 235
        // 异常处理
        $.dialog({
txy committed
236
            contentHtml : '<p style="text-align:center;">'+ data.responseJSON.message +'</p>'
txy committed
237
        });
txy committed
238 239 240 241
    }
  })
}