var Query = { calendar: null, init: function() { Query.checkLogin(); var maxDay = (new Date()).addDays(19); Query.setDate(maxDay); $('#menu_btn').on('click',function(){ $('#user_menu').toggle(); }); $('#user_menu').on('click',function(e){ if($(e.target).attr('id') == 'user_menu'){ $('#user_menu').hide(); } }); $('#open_filter').on('click',function(){ $('#search_station').addClass('fixed_box_show'); }); }, setDate: function(date) { var date = date || (new Date()).date; $('#start_date').html(date.format('yyyy年M月d日') + ' ' + date.day(3)).attr('data-date', date.date.getTime()); if (!Query.calendar) { Query.calendar = new DateComponent({ wrap: $('#calendar'), curDate: date, checkCallback: Query.dateChangeCallback }); } $('.check_left,.check_right').on('click', function() { var checkDate; if ($(this).hasClass('check_left')) { checkDate = Query.calendar.dayPrev(); } else { checkDate = Query.calendar.dayNext(); } if (checkDate) { $('#start_date').html(checkDate.format('yyyy年M月d日') + ' ' + checkDate.day(3)).attr('data-date', checkDate.date.getTime()); } }); $('#start_date').on('click', function() { $('#date_box').addClass('fixed_box_show'); }); $('#date_sure').on('click', function() { $('#start_date').html(Query.calendar.curDate.format('yyyy年M月d日') + ' ' + Query.calendar.curDate.day(3)).attr('data-date', Query.calendar.curDate.date.getTime()); $('#date_box').removeClass('fixed_box_show'); }); $('[name=type]').on('change', function() { var val = $('[name=type]:checked').val(); if (val == 1) { Query.calendar.maxDate = Query.calendar._TODAY.addDays(19); if (Query.calendar.curDate.date.getTime() > Query.calendar.maxDate.date.getTime()) { Query.calendar.curDate = Query.calendar.maxDate; Query.dateChangeCallback(Query.calendar.curDate); } Query.calendar.setBasic(); } else if (val == 2) { Query.calendar.maxDate = Query.calendar._TODAY.addDays(29); Query.calendar.setBasic(); } }); }, dateChangeCallback: function(date) { var time = date.date.getTime(); if (time >= Query.calendar.minDate.date.getTime() && time <= Query.calendar.maxDate.date.getTime()) { $('#date_tip').hide(); $('#date_box').removeClass('fixed_box_show'); $('#start_date').html(Query.calendar.curDate.format('yyyy年M月d日') + ' ' + Query.calendar.curDate.day(3)).attr('data-date', Query.calendar.curDate.date.getTime()); }else{ var offset = $('a.cur',Query.calendar.wrap).offset(); $('#date_tip').css({'left':offset.left,'top':offset.top}).html('

'+date.format('M月d日')+'不在预售期

预约提醒').show(); if(offset.left/window.innerWidth > 0.75){ $('#date_tip').attr('class','tip_small tip_left'); }else if(offset.left/window.innerWidth < 0.25){ $('#date_tip').attr('class','tip_small tip_right'); }else{ $('#date_tip').attr('class','tip_small'); } } }, checkNum: 0, checkLogin: function() { Query.checkNum++; cn12306.isUserLogined(Query.hasLogin, Query.noLogin, function() { Query.noLogin(); // Public.toast("登录时网络错误"); if (Query.checkNum < 2) { Query.checkLogin(); } }); }, hasLogin: function() { $('#login').attr('href', 'javascript:;').attr('data-fn', 'loginout').html('退出'); $('#menu_btn .icon_user').addClass('icon_user2'); $('#login_tip').hide(); }, noLogin: function() { $('#login').attr('href', '/12306/login.html').attr('data-fn', 'login').html('登录'); $('#menu_btn .icon_user').removeClass('icon_user2'); $('#login_tip').show(); } }