var Query = { calendar: null, init: function() { if ($('#query_page').length == 0) { return; } Query.checkLogin(); var maxDay = (new Date()).addDays(19); Public.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() { Public.showInnerPage('filter'); }); $('#filter_cancel').on('click', function() { Public.hideInnerPage('filter'); var bak = $('#query_form [name=filters]').val(), querys = bak.split('&'); Query.setFilter(querys); }); $('#filter_ok').on('click', function() { Public.hideInnerPage('filter'); $('#query_form [name=filters]').val($('#filter_form').serialize()); }); CheckStaion.init(); Query.stationInt(); $('#query_form [name=filters]').val($('#filter_form').serialize()); $('#query_form').on('submit', function() { var start = $('#startStationCode').val(), end = $('#endStationCode').val(); if (start == '') { Public.alert('请选择出发站'); return false; } else if (end == '') { Public.alert('请选择到达站'); return false; }else if(start==end){ Public.alert('出发地和目的地不能相同'); return false; }; var queryString = $('#query_form').serialize(); Public.setHisQuery(start + '-' + end, queryString); window.location.href = 'run_query.html'; return false; }); Query.setHisQuery(); }, setHisQuery: function() { var hisList = Public.his.querys, html = '
' + date.format('M月d日') + '不在预售期
预约提醒'); // if (offset.left / window.innerWidth > 0.75) { // $('#date_tip').attr('class', 'tip_small tip_right'); // } else if (offset.left / window.innerWidth < 0.15) { // $('#date_tip').attr('class', 'tip_small tip_left'); // } 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('退出'); $('body').removeClass('nologin'); $('#menu_btn .icon_user').addClass('icon_user2'); $('#login_tip').hide(); }, noLogin: function() { $('#login').attr('href', '/12306/login.html').attr('data-fn', 'login').html('登录'); $('body').addClass('nologin'); $('#menu_btn .icon_user').removeClass('icon_user2'); $('#login_tip').show(); }, stationInt: function() { $('#startStation').on('click', function() { CheckStaion.callback = Query.startCallback; CheckStaion.cancelCallback = Query.cancelCallback; CheckStaion.show(); $('#wrap').hide(); }); $('#endStation').on('click', function() { CheckStaion.callback = Query.endCallback; CheckStaion.cancelCallback = Query.cancelCallback; CheckStaion.show(); $('#wrap').hide(); }); $('#exchange').on('click', function() { var startName = $('#startStationName').val(), startCode = $('#startStationCode').val(), endName = $('#endStationName').val(), endCode = $('#endStationCode').val(); $('#startStationName').val(endName); $('#startStationCode').val(endCode); $('#endStationName').val(startName); $('#endStationCode').val(startCode); if (!!startName) { $('#endStation').html(startName); } else { $('#endStation').html('到达站'); } if (!!endName) { $('#startStation').html(endName); } else { $('#startStation').html('出发站'); } }); }, startCallback: function(name, code) { // console.log(name, code); // if (code == $('#endStationCode').val() && code != '') { // Public.toast('出发地和目的地不能相同'); // return false; // } $('#startStation').html(name); $('#startStationName').val(name); $('#startStationCode').val(code); CheckStaion.hide(); $('#wrap').show(); }, endCallback: function(name, code) { // console.log(name, code); // if (code == $('#startStationCode').val() && code != '') { // Public.toast('出发地和目的地不能相同'); // return false; // } $('#endStation').html(name); $('#endStationName').val(name); $('#endStationCode').val(code); CheckStaion.hide(); $('#wrap').show(); }, cancelCallback: function() { $('#wrap').show(); } }