841 lines
25 KiB
JavaScript
841 lines
25 KiB
JavaScript
var RunQuery = {
|
||
goRefer: false,
|
||
init: function() {
|
||
if ($('#runquery_page').length == 0) {
|
||
return false;
|
||
}
|
||
|
||
var maxDay = (new Date()).addDays(19);
|
||
Public.formatString = 'M月d日';
|
||
Public.setDate(maxDay);
|
||
Public.calendar.checkCallback = RunQuery.dateChangeCallback;
|
||
|
||
Public.checkLogin(RunQuery.run, RunQuery.run, RunQuery.run);
|
||
|
||
|
||
$('#filter_ok').on('click', function() {
|
||
Public.hideInnerPage('filter');
|
||
$('#query_form [name=filters]').val($('#filter_form').serialize());
|
||
RunQuery.setFilterCond();
|
||
RunQuery.hisUpdata();
|
||
if (RunQuery.goRefer) {
|
||
RunQuery.goRefer = false;
|
||
RunQuery.startRef();
|
||
}
|
||
});
|
||
$('#check_left,#check_right').on('click', function() {
|
||
RunQuery.hisUpdata();
|
||
});
|
||
|
||
$('#filter_cancel').on('click', function() {
|
||
Public.hideInnerPage('filter');
|
||
var bak = $('#query_form [name=filters]').val(),
|
||
querys = bak.split('&');
|
||
|
||
Query.setFilter(querys);
|
||
if (RunQuery.goRefer) {
|
||
RunQuery.goRefer = false;
|
||
RunQuery.startRef();
|
||
}
|
||
});
|
||
|
||
|
||
|
||
$('#filter_btn').on('click', function() {
|
||
Public.showInnerPage('filter');
|
||
});
|
||
|
||
$('#filter_cancel').on('click', function() {
|
||
Public.hideInnerPage();
|
||
});
|
||
|
||
|
||
$('[data-fn="buy"]').live('click', function() {
|
||
var train = $(this).attr('data-traincode'),
|
||
seat = $(this).attr('data-seatcode');
|
||
if (seat == '0' && $('[data-traincode="' + train + '"][data-seatcode="' + seat + '"]').length > 0) {
|
||
seat = '1';
|
||
}
|
||
sessionStorage.setItem(Public.user + 'curBuy', JSON.stringify(RunQuery.trainData.trainMap[train]));
|
||
sessionStorage.setItem(Public.user + 'curBuySeat', seat);
|
||
|
||
if (Public.isLogin) {
|
||
location.href = 'perfect.html';
|
||
} else {
|
||
Public.alert('还未登录,请登陆后购票', function() {
|
||
location.href = 'login.html?t=submitorder';
|
||
});
|
||
}
|
||
});
|
||
|
||
$('#autoTipBtn').live('click', function() {
|
||
|
||
if (Public.isLogin) {
|
||
RunQuery.goRefer = true;
|
||
Public.showInnerPage('filter');
|
||
// RunQuery.startRef();
|
||
} else {
|
||
window.location.href = 'login.html?t=autorefer';
|
||
}
|
||
});
|
||
$('#refresh_end').live('click', function() {
|
||
RunQuery.refStop();
|
||
});
|
||
|
||
},
|
||
run: function() {
|
||
Query.getPassenger();
|
||
RunQuery.getQueryData();
|
||
if (!RunQuery.curData) {
|
||
window.location.href = 'index.html';
|
||
return false;
|
||
}
|
||
RunQuery.setFilter();
|
||
RunQuery.queryTicket();
|
||
Query.filterBind();
|
||
},
|
||
curData: null,
|
||
getQueryData: function() {
|
||
if (!!Public.his.queryObjs[Public.his.querys[0][0]]) {
|
||
RunQuery.curData = Public.his.queryObjs[Public.his.querys[0][0]];
|
||
}
|
||
},
|
||
setFilter: function() {
|
||
Query.setFilter(RunQuery.curData['filters'].split('&'));
|
||
$('.station_title strong').html(RunQuery.curData['startname'] + '→' + RunQuery.curData['endname']);
|
||
$('#query_form [name=startname]').val(RunQuery.curData['startname']);
|
||
$('#query_form [name=startcode]').val(RunQuery.curData['startcode']);
|
||
$('#query_form [name=endname]').val(RunQuery.curData['endname']);
|
||
$('#query_form [name=endcode]').val(RunQuery.curData['endcode']);
|
||
$('#query_form [name=type]').val(RunQuery.curData['type']);
|
||
$('#query_form [name=filters]').val(RunQuery.curData['filters']);
|
||
|
||
var date = new Date(RunQuery.curData['start_date'].replace(/\-/g, '/'));
|
||
$('#start_date').html(date.format('M月d日') + ' ' + date.day(3));
|
||
$('#start_date_val').val(date.format('yyyy-MM-dd'));
|
||
Public.calendar.setCurDate(date);
|
||
RunQuery.setFilterCond();
|
||
},
|
||
queryTicket: function() {
|
||
Public.hideLoading();
|
||
var loading = Public.showLoading('正在查票'),
|
||
data = {
|
||
"leftTicketDTO.train_date": RunQuery.curData.start_date,
|
||
"leftTicketDTO.from_station": RunQuery.curData.startcode,
|
||
"leftTicketDTO.to_station": RunQuery.curData.endcode,
|
||
"purpose_codes": RunQuery.curData.type == "2" ? "0X00" : "ADULT"
|
||
};
|
||
$('#autoTip,#noLoginTip,#noTicket').hide();
|
||
cn12306.queryTicket(data, function(json) {
|
||
Public.hideLoading();
|
||
if (json["status"] == true && json["httpstatus"] == 200) {
|
||
if (json['data'].length > 0) {
|
||
RunQuery.trainData = RunQuery.formatJson(json);
|
||
if (typeof RunQuery.filterCond.train != 'undefined') {
|
||
for (var i = 0; i < RunQuery.filterCond.train.length; i++) {
|
||
if (typeof RunQuery.trainData.codeMap[RunQuery.filterCond.train[i]] == 'undefined') {
|
||
RunQuery.filterCond.train.splice(i, 1);
|
||
i--;
|
||
}
|
||
}
|
||
}
|
||
RunQuery.filterJson(RunQuery.trainData);
|
||
|
||
RunQuery.formatList();
|
||
} else {
|
||
$('.station_title span').html('共 0 趟列车');
|
||
$('#noTicket').html('暂无结果,没有找到从<strong>' + RunQuery.curData['startname'] + '</strong>到<strong>' + RunQuery.curData['endname'] + '</strong>的列车').show();
|
||
}
|
||
} else if (!json["status"] && !!json["messages"]) {
|
||
Public.alert(json["messages"][0] || '未知错误');
|
||
} else {
|
||
Public.alert('未知错误');
|
||
}
|
||
}, function(xhr, type) {
|
||
Public.hideLoading();
|
||
});
|
||
},
|
||
getHtml: function(lists) {
|
||
var html = '';
|
||
if (!lists || lists.length == 0) {
|
||
return html;
|
||
}
|
||
for (var k in lists) {
|
||
obj = lists[k];
|
||
html += '<li>';
|
||
/*第1行*/
|
||
html += '<div class="line no_border">';
|
||
html += '<strong class="pull_right text_underline text_lg" data-id="' + obj["id"] + '">' + obj["code"] + '</strong>';
|
||
html += '<strong class="text_warning text_lg link_label">' + obj["from"]["time"] + '</strong>';
|
||
html += '<span class="text_lg">';
|
||
if (obj["from"]["code"] == obj["start"]["code"]) {
|
||
html += '<i class="text_label">始</i>';
|
||
}
|
||
html += obj["from"]["name"] + '</span>';
|
||
html += '</div>';
|
||
|
||
/*第2行*/
|
||
html += '<div class="line">';
|
||
|
||
ls = obj["elapsedTime"]['total'].split(':');
|
||
html += '<span class="pull_right text_gray">' + (!!ls[0] ? ls[0] + '小时' : '') + (!!ls[1] ? ls[1] + '分' : '0分') + '</span>';
|
||
html += '<span class="text_lg link_label">';
|
||
html += obj["to"]["time"] + '</span>';
|
||
html += '<span class="text_lg">'
|
||
if (obj["to"]["code"] == obj["end"]["code"]) {
|
||
html += '<i class="text_label">终</i>';
|
||
}
|
||
html += obj["to"]["name"] + '</span>';
|
||
html += '</div>';
|
||
|
||
/*输出席别*/
|
||
for (var i = 0; i < obj['ticketMapSort'].length; i++) {
|
||
if (obj['ticketMapSort'][i]["count"] == 0 && !RunQuery.trainData['isMaintain']) {
|
||
continue;
|
||
}
|
||
html += '<div class="line"><span class="pull_right">';
|
||
if (obj['ticketMapSort'][i]["count"] == '有') {
|
||
html += '<span class="text_warning">有</span>';
|
||
} else {
|
||
html += '<span class="text_warning">' + obj['ticketMapSort'][i]["count"] + '</span>';
|
||
html += '<span class="text_gray">张</span>';
|
||
}
|
||
if (!RunQuery.trainData['isMaintain']) {
|
||
html += '<a href="javascript:;" class="btn btn_success" data-fn="buy" data-traincode="' + obj["id"] + '" data-seatcode="' + obj['ticketMapSort'][i]["code"] + '">抢票</a>';
|
||
} else {
|
||
html += '<span href="javascript:;" class="btn btn_gray">维护</span>';
|
||
}
|
||
html += '</span>';
|
||
html += '<span class="link_label">' + obj['ticketMapSort'][i]['name'] + '</span>';
|
||
if((obj['ticketMapSort'][i]['price'] / 10) > 0){
|
||
html += '<span class="text_gray">' + (obj['ticketMapSort'][i]['price'] / 10) + '元</span>';
|
||
}
|
||
html += '</div>';
|
||
};
|
||
|
||
html += '</li>';
|
||
};
|
||
return html;
|
||
},
|
||
formatList: function() {
|
||
// var lists = RunQuery.trainData.trainMap,
|
||
var lists = RunQuery.trainData.train,
|
||
html = '',
|
||
obj = {};
|
||
if (RunQuery.trainData['isMaintain']) {
|
||
lists = RunQuery.trainData.trainMap;
|
||
}
|
||
|
||
$('#train_list').html(RunQuery.getHtml(lists));
|
||
|
||
$('.station_title span').html('共 ' + $('#train_list li').length + ' 趟列车');
|
||
|
||
|
||
if (!RunQuery.trainData['isMaintain'] && Object.keys(RunQuery.trainData.train).length == 0) {
|
||
RunQuery.showRefresh();
|
||
} else if (!RunQuery.trainData['isMaintain'] && RunQuery.refresh) {
|
||
Client.refreshSuccess();
|
||
RunQuery.refStop();
|
||
RunQuery.autoSubmit();
|
||
} else {
|
||
$('#autoTip').hide();
|
||
}
|
||
},
|
||
autoSubmit: function() {
|
||
var btn = $('#train_list li [data-fn="buy"]').eq(0),
|
||
box = btn.closest('li');
|
||
if (bootStrap.isAndroid) {
|
||
var d = {
|
||
title: '恭喜你,刷出票了!',
|
||
content: '你订的 ' + $('[data-id]').html() + ' 次列车有【' + btn.closest('.line').find('.link_label').eq(0).html() + '】了!',
|
||
confirm: 'confirmCallback',
|
||
cancel: 'cancelCallback'
|
||
}
|
||
try {
|
||
__TicketJavaScriptObject__.confirm(JSON.stringify(d));
|
||
} catch (e) {
|
||
alert(e);
|
||
}
|
||
} else {
|
||
btn.click();
|
||
}
|
||
},
|
||
getTicketInfo: function(v) {
|
||
var data = [],
|
||
info = v.indexOf("#") === -1 ? v : /getSelected\(['"](.*?)['"]\)/i.exec(v)[1].split('#')[11],
|
||
match = info.match(/([A-Z\d])0*?([\*\d]{5})0*?(\d{4})/gi);
|
||
|
||
for (var j in match) {
|
||
var m = /([A-Z\d])0*?([\*\d]{5})0*?(\d{4})/i.exec(match[j]);
|
||
var sc = m[1];
|
||
var sp = m[2][0] == '*' ? null : parseInt(m[2], 10);
|
||
var st = parseInt(m[3], 10);
|
||
var seat = {
|
||
code: sc,
|
||
name: Util.toSeatTypeName(sc),
|
||
price: sp
|
||
};
|
||
if (st < 3000) {
|
||
seat.count = st;
|
||
|
||
//TODO 二等软座提交是否和二等座一样都用的MO?
|
||
//一等软座 7, 二等软座 8
|
||
if (sc === "7") {
|
||
data.push({
|
||
code: 'M',
|
||
name: Util.toSeatTypeName('M'),
|
||
price: sp,
|
||
count: st
|
||
});
|
||
} else if (sc === "8") {
|
||
data.push({
|
||
code: 'O',
|
||
name: Util.toSeatTypeName('O'),
|
||
price: sp,
|
||
count: st
|
||
});
|
||
} else {
|
||
data.push(seat);
|
||
}
|
||
} else {
|
||
seat.count = st - 3000;
|
||
seat.code = '0';
|
||
seat.name = "无座";
|
||
data.push(seat);
|
||
}
|
||
};
|
||
return data;
|
||
},
|
||
trainData: null,
|
||
formatJson: function(data) {
|
||
if (!Array.isArray(data['data']) && !data['data'].length) {
|
||
return null;
|
||
}
|
||
var lists = data['data'],
|
||
train, kp, selltimem, trainData = {
|
||
raw: data,
|
||
rawTrainMap: {},
|
||
trainMap: {},
|
||
codeMap: {},
|
||
auto: null,
|
||
nextTime: null
|
||
};
|
||
|
||
for (var i = 0; i < lists.length; i++) {
|
||
t = lists[i];
|
||
train = {
|
||
"id": t["queryLeftNewDTO"]["train_no"],
|
||
"code": t["queryLeftNewDTO"]["station_train_code"],
|
||
"available": t["queryLeftNewDTO"]["canWebBuy"] === 'Y' ? 1 : 0,
|
||
"start": {
|
||
"code": t["queryLeftNewDTO"]['start_station_telecode'],
|
||
"name": t["queryLeftNewDTO"]["start_station_name"]
|
||
},
|
||
"from": {
|
||
"code": t["queryLeftNewDTO"]['from_station_telecode'],
|
||
"fromStationNo": t["queryLeftNewDTO"]['from_station_no'],
|
||
"name": t["queryLeftNewDTO"]['from_station_name'],
|
||
"endpoint": t["queryLeftNewDTO"]['from_station_telecode'] == t["queryLeftNewDTO"]['start_station_telecode'],
|
||
"time": t["queryLeftNewDTO"]['start_time']
|
||
},
|
||
"to": {
|
||
"code": t["queryLeftNewDTO"]['to_station_telecode'],
|
||
"toStationNo": t["queryLeftNewDTO"]['to_station_no'],
|
||
"name": t["queryLeftNewDTO"]['to_station_name'],
|
||
"endpoint": t["queryLeftNewDTO"]['end_station_telecode'] == t["queryLeftNewDTO"]['to_station_telecode'],
|
||
"time": t["queryLeftNewDTO"]['arrive_time']
|
||
},
|
||
"elapsedTime": {
|
||
"days": t["queryLeftNewDTO"]['day_difference'],
|
||
"total": t["queryLeftNewDTO"]['lishi']
|
||
},
|
||
"end": {
|
||
"code": t["queryLeftNewDTO"]['end_station_telecode'],
|
||
"name": t["queryLeftNewDTO"]['end_station_name']
|
||
},
|
||
"ypinfo": t["queryLeftNewDTO"]['yp_info'],
|
||
"ypinfo_ex": t["queryLeftNewDTO"]['yp_ex'],
|
||
"locationCode": t["queryLeftNewDTO"]['location_code'],
|
||
"controlDay": t["queryLeftNewDTO"]['control_day'],
|
||
"supportCard": t["queryLeftNewDTO"]['is_support_card'],
|
||
"saleTime": t["queryLeftNewDTO"]['sale_time'],
|
||
"secureStr": t['secretStr'],
|
||
"selltime": null,
|
||
"date": t["queryLeftNewDTO"]['start_train_date'].replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3"),
|
||
"form_train_date": RunQuery.curData.start_date,
|
||
"limitSellInfo": t['buttonTextInfo'] && t['buttonTextInfo'].indexOf("暂售") != -1 ? t['buttonTextInfo'].replace(/<[^>]+>/i, "") : null
|
||
};
|
||
|
||
|
||
kp = RunQuery.getTicketInfo(t["queryLeftNewDTO"]['yp_info']);
|
||
train.tickets = kp;
|
||
train.ticketMap = Util.mapObject(kp, function(e) {
|
||
return e.code;
|
||
});
|
||
if (!!RunQuery.filterCond['train_seat'] && RunQuery.filterCond['train_seat'].length > 0) {
|
||
train.ticketMapSort = Util.sortType(train.ticketMap, RunQuery.filterCond['train_seat']);
|
||
} else {
|
||
train.ticketMapSort = Util.sortType(train.ticketMap);
|
||
}
|
||
// for (var i = 0; i < train.ticketMapSort.length; i++) {
|
||
// if(train.ticketMapSort[i]['count'] == 0){
|
||
// train.ticketMapSort.splice(i,1);
|
||
// i--;
|
||
// }
|
||
// };
|
||
// //起售时间
|
||
selltimem = /(0*(\d+)月0*(\d+)日)?(\d+)\s*点\s*((\d+)分)?\s*起售/i.exec(t.buttonTextInfo.replace(/<.*?>/g, ''));
|
||
if (selltimem) {
|
||
train.available = -1;
|
||
train.selltime = new Date();
|
||
train.selltime.setHours(parseInt(selltimem[4]));
|
||
train.selltime.setMinutes(parseInt(selltimem[6] || "0", 10));
|
||
train.selltime.setSeconds(0);
|
||
if (selltimem[1]) {
|
||
//带日期
|
||
train.selltime.setMonth(parseInt(selltimem[2]) - 1);
|
||
train.selltime.setDate(parseInt(selltimem[3]));
|
||
if (train.selltime.getMonth() < new Date().getMonth()) {
|
||
train.selltime.setFullYear(train.selltime.getFullYear() + 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
trainData.rawTrainMap[train['id']] = t;
|
||
trainData.codeMap[train['code']] = t;
|
||
trainData.trainMap[train['id']] = train;
|
||
|
||
};
|
||
if (lists.length > 0) {
|
||
trainData["isMaintain"] = lists[0]['buttonTextInfo'].indexOf("系统维护时间") != -1
|
||
}
|
||
return trainData;
|
||
},
|
||
filterCond: {},
|
||
setFilterCond: function() {
|
||
RunQuery.filterCond = {};
|
||
|
||
var arr = $('#filter_form').serializeArray();
|
||
for (var i = 0; i < arr.length; i++) {
|
||
if (!RunQuery.filterCond[arr[i]['name']]) {
|
||
RunQuery.filterCond[arr[i]['name']] = [];
|
||
}
|
||
RunQuery.filterCond[arr[i]['name']].push(arr[i]['value']);
|
||
};
|
||
if (!!RunQuery.filterCond['train_type']) {
|
||
RunQuery.filterCond['train_type'] = RunQuery.filterCond['train_type'].join('|').split('|');
|
||
}
|
||
},
|
||
hasTrains: function(list) {
|
||
var obj = {},
|
||
b = false;
|
||
for (var k in list) {
|
||
b = false;
|
||
for (var i = 0; i < list[k]['ticketMapSort'].length; i++) {
|
||
if (list[k]['ticketMapSort'][i]['count'] > 0) {
|
||
b = true;
|
||
break;
|
||
}
|
||
}
|
||
if (b) {
|
||
obj[k] = list[k];
|
||
}
|
||
};
|
||
return obj;
|
||
},
|
||
|
||
/**
|
||
* 车次筛选
|
||
* @param {Object} list 车次list
|
||
* @param {Array} trainFilter 筛选车次列表,(可选);
|
||
* @return {Object} 筛选后车次列表
|
||
*/
|
||
trainsFilter: function(list, trainFilter) {
|
||
var obj = {},
|
||
trainFilter = trainFilter || RunQuery.filterCond.train;
|
||
if (typeof trainFilter == 'undefined' || trainFilter.length == 0) {
|
||
return list;
|
||
}
|
||
for (var k in list) {
|
||
if (trainFilter.indexOf(list[k]['code']) != -1) {
|
||
obj[k] = list[k];
|
||
}
|
||
};
|
||
return obj;
|
||
},
|
||
trainsType: function(list) {
|
||
if (typeof RunQuery.filterCond['train_type'] == 'undefined' || RunQuery.filterCond['train_type'][0] == 'all') {
|
||
return list;
|
||
}
|
||
var obj = {};
|
||
for (var k in list) {
|
||
if (RunQuery.filterCond['train_type'].indexOf(list[k]['code'][0]) != -1 || (!isNaN(list[k]['code'][0]) && RunQuery.filterCond['train_type'].indexOf('QT') != -1)) {
|
||
obj[k] = list[k];
|
||
}
|
||
};
|
||
return obj;
|
||
},
|
||
trainsSeat: function(list) {
|
||
if (typeof RunQuery.filterCond['train_seat'] == 'undefined' || RunQuery.filterCond['train_seat'][0] == 'all') {
|
||
return list;
|
||
}
|
||
var obj = {},
|
||
b = false;
|
||
for (var k in list) {
|
||
b = false;
|
||
for (var i = 0; i < RunQuery.filterCond['train_seat'].length; i++) {
|
||
if (typeof list[k].ticketMap[RunQuery.filterCond['train_seat'][i]] != 'undefined' && list[k].ticketMap[RunQuery.filterCond['train_seat'][i]]['count'] > 0) {
|
||
b = true;
|
||
break;
|
||
};
|
||
};
|
||
if (b) {
|
||
obj[k] = list[k];
|
||
}
|
||
};
|
||
return obj;
|
||
},
|
||
trainsTime: function(list) {
|
||
if (typeof RunQuery.filterCond['timeslot'] == 'undefined' || RunQuery.filterCond['timeslot'][0] == '0') {
|
||
return list;
|
||
}
|
||
var obj = {},
|
||
t = -1;
|
||
|
||
for (var k in list) {
|
||
// t = parseInt(list[k]['from']['time'].split(':')[0]);
|
||
if (RunQuery.atTime(list[k])) {
|
||
obj[k] = list[k];
|
||
}
|
||
};
|
||
|
||
return obj;
|
||
},
|
||
atTime: function(obj) {
|
||
if (typeof RunQuery.filterCond['timeslot'] == 'undefined' || RunQuery.filterCond['timeslot'][0] == '0') {
|
||
return true;
|
||
}
|
||
var t = obj['from']['time'].split(':'),
|
||
d = false,
|
||
min = null,
|
||
max = null,
|
||
date = new Date();
|
||
// alert(t);
|
||
date.setHours(t[0]);
|
||
// console.log(date);
|
||
date.setMinutes(t[1]);
|
||
// console.log(date);
|
||
date = date.getTime();
|
||
// console.log(date);
|
||
|
||
for (var i = 0; i < RunQuery.filterCond['timeslot'].length; i++) {
|
||
min = new Date();
|
||
max = new Date();
|
||
min.setMinutes(0);
|
||
max.setMinutes(0);
|
||
|
||
switch (RunQuery.filterCond['timeslot'][i]) {
|
||
case '1':
|
||
min.setHours(0);
|
||
max.setHours(6);
|
||
console.log(date,min.getTime(),max.getTime());
|
||
if (date >= min.getTime() && date <= max.getTime()) {
|
||
d = true;
|
||
}
|
||
break;
|
||
case '2':
|
||
min.setHours(6);
|
||
max.setHours(12);
|
||
console.log(date,min.getTime(),max.getTime());
|
||
if (date >= min.getTime() && date <= max.getTime()) {
|
||
d = true;
|
||
}
|
||
break;
|
||
case '3':
|
||
min.setHours(12);
|
||
max.setHours(18);
|
||
console.log(date,min.getTime(),max.getTime());
|
||
if (date >= min.getTime() && date <= max.getTime()) {
|
||
d = true;
|
||
}
|
||
break;
|
||
case '4':
|
||
min.setHours(18);
|
||
max.setHours(24);
|
||
console.log(date,min.getTime(),max.getTime());
|
||
if (date >= min.getTime() && date <= max.getTime()) {
|
||
d = true;
|
||
}
|
||
break;
|
||
default:
|
||
d = true;
|
||
};
|
||
|
||
if (d) {
|
||
// alert('min:'+min);
|
||
// alert('date:'+new Date(date));
|
||
// alert('max:'+max);
|
||
break;
|
||
}
|
||
}
|
||
return d;
|
||
},
|
||
filterJson: function(json) {
|
||
var date = {};
|
||
json.train = RunQuery.hasTrains(json.trainMap);
|
||
json.train = RunQuery.trainsFilter(json.train);
|
||
json.train = RunQuery.trainsType(json.train);
|
||
json.train = RunQuery.trainsSeat(json.train);
|
||
json.train = RunQuery.trainsTime(json.train);
|
||
},
|
||
dateChangeCallback: function(date) {
|
||
var time = date.date.getTime();
|
||
if (time >= Public.calendar.minDate.date.getTime() && time <= Public.calendar.maxDate.date.getTime()) {
|
||
$('#date_tip').hide();
|
||
Public.hideInnerPage('date_box');
|
||
$('#start_date').html(Public.calendar.curDate.format(Public.formatString) + ' ' + Public.calendar.curDate.day(3));
|
||
$('#start_date_val').val(Public.calendar.curDate.format('yyyy-MM-dd'));
|
||
RunQuery.hisUpdata();
|
||
} else {
|
||
var offset = $('a.cur', Public.calendar.wrap).offset(),
|
||
str = '';
|
||
|
||
str = '<p>' + date.format('M月d日') + '不在预售期</p><a href="remind.html?date=' + encodeURIComponent(date.format('yyyy-MM-dd'));
|
||
if ($('#startStationCode').length > 0 && $('#startStationCode').val() != '') {
|
||
str += '&from=' + $('#startStationCode').val();
|
||
}
|
||
if ($('#endStationCode').length > 0 && $('#endStationCode').val() != '') {
|
||
str += '&to=' + $('#endStationCode').val();
|
||
}
|
||
str += '" class="btn btn_m btn_success">预约提醒</a>';
|
||
$('#date_tip').css({
|
||
'left': offset.left,
|
||
'top': offset.top,
|
||
'display': 'block'
|
||
}).html(str);
|
||
|
||
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');
|
||
}
|
||
}
|
||
},
|
||
hisUpdata: function() {
|
||
Public.setHisQuery($('#startStationCode').val() + '-' + $('#endStationCode').val(), $('#query_form').serialize());
|
||
Public.setHis();
|
||
RunQuery.getQueryData();
|
||
RunQuery.queryTicket();
|
||
},
|
||
showRefresh: function() {
|
||
if (RunQuery.refresh) {
|
||
return;
|
||
}
|
||
if (Public.isLogin) {
|
||
$('#autoTip p').html('暂时无票!<br>没有符合你要求的车次和席别');
|
||
} else {
|
||
$('#autoTip p').html('暂时无票!<br>登录后可以自动刷票');
|
||
}
|
||
$('#autoTip').show();
|
||
|
||
var srch = Public.getQueryData(window.location.search);
|
||
if (!!srch.t && srch.t == 'autorefer') {
|
||
history.replaceState(null, null, WIN.location.href.split('?')[0]);
|
||
$('#autoTipBtn').click();
|
||
}
|
||
},
|
||
refCount: 0,
|
||
startDate: null,
|
||
refDate: null,
|
||
refresh: false,
|
||
refTimer: null,
|
||
startRef: function() {
|
||
|
||
if (RunQuery.refresh) {
|
||
return;
|
||
}
|
||
Client.refreshStart();
|
||
RunQuery.startDate = (new Date()).getTime();
|
||
RunQuery.refDate = RunQuery.startDate;
|
||
RunQuery.refresh = true;
|
||
$('#refresh_train').show();
|
||
$('#autoTip').hide();
|
||
RunQuery.queryTicket();
|
||
RunQuery.refCount = 1;
|
||
RunQuery.refGo();
|
||
},
|
||
refGo: function() {
|
||
|
||
if (RunQuery.refresh) {
|
||
var now = (new Date()).getTime();
|
||
var useTime = RunQuery.formatTime(now - RunQuery.startDate);
|
||
var surplus = ((5000 - (now - RunQuery.refDate)) / 1000).toFixed(1);
|
||
if (surplus <= 0) {
|
||
surplus = 0;
|
||
}
|
||
$('#refresh_train .rf_desc').html('已刷 ' + RunQuery.refCount + ' 次,用时 ' + useTime + '<br>距下次刷票还有 ' + surplus + ' 秒 ...');
|
||
if (surplus == 0) {
|
||
RunQuery.refDate = now;
|
||
RunQuery.refCount++;
|
||
RunQuery.queryTicket();
|
||
}
|
||
if (RunQuery.refCount > 2) {
|
||
|
||
}
|
||
RunQuery.refTimer = setTimeout(RunQuery.refGo, 100);
|
||
}
|
||
},
|
||
refStop: function() {
|
||
Client.refreshEnd();
|
||
clearTimeout(RunQuery.refTimer);
|
||
RunQuery.refresh = false;
|
||
$('#refresh_train').hide();
|
||
// RunQuery.queryTicket();
|
||
if (Object.keys(RunQuery.trainData.train).length == 0) {
|
||
RunQuery.showRefresh();
|
||
}
|
||
},
|
||
formatTime: function(t) {
|
||
var m = parseInt(t / 60000);
|
||
var s = parseInt(t % 60000 / 1000);
|
||
return m + '分' + s + '秒';
|
||
},
|
||
getRec: function() {
|
||
var data = {},
|
||
list = RunQuery.trainData['trainMap'];
|
||
|
||
data["key"] = "stupid360";
|
||
data["from"] = $('#startStationCode').val();
|
||
data["to"] = $('#endStationCode').val();
|
||
data["date"] = $('#start_date_val').val();
|
||
|
||
|
||
data['stops'] = {};
|
||
for (var k in list) {
|
||
data['stops'][list[k]['code']] = {};
|
||
data['stops'][list[k]['code']]['info'] = list[k];
|
||
data['stops'][list[k]['code']]['stops'] = cn12306.byTrainNos[k];
|
||
};
|
||
|
||
var data = JSON.stringify(data);
|
||
(0, eval)('this').v = data;
|
||
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: 'http://12306.fishlee.net/ts?key=stupid360&r=' + Math.random(),
|
||
data: {
|
||
data: data
|
||
},
|
||
success: function(json) {
|
||
if (!!json['groups'] && json['groups'].length > 0) {
|
||
RunQuery.setRec(json['groups']);
|
||
}
|
||
},
|
||
error: function(xhr, type) {
|
||
|
||
}
|
||
})
|
||
},
|
||
setRec: function(groups) {
|
||
if (!groups || groups.length == 0) {
|
||
return;
|
||
}
|
||
var queryData = {},
|
||
date = $('#start_date_val').val(),
|
||
purpose_codes = RunQuery.curData.type == "2" ? "0X00" : "ADULT",
|
||
k = '',
|
||
arr = [],
|
||
data, d;
|
||
|
||
for (var i = 0; i < groups.length; i++) {
|
||
if (CheckStaion.zhObj[groups[i]['fromText']] && CheckStaion.zhObj[groups[i]['toText']]) {
|
||
for (var j = 0; j < groups[i]['lines'].length; j++) {
|
||
data = {};
|
||
d = groups[i]['date'];
|
||
|
||
if (groups[i]['lines'][j]['isCrossDate']) {
|
||
d = groups[i]['lines']['j']['form']['date'].split('T')[0];
|
||
}
|
||
|
||
k = CheckStaion.zhObj[groups[i]['fromText']][2] + CheckStaion.zhObj[groups[i]['toText']][2] + d;
|
||
|
||
if (!queryData[k]) {
|
||
queryData[k] = {};
|
||
queryData[k]['filterTicket'] = [];
|
||
queryData[k]['queryData'] = {
|
||
'leftTicketDTO.train_date': d,
|
||
'leftTicketDTO.from_station': CheckStaion.zhObj[groups[i]['fromText']][2],
|
||
'leftTicketDTO.to_station': CheckStaion.zhObj[groups[i]['toText']][2],
|
||
'purpose_codes': purpose_codes
|
||
}
|
||
}
|
||
|
||
queryData[k]['filterTicket'].push(groups[i]['lines'][j]['trainCode']);
|
||
};
|
||
|
||
}
|
||
};
|
||
|
||
for (var k in queryData) {
|
||
arr.push(queryData[k]);
|
||
};
|
||
RunQuery.queryRec(arr, function() {
|
||
var html = '';
|
||
for (var i = 0; i < RunQuery.recData.length; i++) {
|
||
html += RunQuery.getHtml(RunQuery.recData[i]['train']);
|
||
};
|
||
});
|
||
},
|
||
recData: [],
|
||
queryRec: function(queryData, callback) {
|
||
var data = [],
|
||
qd = queryData.shift(),
|
||
ticket = qd['filterTicket'];
|
||
cn12306.queryTicket(qd['queryData'], function(json) {
|
||
|
||
if (json["status"] == true && json["httpstatus"] == 200) {
|
||
if (json['data'].length > 0) {
|
||
var trainData = RunQuery.formatJson(json);
|
||
|
||
for (var j = 0; j < ticket.length; j++) {
|
||
if (typeof trainData.codeMap[ticket[j]] == 'undefined') {
|
||
ticket.splice(j, 1);
|
||
j--;
|
||
}
|
||
}
|
||
|
||
// trainData.hasTrains = RunQuery.hasTrains(trainData.trainMap);
|
||
// trainData.train = RunQuery.trainsFilter(trainData.hasTrains, ticket);
|
||
// trainData.trainsType = RunQuery.trainsType(trainData.train);
|
||
// trainData.trainsSeat = RunQuery.trainsSeat(trainData.trainsType);
|
||
// trainData.train = trainData.trainsSeat;
|
||
RunQuery.filterJson(trainData);
|
||
RunQuery.recData.push(trainData);
|
||
|
||
if (queryData.length > 0) {
|
||
RunQuery.queryRec(queryData, callback);
|
||
} else if (typeof callback == 'function') {
|
||
callback(RunQuery.recData);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}, function(xhr, type) {
|
||
if (typeof callback == 'function') {
|
||
callback(RunQuery.recData);
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
}
|
||
|
||
window['confirmCallback'] = function() {
|
||
$('#train_list li [data-fn="buy"]').eq(0).click();
|
||
}
|
||
window['cancelCallback'] = function() {
|
||
|
||
} |