370 lines
10 KiB
JavaScript
370 lines
10 KiB
JavaScript
var Remind = {
|
||
sellTime: null,
|
||
loading: null,
|
||
init: function() {
|
||
// alert(typeof __ksticket)
|
||
if ($('#remind_page').length == 0) {
|
||
return false;
|
||
}
|
||
|
||
Remind.deviceInfo = JSON.parse(bootStrap.device_info);
|
||
/* Remind.deviceInfo = {
|
||
'did':'020000000000|FFFFFFFF8C61465AA89F4FA78D8767DC0B7F531C',
|
||
'device_type':1
|
||
}; */
|
||
if(!Remind.deviceInfo){
|
||
Public.alert('订阅功能仅请使用手机猎豹浏览器',function(){
|
||
window.history.back();
|
||
});
|
||
return ;
|
||
}
|
||
|
||
$('#menu_btn').on('click', function() {
|
||
|
||
var _height;
|
||
|
||
$('#user_menu').toggle();
|
||
if($(window).height() > $('body').height()){
|
||
_height = $(window).height();
|
||
}else{
|
||
_height = $('body').height();
|
||
}
|
||
$('#user_menu').height(_height - 45);
|
||
});
|
||
$('#user_menu').on('click', function(e) {
|
||
if ($(e.target).attr('id') == 'user_menu') {
|
||
$('#user_menu').hide();
|
||
}
|
||
});
|
||
|
||
Public.checkLogin(Remind.hasLogin, Remind.noLogin, Remind.noLogin);
|
||
|
||
|
||
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;
|
||
});
|
||
|
||
|
||
var sch = Public.getQueryData(window.location.search);
|
||
|
||
if(!!sch['date'] && !isNaN((new Date(sch['date'].replace(/\-/gi,'/'))).getTime())){
|
||
Remind.dateChangeCallback(new Date(sch['date'].replace(/\-/gi,'/')));
|
||
}
|
||
|
||
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]);
|
||
}
|
||
|
||
$('#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('退出失败,请重试。');
|
||
});
|
||
}
|
||
});
|
||
|
||
},
|
||
hasLogin: function() {
|
||
$('#login').attr('href', 'javascript:;').attr('data-fn', 'loginout').html('退出');
|
||
$('#menu_btn .icon_user').addClass('icon_user2');
|
||
|
||
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();
|
||
},
|
||
dataInit: function() {
|
||
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(/\-/,'/')));
|
||
}
|
||
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',
|
||
date = (new Date()).addDays(10).format('yyyy-MM-dd'),
|
||
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
|
||
};
|
||
Remind.checkType([]);
|
||
if (from == to) {
|
||
return;
|
||
}
|
||
if (!!Remind.trainsHis[key]) {
|
||
Remind.checkType(Remind.trainsHis[key]);
|
||
return;
|
||
}
|
||
Public.showLoading('正在查询数据')
|
||
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']);
|
||
Public.hideLoading();
|
||
}else{
|
||
Remind.checkType([]);
|
||
Public.hideLoading();
|
||
Public.alert('没有找到从<strong>'+$('#startStationName').val()+'</strong>到<strong>'+$('#endStationName').val()+'</strong>的列车');
|
||
}
|
||
}
|
||
});
|
||
},
|
||
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 = [];
|
||
d = c.addDays(-19).format('yyyy/MM/dd');
|
||
|
||
types.each(function(idx, el) {
|
||
var val = $(el).val(),
|
||
time = Remind.sellTime[data['fromCode']];
|
||
|
||
if (val == 'all') {
|
||
return;
|
||
}
|
||
|
||
if (!time) {
|
||
time = Remind.sellTime[data['fromName']];
|
||
}
|
||
|
||
time = time.split('/');
|
||
|
||
switch (val) {
|
||
case '1':
|
||
times.push('14:00');
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' 14:00').getTime())-900000,
|
||
// "time": (new Date().getTime())+300000,
|
||
"left": 15,
|
||
"type": 1
|
||
});
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' 14:00').getTime())-3600000,
|
||
// "time": (new Date().getTime())+600000,
|
||
"left": 60,
|
||
"type": 1
|
||
});
|
||
break;
|
||
case '2':
|
||
times.push('11:00');
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' 11:00')).getTime()-900000,
|
||
// "time": (new Date()).getTime()+300000,
|
||
"left": 15,
|
||
"type": 2
|
||
});
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' 11:00')).getTime()-3600000,
|
||
// "time": (new Date()).getTime()+600000,
|
||
"left": 60,
|
||
"type": 2
|
||
});
|
||
break;
|
||
case '3':
|
||
for (var i = 0; i < time.length; i++) {
|
||
times.push(time[i]);
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' ' + time[i]).getTime())-900000,
|
||
// "time": (new Date().getTime())+300000,
|
||
"left": 15,
|
||
"type": 3
|
||
});
|
||
data['tasks'].push({
|
||
"time": (new Date(d + ' ' + time[i]).getTime())-3600000,
|
||
// "time": (new Date().getTime())+600000,
|
||
"left": 60,
|
||
"type": 3
|
||
});
|
||
};
|
||
|
||
break;
|
||
}
|
||
});
|
||
|
||
times.sort(function(a,b){
|
||
return parseInt(a.split(':')[0]) > parseInt(b.split(':')[0]) ? 1 : -1;
|
||
});
|
||
|
||
times = times.join(',');
|
||
|
||
//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'] + '】火车票的开售提醒!';
|
||
|
||
$.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('预定失败');
|
||
}
|
||
});
|
||
}
|
||
} |