Light12306/Mobile12306New/js/remind.js

426 lines
12 KiB
JavaScript
Raw Normal View History

2014-09-01 13:50:43 +08:00
var Remind = {
sellTime: null,
loading: null,
init: function() {
2014-09-09 12:41:28 +08:00
try{
2014-09-01 13:50:43 +08:00
if ($('#remind_page').length == 0) {
return false;
}
2014-09-01 13:50:43 +08:00
Remind.deviceInfo = JSON.parse(bootStrap.device_info);
2014-09-05 21:03:19 +08:00
/* Remind.deviceInfo = {
2014-09-04 17:11:16 +08:00
'did':'020000000000|FFFFFFFF8C61465AA89F4FA78D8767DC0B7F531C',
'device_type':1
}; */
2014-09-09 12:41:28 +08:00
if (!Remind.deviceInfo) {
Remind.showLeibaoAD();
return;
2014-09-04 22:34:02 +08:00
}
2014-09-04 17:11:16 +08:00
$('#menu_btn').on('click', function() {
2014-09-09 12:41:28 +08:00
2014-09-05 15:19:17 +08:00
var _height;
2014-09-09 12:41:28 +08:00
2014-09-04 17:11:16 +08:00
$('#user_menu').toggle();
2014-09-09 12:41:28 +08:00
if ($(window).height() > $('body').height()) {
2014-09-05 15:19:17 +08:00
_height = $(window).height();
2014-09-09 12:41:28 +08:00
} else {
2014-09-05 15:19:17 +08:00
_height = $('body').height();
}
$('#user_menu').height(_height - 45);
2014-09-04 17:11:16 +08:00
});
$('#user_menu').on('click', function(e) {
if ($(e.target).attr('id') == 'user_menu') {
$('#user_menu').hide();
}
});
2014-09-01 13:50:43 +08:00
2014-09-04 17:11:16 +08:00
Public.checkLogin(Remind.hasLogin, Remind.noLogin, Remind.noLogin);
2014-09-01 13:50:43 +08:00
Remind.sellTime = WIN['sellTime'];
Remind.dataInit();
Remind.staionInt();
$('.query_box [type="checkbox"]').on('change', function() {
setTimeout(function() {
Remind.checkSubmit();
}, 50);
});
$('#remind_form').on('submit', function() {
Remind.remindSubmit();
return false;
});
2014-09-03 19:25:32 +08:00
var sch = Public.getQueryData(window.location.search);
2014-09-09 12:41:28 +08:00
if (!!sch['date'] && !isNaN((new Date(sch['date'].replace(/\-/gi, '/'))).getTime())) {
Remind.dateChangeCallback(new Date(sch['date'].replace(/\-/gi, '/')));
2014-09-03 19:25:32 +08:00
}
2014-09-09 12:41:28 +08:00
if (!!sch['from'] && CheckStaion.CodeObj[sch['from']]) {
Remind.startCallback(CheckStaion.CodeObj[sch['from']][1], CheckStaion.CodeObj[sch['from']][2]);
2014-09-03 19:25:32 +08:00
}
2014-09-09 12:41:28 +08:00
if (!!sch['to'] && CheckStaion.CodeObj[sch['to']]) {
Remind.endCallback(CheckStaion.CodeObj[sch['to']][1], CheckStaion.CodeObj[sch['to']][2]);
2014-09-03 19:25:32 +08:00
}
2014-09-04 17:11:16 +08:00
$('#login').on('click', function() {
if ($(this).attr('data-fn') == 'loginout') {
cn12306.loginOut(function() {
Public.toast('退出成功,正在跳转');
setTimeout(function() {
window.location.href = 'login.html';
}, 1000);
}, function() {
Public.toast('退出失败,请重试。');
});
}
});
2014-09-09 12:41:28 +08:00
}catch(e){
alert(e);
}
},
showLeibaoAD: function() {
var adUrl = 'http://dl.liebao.cn/android/fast/cheetah_2.11.0.apk',
iosUrl = 'https://itunes.apple.com/cn/app/id641522896',
downloadUrl = IsIOS ? iosUrl : adUrl,
lowerUA = UA.toLowerCase(),
IsLiebao = lowerUA.match(/LieBao/i) == 'liebao';
2014-09-09 12:41:28 +08:00
if (!((bootStrap.isIos && typeof __ksticket != 'undefined') || bootStrap.isAndroid)) {
if (IsLiebao) {
if (lowerUA.match(/LieBaoFast/i) == "liebaofast") {
Public.confirm('当前浏览器版本不支持提醒功能,请升级至最新版本', function() {
Public.updateAndroid();
Public.alert('升级成功后即可使用提醒功能', function() {
location.href = './';
});
}, '立即升级', function() {
location.href = './';
});
} else if (IsAndroid) {
$('body').prepend('<span class="update_notice"><a href="' + downloadUrl + '"><img src="images/update_lb.png"></a></span>').addClass('showBanner');
Public.confirm('提醒功能仅支持手机猎豹极速版本,点击升级开启提醒', function() {
Public.updateAndroid();
Public.alert('升级成功后即可使用提醒功能', function() {
location.href = './';
});
}, '立即升级', function() {
location.href = './';
});
} else {
Public.alert('当前浏览器版本不支持提醒功能,请升级至最新版本', function(){
Public.updateIos();
Public.alert('升级成功后即可使用提醒功能', function() {
location.href = './';
});
}, '立即升级', function() {
location.href = './';
});
}
} else {
// 非猎豹处理
// if(IsIOS){
// Client.tryOpenLB('lb://u/1/aHR0cDovL2FwcC5maXNobGVlLm5ldC8xMjMwNi9yZW1pbmQuaHRtbA==')
// }
$('body').prepend('<span class="update_notice"><a href="' + downloadUrl + '"><img src="images/update_all.png"></a></span>').addClass('showBanner');
Public.confirm('当前浏览器不支持预售提醒功能', function() {
IsIOS ? Public.updateIos() : Public.updateAndroid();
Public.alert('升级成功后即可使用提醒功能', function() {
location.href = './';
});
}, '立即下载', function() {
location.href = './';
});
}
}
2014-09-01 13:50:43 +08:00
},
2014-09-04 17:11:16 +08:00
hasLogin: function() {
$('#login').attr('href', 'javascript:;').attr('data-fn', 'loginout').html('退出');
$('#menu_btn .icon_user').addClass('icon_user2');
2014-09-01 13:50:43 +08:00
2014-09-04 17:11:16 +08:00
Query.setHisQuery();
Query.getPassenger();
},
noLogin: function() {
$('#login').attr('href', '/12306/login.html').attr('data-fn', 'login').html('登录');
$('#menu_btn .icon_user').removeClass('icon_user2');
Query.setHisQuery();
2014-09-01 13:50:43 +08:00
},
dataInit: function() {
2014-09-03 19:25:32 +08:00
var sch = Public.getQueryData(window.location.search),
maxDay = (new Date()).addDays(49);
2014-09-09 12:41:28 +08:00
if (!!sch['date'] && !isNaN((new Date(sch['date'].replace(/\-/gi, '/'))).getTime())) {
maxDay = (new Date(sch['date'].replace(/\-/gi, '/')));
2014-09-03 19:25:32 +08:00
// alert(maxDay)
// Remind.dateChangeCallback(new Date(sch['date'].replace(/\-/,'/')));
}
2014-09-01 13:50:43 +08:00
Public.setDate(maxDay);
Public.calendar.setSection((new Date()).addDays(20), 29);
Public.calendar.checkCallback = Remind.dateChangeCallback;
Public.calendar.setBasic();
},
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'));
}
},
staionInt: function() {
CheckStaion.init();
$('#startStation').on('click', function() {
CheckStaion.callback = Remind.startCallback;
CheckStaion.cancelCallback = Remind.cancelCallback;
CheckStaion.show();
$('#wrap').hide();
});
$('#endStation').on('click', function() {
CheckStaion.callback = Remind.endCallback;
CheckStaion.cancelCallback = Remind.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('出发站');
}
Remind.changeCity();
});
},
startCallback: function(name, code) {
$('#startStation').html(name);
$('#startStationName').val(name);
$('#startStationCode').val(code);
CheckStaion.hide();
$('#wrap').show();
Remind.changeCity();
},
endCallback: function(name, code) {
$('#endStation').html(name);
$('#endStationName').val(name);
$('#endStationCode').val(code);
CheckStaion.hide();
$('#wrap').show();
Remind.changeCity();
},
changeCity: function() {
Remind.checkSubmit();
if ($('.station [value=""]').length > 0) {
return false;
}
Remind.getTrains();
},
cancelCallback: function() {
$('#wrap').show();
},
trainsHis: {},
getTrains: function() {
var type = 'ADULT',
2014-09-03 19:25:32 +08:00
date = (new Date()).addDays(10).format('yyyy-MM-dd'),
2014-09-01 13:50:43 +08:00
from = $('#startStationCode').val(),
to = $('#endStationCode').val(),
key = from + to + date + type,
data = {
"leftTicketDTO.train_date": date,
"leftTicketDTO.from_station": from,
"leftTicketDTO.to_station": to,
"purpose_codes": type
};
2014-09-04 14:46:15 +08:00
Remind.checkType([]);
2014-09-01 13:50:43 +08:00
if (from == to) {
return;
}
if (!!Remind.trainsHis[key]) {
Remind.checkType(Remind.trainsHis[key]);
return;
}
Public.showLoading('正在查询数据')
2014-09-09 12:41:28 +08:00
cn12306.queryTicket(data, function(json) {
2014-09-01 13:50:43 +08:00
if (json["status"] == true && json["httpstatus"] == 200) {
if (json['data'].length > 0) {
Remind.trainsHis[key] = json['data'];
Remind.checkType(json['data']);
Public.hideLoading();
2014-09-09 12:41:28 +08:00
} else {
2014-09-04 14:46:15 +08:00
Remind.checkType([]);
Public.hideLoading();
2014-09-09 12:41:28 +08:00
Public.alert('没有找到从<strong>' + $('#startStationName').val() + '</strong>到<strong>' + $('#endStationName').val() + '</strong>的列车');
2014-09-01 13:50:43 +08:00
}
}
});
},
checkType: function(list) {
$('.query_box [type="checkbox"]').attr('disabled', 'disabled').prop('checked', false);
for (var i = 0, len = list.length; i < len; i++) {
if ($('.query_box [type="checkbox"]:checked').length > 2) {
$('.query_box [value="all"]').removeAttr('disabled').prop('checked', true);
break;
}
switch (list[i]['queryLeftNewDTO']['station_train_code'][0]) {
case "G":
$('.query_box [value="1"]').removeAttr('disabled').prop('checked', true);
break;
case "D":
case "C":
$('.query_box [value="2"]').removeAttr('disabled').prop('checked', true);
break;
default:
$('.query_box [value="3"]').removeAttr('disabled').prop('checked', true);
}
};
Remind.checkSubmit();
},
checkSubmit: function() {
if ($('.station [value=""]').length == 0 && $('[name="train_type"]:checked').length > 0 && $('#startStationCode').val() != $('#endStationCode').val()) {
$('#remind_btn').removeAttr('disabled').removeClass('btn_gray');
} else {
$('#remind_btn').attr('disabled', 'disabled').addClass('btn_gray');
};
},
remindSubmit: function() {
Remind.loading = Public.showLoading('正在预定');
var types = $('.query_box [type="checkbox"]:checked'),
text = '',
data = {
"device_id": Remind.deviceInfo['did'],
"device_type": Remind.deviceInfo['device_type'],
"fromCode": $('#startStationCode').val(),
"fromName": $('#startStationName').val(),
"toCode": $('#endStationCode').val(),
"toName": $('#endStationName').val(),
"date": $('#start_date_val').val(),
"tasks": []
},
d = data['date'].replace(/\-/g, '/'),
c = new Date(d),
times = [];
2014-09-03 19:25:32 +08:00
d = c.addDays(-19).format('yyyy/MM/dd');
2014-09-01 13:50:43 +08:00
types.each(function(idx, el) {
var val = $(el).val(),
time = Remind.sellTime[data['fromCode']];
2014-09-01 13:50:43 +08:00
if (val == 'all') {
return;
}
2014-09-01 13:50:43 +08:00
if (!time) {
time = Remind.sellTime[data['fromName']];
}
time = time.split('/');
switch (val) {
case '1':
times.push('14:00');
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' 14:00').getTime()) - 900000,
2014-09-04 17:18:45 +08:00
// "time": (new Date().getTime())+300000,
2014-09-01 13:50:43 +08:00
"left": 15,
"type": 1
});
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' 14:00').getTime()) - 3600000,
2014-09-04 17:18:45 +08:00
// "time": (new Date().getTime())+600000,
2014-09-01 13:50:43 +08:00
"left": 60,
"type": 1
});
break;
case '2':
times.push('11:00');
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' 11:00')).getTime() - 900000,
2014-09-04 17:18:45 +08:00
// "time": (new Date()).getTime()+300000,
2014-09-01 13:50:43 +08:00
"left": 15,
"type": 2
});
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' 11:00')).getTime() - 3600000,
2014-09-04 17:18:45 +08:00
// "time": (new Date()).getTime()+600000,
2014-09-01 13:50:43 +08:00
"left": 60,
"type": 2
});
break;
case '3':
for (var i = 0; i < time.length; i++) {
times.push(time[i]);
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' ' + time[i]).getTime()) - 900000,
2014-09-04 17:18:45 +08:00
// "time": (new Date().getTime())+300000,
2014-09-01 13:50:43 +08:00
"left": 15,
"type": 3
});
data['tasks'].push({
2014-09-09 12:41:28 +08:00
"time": (new Date(d + ' ' + time[i]).getTime()) - 3600000,
2014-09-04 17:18:45 +08:00
// "time": (new Date().getTime())+600000,
2014-09-01 13:50:43 +08:00
"left": 60,
"type": 3
});
};
2014-09-01 13:50:43 +08:00
break;
}
});
2014-09-09 12:41:28 +08:00
times.sort(function(a, b) {
2014-09-01 13:50:43 +08:00
return parseInt(a.split(':')[0]) > parseInt(b.split(':')[0]) ? 1 : -1;
});
times = times.join(',');
2014-09-04 21:48:13 +08:00
//text = '你预约的' + c.format('YYYY年M月d日') + '' + data['fromName'] + '至' + data['toName'] + '的火车票,将于' + c.addDays(-19).format('YYYY年M月d日') + times +'开售。售票开始前我们会提醒你。祝你抢票成功!';
text = '你会在' + c.addDays(-19).format('M月d日') + '收到【' + data['fromName'] + '-' + data['toName'] + '】火车票的开售提醒!';
2014-09-01 13:50:43 +08:00
$.ajax({
type: 'POST',
url: 'http://12306.liebao.cn/index.php?r=Api/SentRss',
data: {
data: JSON.stringify(data)
},
dataType: 'json',
success: function(data) {
Public.hideLoading(Remind.loading);
if (data['resCode'] == 0) {
Public.alert(text);
} else {
Public.alert(data['message']);
}
},
error: function() {
Public.hideLoading(Remind.loading);
Public.alert('预定失败');
}
});
}
}