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() {
|
|
|
|
|
$('.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
|
|
|
|
|
|
|
|
|
$('.checks').each(function(index) {
|
|
|
|
|
var checkbox = $('[type=checkbox]', this);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('[data-fn="back"]').on('click',function(){
|
|
|
|
|
window.history.back();
|
|
|
|
|
});
|
|
|
|
|
Public.setHis();
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
his: {
|
|
|
|
|
querys:[],
|
|
|
|
|
queryObjs:{}
|
|
|
|
|
},
|
|
|
|
|
setHis :function(){
|
|
|
|
|
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-08-21 16:32:56 +08:00
|
|
|
|
showLoading:function(text){
|
|
|
|
|
var text = !!text ? ' '+text : '',
|
|
|
|
|
dom = $('<div class="loadingBox"><div class="loading"><i class="icon_loading"></i>'+text+'</div></div>');;
|
|
|
|
|
$('body').append(dom);
|
|
|
|
|
return dom;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
hideLoading:function(dom){
|
|
|
|
|
if(!!dom){
|
|
|
|
|
dom.remove();
|
|
|
|
|
}else{
|
|
|
|
|
$('.loadingBox').remove();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-08-19 16:11:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* 模拟 confirm 弹出层
|
|
|
|
|
* 依赖 Public.popHtml()
|
|
|
|
|
*
|
|
|
|
|
* @param {string} 弹出提示文字
|
|
|
|
|
* @param {function} 点击确定后的回调 (可选)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
confirm: function(text, callback) {
|
|
|
|
|
var dom = Public.popHtml(text, {
|
|
|
|
|
'cancel': '取消',
|
|
|
|
|
'sure': '确定'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.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) {
|
|
|
|
|
var b=-1;
|
|
|
|
|
for (var i = 0, len = arr.length; i < len; i++) {
|
|
|
|
|
if(arr[i][key] == val){
|
|
|
|
|
b=i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return b;
|
|
|
|
|
},
|
|
|
|
|
getHisQuery: function() {
|
|
|
|
|
var hisList = localStorage.getItem('hisQuery');
|
|
|
|
|
if (!hisList) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse(hisList);
|
|
|
|
|
},
|
|
|
|
|
setHisQuery:function(key,val){
|
|
|
|
|
var hisList = Public.getHisQuery(),
|
|
|
|
|
idx = Public.hasArrObjKey(hisList,0,key);
|
|
|
|
|
if(idx != -1){
|
|
|
|
|
hisList.splice(idx,1);
|
|
|
|
|
}
|
|
|
|
|
hisList.unshift([key,val]);
|
|
|
|
|
if(hisList.length > 6){
|
|
|
|
|
hisList.length == 6;
|
|
|
|
|
}
|
|
|
|
|
localStorage.setItem('hisQuery',JSON.stringify(hisList));
|
|
|
|
|
},
|
|
|
|
|
showInnerPage: function(id) {
|
|
|
|
|
$('#' + 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-08-21 13:42:42 +08:00
|
|
|
|
formatString:'yyyy年M月d日',
|
|
|
|
|
setDate: function(date) {
|
|
|
|
|
if($('#calendar').length == 0){
|
|
|
|
|
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) {
|
2014-08-21 16:32:56 +08:00
|
|
|
|
console.log('public')
|
2014-08-21 13:42:42 +08:00
|
|
|
|
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'
|
|
|
|
|
}).html('<p>' + date.format('M月d日') + '不在预售期</p><a href="#" class="btn btn_m btn_success">预约提醒</a>');
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|