2014-09-01 13:50:43 +08:00
|
|
|
|
var Remind = {
|
|
|
|
|
sellTime: null,
|
|
|
|
|
loading: null,
|
|
|
|
|
init: function() {
|
|
|
|
|
if ($('#remind_page').length == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-09-04 18:33:53 +08:00
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
Remind.deviceInfo = JSON.parse(bootStrap.device_info);
|
2014-09-04 17:11:16 +08:00
|
|
|
|
/* Remind.deviceInfo = {
|
|
|
|
|
'did':'020000000000|FFFFFFFF8C61465AA89F4FA78D8767DC0B7F531C',
|
|
|
|
|
'device_type':1
|
|
|
|
|
}; */
|
2014-09-01 13:50:43 +08:00
|
|
|
|
if(!Remind.deviceInfo){
|
|
|
|
|
Public.alert('订阅功能仅请使用手机猎豹浏览器',function(){
|
|
|
|
|
window.history.back();
|
|
|
|
|
});
|
|
|
|
|
return ;
|
2014-09-04 22:34:02 +08:00
|
|
|
|
}
|
2014-09-04 18:41:23 +08:00
|
|
|
|
|
2014-09-04 17:11:16 +08:00
|
|
|
|
$('#menu_btn').on('click', function() {
|
2014-09-05 15:19:17 +08:00
|
|
|
|
|
|
|
|
|
var _height;
|
|
|
|
|
|
2014-09-04 17:11:16 +08:00
|
|
|
|
$('#user_menu').toggle();
|
2014-09-05 15:19:17 +08:00
|
|
|
|
if($(window).height() > $('body').height()){
|
|
|
|
|
_height = $(window).height();
|
|
|
|
|
}else{
|
|
|
|
|
_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-04 18:41:23 +08:00
|
|
|
|
});
|
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-04 18:33:53 +08:00
|
|
|
|
|
2014-09-03 19:25:32 +08:00
|
|
|
|
if(!!sch['date'] && !isNaN((new Date(sch['date'].replace(/\-/gi,'/'))).getTime())){
|
|
|
|
|
Remind.dateChangeCallback(new Date(sch['date'].replace(/\-/gi,'/')));
|
|
|
|
|
}
|
2014-09-04 18:33:53 +08:00
|
|
|
|
|
2014-09-03 19:25:32 +08:00
|
|
|
|
if(!!sch['from'] && CheckStaion.CodeObj[sch['from']]){
|
|
|
|
|
Remind.startCallback(CheckStaion.CodeObj[sch['from']][1],CheckStaion.CodeObj[sch['from']][2]);
|
|
|
|
|
}
|
|
|
|
|
if(!!sch['to'] && CheckStaion.CodeObj[sch['to']]){
|
|
|
|
|
Remind.endCallback(CheckStaion.CodeObj[sch['to']][1],CheckStaion.CodeObj[sch['to']][2]);
|
|
|
|
|
}
|
2014-09-04 18:34:15 +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-04 18:41:23 +08:00
|
|
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
|
if(!!sch['date'] && !isNaN((new Date(sch['date'].replace(/\-/gi,'/'))).getTime())){
|
|
|
|
|
maxDay = (new Date(sch['date'].replace(/\-/gi,'/')));
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
2014-09-04 18:41:23 +08:00
|
|
|
|
Public.showLoading('正在查询数据')
|
2014-09-01 13:50:43 +08:00
|
|
|
|
cn12306.queryTicket(data,function(json) {
|
|
|
|
|
if (json["status"] == true && json["httpstatus"] == 200) {
|
|
|
|
|
if (json['data'].length > 0) {
|
|
|
|
|
Remind.trainsHis[key] = json['data'];
|
|
|
|
|
Remind.checkType(json['data']);
|
2014-09-04 18:33:53 +08:00
|
|
|
|
Public.hideLoading();
|
2014-09-03 17:09:04 +08:00
|
|
|
|
}else{
|
2014-09-04 14:46:15 +08:00
|
|
|
|
Remind.checkType([]);
|
2014-09-04 18:41:23 +08:00
|
|
|
|
Public.hideLoading();
|
2014-09-03 17:09:04 +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-04 18:33:53 +08:00
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
if (val == 'all') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-09-04 18:33:53 +08:00
|
|
|
|
|
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-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' 14:00').getTime())-900000,
|
|
|
|
|
// "time": (new Date().getTime())+300000,
|
2014-09-01 13:50:43 +08:00
|
|
|
|
"left": 15,
|
|
|
|
|
"type": 1
|
|
|
|
|
});
|
|
|
|
|
data['tasks'].push({
|
2014-09-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' 14:00').getTime())-3600000,
|
|
|
|
|
// "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-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' 11:00')).getTime()-900000,
|
|
|
|
|
// "time": (new Date()).getTime()+300000,
|
2014-09-01 13:50:43 +08:00
|
|
|
|
"left": 15,
|
|
|
|
|
"type": 2
|
|
|
|
|
});
|
|
|
|
|
data['tasks'].push({
|
2014-09-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' 11:00')).getTime()-3600000,
|
|
|
|
|
// "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-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' ' + time[i]).getTime())-900000,
|
|
|
|
|
// "time": (new Date().getTime())+300000,
|
2014-09-01 13:50:43 +08:00
|
|
|
|
"left": 15,
|
|
|
|
|
"type": 3
|
|
|
|
|
});
|
|
|
|
|
data['tasks'].push({
|
2014-09-04 17:18:45 +08:00
|
|
|
|
"time": (new Date(d + ' ' + time[i]).getTime())-3600000,
|
|
|
|
|
// "time": (new Date().getTime())+600000,
|
2014-09-01 13:50:43 +08:00
|
|
|
|
"left": 60,
|
|
|
|
|
"type": 3
|
|
|
|
|
});
|
|
|
|
|
};
|
2014-09-04 18:33:53 +08:00
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
times.sort(function(a,b){
|
|
|
|
|
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('预定失败');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|