2014-08-19 16:11:37 +08:00
|
|
|
|
var WIN = window;
|
|
|
|
|
var DOC = document;
|
|
|
|
|
var SKIPVC = true;
|
|
|
|
|
var hostApi = "12306.cn/otsweb";
|
|
|
|
|
var baseProxyUrl = "/12306/proxy.php";
|
|
|
|
|
// var baseProxyUrl = "/12306/";
|
|
|
|
|
var isMobile = true;
|
2014-08-21 13:42:42 +08:00
|
|
|
|
var isIos = typeof(window.__gChrome) != 'undefined' || (typeof(liebaoExtentions) != 'undefined' && liebaoExtentions.isWebviewLiebao && liebaoExtentions.isWebviewLiebao());
|
|
|
|
|
var isAndLiebao = typeof(liebaoExtentions) != 'undefined';
|
2014-08-19 16:11:37 +08:00
|
|
|
|
var isWebApp = false;
|
2014-08-21 13:42:42 +08:00
|
|
|
|
DOC.addEventListener("mobileSupportInitialized", function() {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
isWebApp = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var Public = {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
init: function() {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
Public.setHis();
|
|
|
|
|
cn12306.getLocalTrainNos();
|
2014-09-01 18:15:29 +08:00
|
|
|
|
|
|
|
|
|
CheckStaion.formatStation();
|
|
|
|
|
|
2014-08-22 18:00:59 +08:00
|
|
|
|
// 刷新验证码
|
2014-09-01 13:50:43 +08:00
|
|
|
|
$('#randcodeimg').live('click', function(e) {
|
2014-08-22 18:00:59 +08:00
|
|
|
|
cn12306.recode();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2014-08-21 13:42:42 +08:00
|
|
|
|
$('.query_box .query_bigcheck').live('click', function() {
|
|
|
|
|
$('.query_bigcheck', $(this).parent('.query_box')).removeClass('query_bigcheck_checked');
|
2014-08-19 16:11:37 +08:00
|
|
|
|
// $('.query_bigcheck input[type=radio]',$(this).parent('.query_box')).removeAttr('checked');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
$('input[type=radio]', this).attr('checked', 'checked');
|
2014-08-19 16:11:37 +08:00
|
|
|
|
$(this).addClass('query_bigcheck_checked');
|
|
|
|
|
});
|
2014-08-21 13:42:42 +08:00
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
$('[data-fn="back"]').on('click', function() {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
window.history.back();
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
$('.query_box [type=checkbox]').live('change', function(e) {
|
|
|
|
|
if ($(this).closest('.query_box').find('[type=checkbox][value="all"]').length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var $checkbox = $(this).closest('.query_box').find('[type=checkbox]'),
|
|
|
|
|
$allBtn = $(this).closest('.query_box').find('[type=checkbox][value="all"]');
|
|
|
|
|
|
|
|
|
|
if ($(this).val() == 'all') {
|
|
|
|
|
if ($(this).prop('checked')) {
|
|
|
|
|
$checkbox.prop('checked', true);
|
|
|
|
|
} else {
|
|
|
|
|
$checkbox.prop('checked', false);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
var num = $(this).closest('.query_box').find('[type=checkbox]:checked').length;
|
|
|
|
|
if ($allBtn.prop('checked')) {
|
|
|
|
|
num--;
|
|
|
|
|
}
|
|
|
|
|
if (num == $checkbox.length - 1) {
|
|
|
|
|
$allBtn.prop('checked', true);
|
|
|
|
|
} else {
|
|
|
|
|
$allBtn.prop('checked', false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 16:24:47 +08:00
|
|
|
|
});
|
|
|
|
|
window.onbeforeunload = function(){
|
|
|
|
|
// alert('退出');
|
|
|
|
|
Client.refreshEnd();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.onunload = function(){
|
|
|
|
|
// alert('关闭');
|
|
|
|
|
Client.refreshEnd();
|
|
|
|
|
};
|
2014-09-01 13:50:43 +08:00
|
|
|
|
},
|
|
|
|
|
user: '',
|
|
|
|
|
isLogin: false,
|
|
|
|
|
checkNum: 0,
|
|
|
|
|
checkLogin: function(loginCB, noLoginCB, errorCB) {
|
|
|
|
|
Public.checkNum++;
|
|
|
|
|
cn12306.isUserLogined(function() {
|
|
|
|
|
|
|
|
|
|
Public.isLogin = true;
|
|
|
|
|
|
|
|
|
|
if (sessionStorage.getItem('user')) {
|
|
|
|
|
Public.user = sessionStorage.getItem('user');
|
|
|
|
|
} else if (localStorage.getItem('useraccount')) {
|
|
|
|
|
Public.user = (JSON.parse(localStorage.getItem('useraccount'))['username']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Public.setHis();
|
|
|
|
|
$('body').removeClass('nologin');
|
|
|
|
|
$('#login_tip').hide();
|
|
|
|
|
|
|
|
|
|
if (typeof loginCB == 'function') {
|
|
|
|
|
loginCB();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, function() {
|
|
|
|
|
sessionStorage.clear();
|
|
|
|
|
|
|
|
|
|
Public.isLogin = false;
|
|
|
|
|
|
|
|
|
|
$('body').addClass('nologin');
|
|
|
|
|
$('#login_tip').show();
|
|
|
|
|
|
|
|
|
|
if (typeof noLoginCB == 'function') {
|
|
|
|
|
noLoginCB();
|
|
|
|
|
}
|
|
|
|
|
}, function() {
|
|
|
|
|
|
|
|
|
|
Public.isLogin = false;
|
|
|
|
|
|
|
|
|
|
$('body').addClass('nologin');
|
|
|
|
|
$('#login_tip').show();
|
|
|
|
|
|
|
|
|
|
if (Public.checkNum < 2) {
|
|
|
|
|
Public.checkLogin(loginCB, noLoginCB, errorCB);
|
|
|
|
|
} else {
|
|
|
|
|
errorCB();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-08-21 13:42:42 +08:00
|
|
|
|
},
|
|
|
|
|
his: {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
querys: [],
|
|
|
|
|
queryObjs: {}
|
2014-08-21 13:42:42 +08:00
|
|
|
|
},
|
2014-09-01 13:50:43 +08:00
|
|
|
|
setHis: function() {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
Public.his.querys = Public.getHisQuery();
|
|
|
|
|
for (var i = 0, len = Public.his.querys.length; i < len; i++) {
|
|
|
|
|
Public.his.queryObjs[Public.his.querys[i][0]] = Public.getQueryData(Public.his.querys[i][1]);
|
|
|
|
|
};
|
2014-08-19 16:11:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 弹出提示
|
2014-08-21 13:42:42 +08:00
|
|
|
|
*
|
2014-08-19 16:11:37 +08:00
|
|
|
|
* @param {string} 弹出提示文字
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-08-21 13:42:42 +08:00
|
|
|
|
toast: function(text, ms) {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
if (!text) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 13:42:42 +08:00
|
|
|
|
var dom = $('<div class="public_toast">' + text + '</div>');
|
2014-08-19 16:11:37 +08:00
|
|
|
|
var ms = ms || 1500;
|
|
|
|
|
$('body').append(dom);
|
2014-08-21 13:42:42 +08:00
|
|
|
|
setTimeout(function() {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
dom.addClass('public_toast_show');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
}, 10);
|
|
|
|
|
setTimeout(function() {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
dom.removeClass('public_toast_show');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
dom.on('webkitTransitionEnd', function() {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
dom.remove();
|
|
|
|
|
});
|
2014-08-21 13:42:42 +08:00
|
|
|
|
}, ms);
|
2014-08-19 16:11:37 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 弹出层
|
|
|
|
|
* @param {string} 弹出提示文字
|
|
|
|
|
* @param {object} 弹层按钮 {'sure':'确定','cancel':'取消'}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
popHtml: function(text, btns) {
|
|
|
|
|
var html = "",
|
|
|
|
|
dom = DOC['createElement']('div'),
|
|
|
|
|
btnsHtml = '';
|
|
|
|
|
|
|
|
|
|
if (typeof btns == 'object') {
|
|
|
|
|
for (var k in btns) {
|
|
|
|
|
btnsHtml += '<a href="javascript:;" data-val="' + k + '">' + btns[k] + '</a>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (btnsHtml == '') {
|
|
|
|
|
btnsHtml = '<div class="public_btns"><a href="javascript:;" data-type="sure">确定</a></div>';
|
|
|
|
|
} else {
|
|
|
|
|
btnsHtml = '<div class="public_btns">' + btnsHtml + '</div>'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dom['className'] = 'public_layer';
|
|
|
|
|
|
|
|
|
|
html += '<div class="public_pop"><p>' + text + '</p>' + btnsHtml + '</div>';
|
|
|
|
|
|
|
|
|
|
dom.innerHTML = html;
|
|
|
|
|
|
|
|
|
|
document.getElementsByTagName('body')[0].appendChild(dom);
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$('.public_pop', dom).addClass('public_pop_show');
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
$(dom).on('touchmove', function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
return $(dom);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 模拟 alert 弹出层
|
|
|
|
|
* 依赖 Public.popHtml()
|
|
|
|
|
*
|
|
|
|
|
* @param {string} 弹出提示文字
|
|
|
|
|
* @param {function} 点击确定后的回调 (可选)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
alert: function(text, callback) {
|
|
|
|
|
var dom = Public.popHtml(text, {
|
|
|
|
|
'sure': '确定'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.public_btns a', dom).on('click', function() {
|
|
|
|
|
dom.remove();
|
|
|
|
|
if (typeof callback == 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
showLoading: function(text) {
|
|
|
|
|
var text = !!text ? ' ' + text : '',
|
|
|
|
|
dom = $('<div class="loadingBox"><div class="loading"><i class="icon_loading"></i><span>' + text + '</span></div></div>');;
|
2014-08-21 16:32:56 +08:00
|
|
|
|
$('body').append(dom);
|
|
|
|
|
return dom;
|
|
|
|
|
},
|
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
hideLoading: function(dom) {
|
|
|
|
|
if (!!dom) {
|
2014-08-21 16:32:56 +08:00
|
|
|
|
dom.remove();
|
2014-09-01 13:50:43 +08:00
|
|
|
|
} else {
|
2014-08-21 16:32:56 +08:00
|
|
|
|
$('.loadingBox').remove();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-08-19 16:11:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* 模拟 confirm 弹出层
|
|
|
|
|
* 依赖 Public.popHtml()
|
|
|
|
|
*
|
|
|
|
|
* @param {string} 弹出提示文字
|
|
|
|
|
* @param {function} 点击确定后的回调 (可选)
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-09-01 13:50:43 +08:00
|
|
|
|
confirm: function(text, callback, sureBtn) {
|
2014-08-19 16:11:37 +08:00
|
|
|
|
var dom = Public.popHtml(text, {
|
|
|
|
|
'cancel': '取消',
|
2014-09-01 13:50:43 +08:00
|
|
|
|
'sure': sureBtn || '确定'
|
2014-08-19 16:11:37 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.public_btns a', dom).on('click', function() {
|
|
|
|
|
var type = $(this).attr('data-val');
|
|
|
|
|
dom.remove();
|
|
|
|
|
if (typeof callback == 'function' && type == "sure") {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-08-21 13:42:42 +08:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 根据传入的query字符串返回键值对形式的对象
|
|
|
|
|
* @param {String} queryString query字符串
|
|
|
|
|
* @return {KeyValueObject}
|
|
|
|
|
*/
|
|
|
|
|
getQueryData: function(queryString) {
|
|
|
|
|
|
|
|
|
|
/* 去掉字符串前面的"?",并把&转换为& */
|
|
|
|
|
queryString = queryString.replace(/^\?+/, '').replace(/&/, '&');
|
|
|
|
|
var querys = queryString.split('&'),
|
|
|
|
|
i = querys.length,
|
|
|
|
|
_URLParms = {};
|
|
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
|
item = querys[i].split('=');
|
|
|
|
|
if (item[0]) {
|
|
|
|
|
var value = item[1] || '';
|
|
|
|
|
try {
|
|
|
|
|
value = decodeURIComponent(value);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
value = unescape(value);
|
|
|
|
|
}
|
|
|
|
|
_URLParms[decodeURIComponent(item[0])] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return _URLParms;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 参数对象转为查询字符串片段
|
|
|
|
|
*/
|
|
|
|
|
objToQueryString: function(obj) {
|
|
|
|
|
var result = [],
|
|
|
|
|
key, value, i;
|
|
|
|
|
for (key in obj) {
|
|
|
|
|
value = obj[key];
|
|
|
|
|
if (value instanceof Array) {
|
|
|
|
|
for (i = value.length; i--;) {
|
|
|
|
|
result.push(key + '[]=' + encodeURIComponent(value[i]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result.push(key + ('' === value ? '' : ('=' + encodeURIComponent(value))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result.join('&');
|
|
|
|
|
},
|
|
|
|
|
hasArrObjKey: function(arr, key, val) {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
var b = -1;
|
2014-08-21 13:42:42 +08:00
|
|
|
|
for (var i = 0, len = arr.length; i < len; i++) {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
if (arr[i][key] == val) {
|
|
|
|
|
b = i;
|
2014-08-21 13:42:42 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return b;
|
|
|
|
|
},
|
|
|
|
|
getHisQuery: function() {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
var hisList = localStorage.getItem(Public.user + 'hisQuery');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
if (!hisList) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse(hisList);
|
|
|
|
|
},
|
2014-09-01 13:50:43 +08:00
|
|
|
|
setHisQuery: function(key, val) {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
var hisList = Public.getHisQuery(),
|
2014-09-01 13:50:43 +08:00
|
|
|
|
idx = Public.hasArrObjKey(hisList, 0, key);
|
|
|
|
|
if (idx != -1) {
|
|
|
|
|
hisList.splice(idx, 1);
|
2014-08-21 13:42:42 +08:00
|
|
|
|
}
|
2014-09-01 13:50:43 +08:00
|
|
|
|
hisList.unshift([key, val]);
|
|
|
|
|
if (hisList.length > 6) {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
hisList.length == 6;
|
|
|
|
|
}
|
2014-09-01 13:50:43 +08:00
|
|
|
|
localStorage.setItem(Public.user + 'hisQuery', JSON.stringify(hisList));
|
2014-08-21 13:42:42 +08:00
|
|
|
|
},
|
|
|
|
|
showInnerPage: function(id) {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
$('.fixed_box').removeClass('fixed_box_show');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
$('#' + id).addClass('fixed_box_show');
|
|
|
|
|
$('#wrap').hide();
|
|
|
|
|
},
|
|
|
|
|
hideInnerPage: function() {
|
|
|
|
|
$('.fixed_box').removeClass('fixed_box_show');
|
|
|
|
|
$('#wrap').show();
|
|
|
|
|
},
|
2014-08-19 16:11:37 +08:00
|
|
|
|
|
2014-09-01 13:50:43 +08:00
|
|
|
|
formatString: 'yyyy年M月d日',
|
2014-08-21 13:42:42 +08:00
|
|
|
|
setDate: function(date) {
|
2014-09-01 13:50:43 +08:00
|
|
|
|
if ($('#calendar').length == 0) {
|
2014-08-21 13:42:42 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var date = date || (new Date()).date;
|
|
|
|
|
|
|
|
|
|
$('#start_date').html(date.format(Public.formatString) + ' ' + date.day(3));
|
|
|
|
|
$('#start_date_val').val(date.format('yyyy-MM-dd'));
|
|
|
|
|
if (!Public.calendar) {
|
|
|
|
|
Public.calendar = new DateComponent({
|
|
|
|
|
wrap: $('#calendar'),
|
|
|
|
|
curDate: date,
|
|
|
|
|
checkCallback: Public.dateChangeCallback
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
$('#check_left,#check_right').on('click', function() {
|
|
|
|
|
var checkDate;
|
|
|
|
|
if ($(this).attr('id') == 'check_left') {
|
|
|
|
|
checkDate = Public.calendar.dayPrev();
|
|
|
|
|
} else {
|
|
|
|
|
checkDate = Public.calendar.dayNext();
|
|
|
|
|
}
|
|
|
|
|
if (checkDate) {
|
|
|
|
|
$('#start_date').html(checkDate.format(Public.formatString) + ' ' + checkDate.day(3));
|
|
|
|
|
$('#start_date_val').val(checkDate.format('yyyy-MM-dd'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#start_date').on('click', function() {
|
|
|
|
|
Public.showInnerPage('date_box');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('[name=type]').on('change', function() {
|
|
|
|
|
var val = $('[name=type]:checked').val();
|
|
|
|
|
if (val == 1) {
|
|
|
|
|
Public.calendar.maxDate = Public.calendar._TODAY.addDays(19);
|
|
|
|
|
if (Public.calendar.curDate.date.getTime() > Public.calendar.maxDate.date.getTime()) {
|
|
|
|
|
Public.calendar.curDate = Public.calendar.maxDate;
|
2014-08-21 16:32:56 +08:00
|
|
|
|
Public.calendar.checkCallback(Public.calendar.curDate);
|
|
|
|
|
// Public.dateChangeCallback(Public.calendar.curDate);
|
2014-08-21 13:42:42 +08:00
|
|
|
|
}
|
|
|
|
|
Public.calendar.setBasic();
|
|
|
|
|
} else if (val == 2) {
|
|
|
|
|
Public.calendar.maxDate = Public.calendar._TODAY.addDays(29);
|
|
|
|
|
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'));
|
|
|
|
|
} else {
|
|
|
|
|
var offset = $('a.cur', Public.calendar.wrap).offset();
|
|
|
|
|
$('#date_tip').css({
|
|
|
|
|
'left': offset.left,
|
|
|
|
|
'top': offset.top,
|
|
|
|
|
'display': 'block'
|
2014-09-01 13:50:43 +08:00
|
|
|
|
}).html('<p>' + date.format('M月d日') + '不在预售期</p><a href="remind.html?data=' + encodeURIComponent(date.format('M月d日')) + '" class="btn btn_m btn_success">预约提醒</a>');
|
2014-08-21 13:42:42 +08:00
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|