295 lines
8.8 KiB
JavaScript
295 lines
8.8 KiB
JavaScript
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 = '<div class="his_title">最近查找</div>',
|
|
val;
|
|
if (Public.his.querys.length == 0) {
|
|
return false;
|
|
}
|
|
|
|
html += '<ul class="list his_list">';
|
|
for (var i = 0, len = hisList.length; i < len; i++) {
|
|
val = Public.his.queryObjs[hisList[i][0]];
|
|
html += '<li><a href="javascript:;" data-key="' + hisList[i][0] + '"><span>' + val["startname"] + '</span><span>' + val["endname"] + '</span></a></li>'
|
|
};
|
|
html += '</ul>';
|
|
|
|
$('#hisQuery').html(html);
|
|
$('#hisQuery [data-key]').on('click', function() {
|
|
var key = $(this).attr('data-key');
|
|
if (!!key && !!Public.his.queryObjs[key]) {
|
|
Query.newQuery(Public.his.queryObjs[key]);
|
|
}
|
|
});
|
|
|
|
Query.newQuery(Public.his.queryObjs[$('#hisQuery [data-key]:eq(0)').attr('data-key')]);
|
|
},
|
|
newQuery: function(obj) {
|
|
var el;
|
|
$('#query_form [type=checkbox],#query_form [type=radio]').prop("checked", false);
|
|
for (var k in obj) {
|
|
el = $('#query_form [name=' + k + ']');
|
|
if (el.length > 1) {
|
|
$('#query_form [name="' + k + '"][value="'+obj[k]+'"]').prop("checked", true);
|
|
} else {
|
|
el.val(obj[k]);
|
|
if(k=='startname'){
|
|
$('#startStation').html(obj[k]);
|
|
}else if (k=='endname') {
|
|
$('#endStation').html(obj[k]);
|
|
}else if (k=='start_date') {
|
|
var date = new Date(obj[k].replace(/\-/g,'/'));
|
|
$('#start_date').html(date.format('yyyy年M月d日') + ' ' + date.day(3));
|
|
Public.calendar.setCurDate(date);
|
|
}
|
|
}
|
|
};
|
|
var bak = $('#query_form [name=filters]').val(),
|
|
querys = bak.split('&');
|
|
|
|
Query.setFilter(querys);
|
|
},
|
|
setFilter:function(querys){
|
|
var arr = [],
|
|
el;
|
|
$('#filter_form [type=checkbox],#filter_form [type=radio]').prop("checked", false);
|
|
for (var i = 0; i < querys.length; i++) {
|
|
arr = querys[i].split('=');
|
|
arr[1] = decodeURIComponent(arr[1]);
|
|
el = $('#filter_form [name="' + arr[0] + '"][value="' + arr[1] + '"]');
|
|
|
|
if (arr[0] == 'train_type' || arr[0] == 'train_seat') {
|
|
el.prop("checked", true);
|
|
} else if (arr[0] == 'timeslot') {
|
|
el.prop("checked", true);
|
|
el.closest('.query_box').find('label').removeClass('query_bigcheck_checked');
|
|
el.closest('label').addClass('query_bigcheck_checked');
|
|
};
|
|
};
|
|
},
|
|
// setDate: function(date) {
|
|
// var date = date || (new Date()).date;
|
|
|
|
// $('#start_date').html(date.format('yyyy年M月d日') + ' ' + date.day(3));
|
|
// $('#start_date_val').val(date.format('yyyy-M-d'));
|
|
// 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));
|
|
// $('#start_date_val').val(checkDate.format('yyyy-M-d'));
|
|
// }
|
|
// });
|
|
|
|
// $('#start_date').on('click', function() {
|
|
// Public.showInnerPage('date_box');
|
|
// });
|
|
|
|
// $('[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();
|
|
// Public.hideInnerPage('date_box');
|
|
// $('#start_date').html(Query.calendar.curDate.format('yyyy年M月d日') + ' ' + Query.calendar.curDate.day(3));
|
|
// $('#start_date_val').val(Query.calendar.curDate.format('yyyy-M-d'));
|
|
// } else {
|
|
// var offset = $('a.cur', Query.calendar.wrap).offset();
|
|
// $('#date_tip').css({
|
|
// 'left': offset.left,
|
|
// 'top': offset.top,
|
|
// 'display': 'block'
|
|
// }).html('<p>' + date.format('M月d日') + '不在预售期</p><a href="#" class="btn btn_m btn_success">预约提醒</a>');
|
|
// 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();
|
|
}
|
|
|
|
} |