|
@@ -0,0 +1,447 @@
|
|
|
+// ---- 助力竞猜分享模板js ----
|
|
|
+var Swiper = require('swiper.min.js');//轮播
|
|
|
+var matchListTpl = __inline("/src/tpl/share/matchSlider.tmpl"); //比赛列表
|
|
|
+var matchWeekTpl = __inline("/src/tpl/share/matchWeek.tmpl"); //比赛周列表
|
|
|
+var modalTpl = __inline("/src/tpl/share/modal.tmpl"); //弹窗模板
|
|
|
+var QRcodeTpl = __inline("/src/tpl/share/QRcode.tmpl");
|
|
|
+
|
|
|
+var MatchList = []; //比赛信息
|
|
|
+var swiper = null;
|
|
|
+var mobileFlag = false //移动端标识 true => 移动端 默认pc端
|
|
|
+var btnMoreFlag = true //展开更多按钮点击标识
|
|
|
+var API = '//match-guess.duowan.com';
|
|
|
+var AC_ID = $('.page-stake').attr('data-acid') //活动ID
|
|
|
+
|
|
|
+var C = {
|
|
|
+ init: function() {
|
|
|
+ this.guessShow();
|
|
|
+ this.weekSelect();
|
|
|
+ this.showMore();
|
|
|
+ this.submitWin();
|
|
|
+ this.liveQueSubmit();
|
|
|
+ this.maskClick();
|
|
|
+ },
|
|
|
+ guessShow: function() {
|
|
|
+ // 更多竞猜
|
|
|
+ $(document).on('click', '.match-guess-btn', function(){
|
|
|
+ if($(this).prev().hasClass('match-guess-wrap')){
|
|
|
+ $(this).prev().slideToggle();
|
|
|
+ $(this).find('.arrow-down-icon').toggleClass('rotate')
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ alert('没有更多竞猜了')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ weekSelect: function() {
|
|
|
+ $(document).on('click', '.week-btn-wrap .btn', function() {
|
|
|
+ $('.week-btn-wrap').find('.btn').removeClass('active');
|
|
|
+ $(this).addClass('active');
|
|
|
+
|
|
|
+ var weekVal = $(this).attr('data-week');
|
|
|
+ V.renderMatchList(MatchList.data[weekVal], mobileFlag);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ showMore: function() {
|
|
|
+ // 点击更多
|
|
|
+ $(document).on('click', '.btn-more', function() {
|
|
|
+ var $btnWrap = $('.week-select').find('.week-btn-wrap');
|
|
|
+ $btnWrap.toggleClass('showmore');
|
|
|
+ $btnWrap.hasClass('showmore') ? $(this).text('收起更多') : $(this).text('展开更多');
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 胜负提交
|
|
|
+ submitWin: function(){
|
|
|
+ $(document).on('click', '.guess-submit', function() {
|
|
|
+ var guessId = $(this).attr('data-guess');
|
|
|
+ var optionId = $(this).attr('data-option');
|
|
|
+ var matchId = $(this).parents('.top-swiper-slide').attr('data-match');
|
|
|
+ var param = {
|
|
|
+ guess_id: guessId,
|
|
|
+ option_id: optionId,
|
|
|
+ match_id: matchId
|
|
|
+ };
|
|
|
+ M.submitAnswer(param, $(this));
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 实况问题提交
|
|
|
+ liveQueSubmit: function() {
|
|
|
+ $(document).on('click', '.live-que-submit', function() {
|
|
|
+ var param = [];
|
|
|
+ var $quewrap = $(this).parent('.match-guess-wrap');
|
|
|
+ var matchId = $(this).parents('.top-swiper-slide').attr('data-match');
|
|
|
+ // var step = 0;
|
|
|
+ var queSum = $quewrap.find('.que-radio').length;
|
|
|
+ var guessId= '';
|
|
|
+ var optionId = '';
|
|
|
+ $quewrap.find('.que-radio').each(function() {
|
|
|
+ // var guessId = $(this).attr('data-guess');
|
|
|
+ var $radio = $(this).find('input[type="radio"]');
|
|
|
+ $radio.each(function() {
|
|
|
+ // 选中
|
|
|
+ if($(this).is(':checked')){
|
|
|
+ // step++;
|
|
|
+ guessId = $(this).attr('data-guess');
|
|
|
+ optionId = $(this).attr('data-option');
|
|
|
+ param.push({
|
|
|
+ guess_id: guessId,
|
|
|
+ option_id: optionId,
|
|
|
+ match_id: matchId
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ if(param.length != queSum){
|
|
|
+ alert('还有竞猜没完成哦');
|
|
|
+ // V.showModal('还有竞猜没完成哦')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ M.liveQueSubmit(param,$(this));
|
|
|
+ })
|
|
|
+ },
|
|
|
+ maskClick() {
|
|
|
+ $(document).on('click', '.pub-guess-masker', function() {
|
|
|
+ $(this).remove()
|
|
|
+ })
|
|
|
+ $(document).on('click', '.pub-guess-modal', function(e) {
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var V = {
|
|
|
+ init: function() {
|
|
|
+ this.screenInit();
|
|
|
+ this.setPrecent();
|
|
|
+
|
|
|
+ M.getMatchList();
|
|
|
+ },
|
|
|
+ screenInit: function() {
|
|
|
+ // 页面初始化设置
|
|
|
+ var winWidth = $(window).width();
|
|
|
+ if(winWidth > 750) {
|
|
|
+ this.initSwiper(4);
|
|
|
+ }else {
|
|
|
+ this.initSwiper(2);
|
|
|
+ mobileFlag = true;
|
|
|
+ }
|
|
|
+ var btnLen = $('.week-btn-wrap').find('.btn').length;
|
|
|
+ if(btnLen > 9 && !mobileFlag && btnMoreFlag){
|
|
|
+ btnMoreFlag = false
|
|
|
+ $('.week-select').find('.btn-more').trigger('click');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 轮播
|
|
|
+ initSwiper: function(num) {
|
|
|
+ swiper = new Swiper('.top-swiper-container', {
|
|
|
+ slidesPerView: num,
|
|
|
+ centeredSlides: false,
|
|
|
+ spaceBetween: 2,
|
|
|
+ slideClass : 'top-swiper-slide',
|
|
|
+ navigation: {
|
|
|
+ nextEl: '.swiper-button-next',
|
|
|
+ prevEl: '.swiper-button-prev',
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ setPrecent: function() {
|
|
|
+ // 设置百分比进度条
|
|
|
+ var prencetWidth = $('.match-precent').find('.progress').width();
|
|
|
+ var progressAll = prencetWidth - 40;
|
|
|
+ $('.progress').find('.num').each(function() {
|
|
|
+ var num = $(this).html().replace('%','');
|
|
|
+ var length = progressAll * (num/100);
|
|
|
+ $(this).parent().find('.length').width(length);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 参数灵活配置按天分组还是按周分组
|
|
|
+ // 确认第几周
|
|
|
+ confirmWeek: function(data) {
|
|
|
+ var flag = false;
|
|
|
+ var keyArr = [];
|
|
|
+ for(var i in data) {
|
|
|
+ keyArr.push(i);
|
|
|
+ var startTime = data[i][0]["start_time"];
|
|
|
+ if(Week.getWeekTime(startTime)){
|
|
|
+ flag = true;
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ // debugger
|
|
|
+ }
|
|
|
+ // 没匹配,默认显示第一个key
|
|
|
+ if(!flag) {
|
|
|
+ return keyArr[0];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 确认第几天
|
|
|
+ confirmDay: function(data) {
|
|
|
+ var flag = false;
|
|
|
+ var keyArr = [];
|
|
|
+ for(var i in data) {
|
|
|
+ keyArr.push(i);
|
|
|
+ var startTime = data[i][0]["start_time_md"];
|
|
|
+ if(Day.getDayTime(startTime)){
|
|
|
+ flag = true;
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ // debugger
|
|
|
+ }
|
|
|
+ // 没匹配,默认显示第一个key
|
|
|
+ if(!flag) {
|
|
|
+ return keyArr[0];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 比赛列表 新增移动端判断参数 moblie
|
|
|
+ renderMatchList: function(obj, moblie) {
|
|
|
+ var dom = matchListTpl({data: obj,moblie: moblie});
|
|
|
+ $('.match-slider-wrap').remove();
|
|
|
+ $('.page-stake').append(dom);
|
|
|
+ V.screenInit();
|
|
|
+ V.setPrecent();
|
|
|
+ },
|
|
|
+ // 日期选择
|
|
|
+ // 参数: 比赛列表 当前显示日期索引 分组规则 移动端显示规则
|
|
|
+ renderWeekSel: function(obj,i,group,moblie) {
|
|
|
+ var dom = matchWeekTpl({data: obj,curWeek: i, group: group, moblie: moblie});
|
|
|
+ $('.page-stake').append(dom);
|
|
|
+ },
|
|
|
+ // 弹窗显示
|
|
|
+ showModal: function(data) {
|
|
|
+ var dom = modalTpl({data})
|
|
|
+ $('body').append(dom)
|
|
|
+ },
|
|
|
+ // 显示弹窗类型
|
|
|
+ showQRcode: function(defalutMsg){
|
|
|
+ if(dwUDBProxy.isLogin()){
|
|
|
+ $.ajax({
|
|
|
+ dataType: 'jsonp',
|
|
|
+ url: API + '/encour/getTodayAllot?ac_id=' + AC_ID,
|
|
|
+ success: function(data){
|
|
|
+ if(data.rs){
|
|
|
+ if(data.needTip != false){
|
|
|
+
|
|
|
+ new Image().src = 'http://clickstats.duowan.com/index.php?r=stats/index&event=match_guess_encour_allot'
|
|
|
+
|
|
|
+ var dom = QRcodeTpl(),
|
|
|
+ codeUrl = 'http://hdzt.duowan.com/s/zljc.html?code=',
|
|
|
+ codeEle,qrcode;
|
|
|
+ if($('.QRcode-guess-masker').length < 1){
|
|
|
+ $('body').append(dom);
|
|
|
+ codeEle = document.getElementById('guess-QRcode');
|
|
|
+ qrcode = new QRCode(codeEle,{
|
|
|
+ text: codeUrl + data.progress.progress_code,
|
|
|
+ height: 160,
|
|
|
+ width: 160
|
|
|
+ });
|
|
|
+ $('.QRcode-guess-masker').on('click','.close',function(){
|
|
|
+ $('.QRcode-guess-masker').remove();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ alert(defalutMsg);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ alert(data.msg);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(){
|
|
|
+ // alert('请先登录')
|
|
|
+ dwUDBProxy.login("") //登录成功地址,默认当前页
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else{
|
|
|
+ dwUDBProxy.login("")
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var M = {
|
|
|
+ // 比赛列表
|
|
|
+ getMatchList: function() {
|
|
|
+ var type = $('.page-stake').attr('data-group');
|
|
|
+ $.ajax({
|
|
|
+ dataType: 'jsonp',
|
|
|
+ url: API+'/matches/list?ac_id='+AC_ID,
|
|
|
+ data: {
|
|
|
+ groupMode: type
|
|
|
+ },
|
|
|
+ success: function(data){
|
|
|
+ var matchList = []
|
|
|
+ var data = data.data
|
|
|
+ for(var i in data){
|
|
|
+ matchList = matchList.concat(data[i])
|
|
|
+ }
|
|
|
+
|
|
|
+ var index = 0;
|
|
|
+ var pIndex = $('.page-stake-zm').attr('ind')
|
|
|
+ $.each(matchList, function(i,e) {
|
|
|
+ if(e.status == 1){
|
|
|
+ index = i;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ index = pIndex ? pIndex : index
|
|
|
+
|
|
|
+ V.renderMatchList(matchList, mobileFlag);
|
|
|
+ // 自动滚动到进行中的位置
|
|
|
+ swiper.slideTo(index, 0, false)
|
|
|
+
|
|
|
+ /*MatchList = data;
|
|
|
+ MatchList.length = Object.keys(data.data).length;
|
|
|
+ if(type == "week") {
|
|
|
+ var i = V.confirmWeek(MatchList.data);
|
|
|
+ }
|
|
|
+ if(type == "day") {
|
|
|
+ var i = V.confirmDay(MatchList.data);
|
|
|
+ }
|
|
|
+ V.renderWeekSel(Object.keys(data.data),i,type,mobileFlag);
|
|
|
+ // var testArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
|
+ // V.renderWeekSel(testArr,i,type,mobileFlag);
|
|
|
+
|
|
|
+ var matchTemp = MatchList.data[i];
|
|
|
+ var index = 0; //进行中的索引
|
|
|
+ $.each(matchTemp, function(i ,e) {
|
|
|
+ if(e.status == 1) {
|
|
|
+ index = i;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ V.renderMatchList(MatchList.data[i], mobileFlag);
|
|
|
+ // 自动滚动到进行中的位置
|
|
|
+ swiper.slideTo(index, 0, false)*/
|
|
|
+ },
|
|
|
+ error: function(){
|
|
|
+ // 登录态失效
|
|
|
+ // data.isLogin = false;
|
|
|
+ // V.renderGuessModal(data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 胜负竞猜提交
|
|
|
+ submitAnswer: function(obj, $this) {
|
|
|
+ if(dwUDBProxy.isLogin()){
|
|
|
+ $.ajax({
|
|
|
+ dataType: 'jsonp',
|
|
|
+ url: API+'/guess/SubmitWin?ac_id='+AC_ID,
|
|
|
+ data: obj,
|
|
|
+ success: function(data){
|
|
|
+ if(data.rs){
|
|
|
+ V.showQRcode(data.msg);
|
|
|
+
|
|
|
+ $this.parents('.top-swiper-slide').find('.match-precent').removeClass('pre-hidden');
|
|
|
+ if($this.hasClass('red-team')){
|
|
|
+ $this.parent().find('.blue-team').addClass('team-unselect');
|
|
|
+ } else if($this.hasClass('blue-team')){
|
|
|
+ $this.parent().find('.red-team').addClass('team-unselect');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ alert(data.msg)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(){
|
|
|
+ // alert('请先登录')
|
|
|
+ dwUDBProxy.login("") //登录成功地址,默认当前页
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else{
|
|
|
+ dwUDBProxy.login("") //登录成功地址,默认当前页
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 实况问题提交
|
|
|
+ liveQueSubmit: function(param,$this) {
|
|
|
+ if(dwUDBProxy.isLogin()){
|
|
|
+ $.ajax({
|
|
|
+ dataType: 'jsonp',
|
|
|
+ url: API+'/guess/SubmitLives?ac_id='+AC_ID,
|
|
|
+ data: {args: param},
|
|
|
+ success: function(data){
|
|
|
+ if(data.rs) {
|
|
|
+ V.showQRcode(data.msg);
|
|
|
+ } else {
|
|
|
+ alert(data.msg)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function() {
|
|
|
+ // alert('请先登录');
|
|
|
+ dwUDBProxy.login("") //登录成功地址,默认当前页
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ dwUDBProxy.login("") //登录成功地址,默认当前页
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+var Week = {
|
|
|
+ getWeekTime: function(curTimes) {
|
|
|
+ var now = new Date();
|
|
|
+ var nowTime = now.getTime() ;
|
|
|
+ var day = now.getDay();
|
|
|
+ if(day == 0) {
|
|
|
+ day = 7;
|
|
|
+ }
|
|
|
+ var oneDayLong = 24*60*60*1000 ;
|
|
|
+ var MondayTime = nowTime - (day-1)*oneDayLong ;
|
|
|
+ var SundayTime = nowTime + (7-day)*oneDayLong ;
|
|
|
+ //本周年份
|
|
|
+ var yearMonday = new Date(MondayTime).getFullYear();
|
|
|
+ var yearSunday = new Date(SundayTime).getFullYear();
|
|
|
+ // 本周月份
|
|
|
+ var monMonday = new Date(MondayTime).getMonth()+1;
|
|
|
+ var monSunday = new Date(SundayTime).getMonth()+1;
|
|
|
+ // 本周日期
|
|
|
+ var dayMonday = new Date(MondayTime).getDate();
|
|
|
+ var daySunday = new Date(SundayTime).getDate();
|
|
|
+ function getTime(year,month,day){
|
|
|
+ return year+'/'+month+'/'+day
|
|
|
+ }
|
|
|
+ // 一周开始时间截
|
|
|
+ var timesStart = (new Date(getTime(yearMonday,monMonday,dayMonday)+' 00:00:00').getTime())/1000;
|
|
|
+ // 一周结束时间截
|
|
|
+ var timesEnd = (new Date(getTime(yearSunday,monSunday,daySunday)+' 23:59:59').getTime())/1000;
|
|
|
+ // debugger
|
|
|
+
|
|
|
+ if(curTimes > timesStart && curTimes < timesEnd){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var Day = {
|
|
|
+ getDayTime: function(curDay) {
|
|
|
+ var now = new Date();
|
|
|
+ var month = now.getMonth() + 1;
|
|
|
+ var day = now.getDate();
|
|
|
+ var year = now.getFullYear();
|
|
|
+
|
|
|
+ var mathchMon = curDay.split('-')[0]
|
|
|
+ var mathchDay = curDay.split('-')[1]
|
|
|
+
|
|
|
+ if(month < 10) {
|
|
|
+ month = '0' + month
|
|
|
+ }
|
|
|
+ if(day < 10) {
|
|
|
+ day = '0' + day
|
|
|
+ }
|
|
|
+ // var dayStr = month+'-'+day
|
|
|
+
|
|
|
+ var nowTime = new Date(year+'/'+month+'/'+day+' 00:00:00').getTime()
|
|
|
+ var matchTime = new Date(year+'/'+mathchMon+'/'+mathchDay+' 00:00:00').getTime()
|
|
|
+
|
|
|
+ if(nowTime == matchTime || nowTime < matchTime) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+C.init();
|
|
|
+V.init();
|
|
|
+
|
|
|
+// Day.getDayTime()
|