2014-09-01 13:50:43 +08:00
|
|
|
var MyRemind = {
|
|
|
|
init: function() {
|
|
|
|
if ($('#myremind_page').length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MyRemind.deviceInfo = JSON.parse(bootStrap.device_info);
|
|
|
|
|
|
|
|
// MyRemind.deviceInfo = {
|
|
|
|
// 'did': '020000000000|FFFFFFFF8C61465AA89F4FA78D8767DC0B7F531C',
|
|
|
|
// 'device_type': 1
|
|
|
|
// };
|
|
|
|
|
|
|
|
if (!MyRemind.deviceInfo) {
|
|
|
|
Public.alert('订阅功能仅请使用手机猎豹浏览器', function() {
|
|
|
|
window.history.back();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MyRemind.getMyRemind();
|
|
|
|
|
|
|
|
$('[data-ids]').live('click',function(){
|
|
|
|
var $this = $(this),
|
|
|
|
ids = $(this).attr('data-ids');
|
|
|
|
Public.confirm('删除提醒后,你将不会收到放票提醒,确定删除吗?',function(){
|
|
|
|
MyRemind.deleteRemind(ids,$this.closest('li'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
deleteRemind: function(ids,$ele) {
|
|
|
|
var loading = Public.showLoading('正在删除提醒'),
|
|
|
|
data = {
|
|
|
|
'device_id' : MyRemind.deviceInfo['did'],
|
|
|
|
'id_list' : ids
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type:'POST',
|
|
|
|
url:'http://12306.liebao.cn/index.php?r=Api/UpdateRss',
|
|
|
|
data:data,
|
|
|
|
success:function(){
|
|
|
|
$('.loading',loading).html('删除提醒成功');
|
|
|
|
$ele.remove();
|
|
|
|
setTimeout(function(){
|
|
|
|
Public.hideLoading(loading);
|
|
|
|
},1000);
|
|
|
|
},error:function(){
|
|
|
|
Public.hideLoading(loading);
|
|
|
|
Public.alert('删除提醒失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getMyRemind: function() {
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: 'http://12306.liebao.cn/index.php?r=Api/GetRss',
|
|
|
|
data: {
|
|
|
|
'device_id': MyRemind.deviceInfo['did']
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
if (data['resCode'] == 0 && data['data'].length > 0) {
|
|
|
|
MyRemind.formatJson(data['data']);
|
|
|
|
MyRemind.setHtmlList();
|
|
|
|
$('.list_tip').hide();
|
|
|
|
$('#myremind_list').show();
|
|
|
|
} else {
|
|
|
|
Public.alert(data['message']);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function() {
|
2014-09-02 20:02:55 +08:00
|
|
|
$('.list_tip').html('获取信息失败');
|
2014-09-01 13:50:43 +08:00
|
|
|
Public.alert('获取信息失败');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
remindObj: {},
|
|
|
|
remindList: [],
|
|
|
|
formatJson: function(list) {
|
|
|
|
var k = '';
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
if(list[i]['ispush'] == 1){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k = list[i]['fromCode'] + list[i]['toCode'] + list[i]['date'];
|
|
|
|
if (!MyRemind.remindObj[k]) {
|
|
|
|
MyRemind.remindObj[k] = list[i];
|
|
|
|
MyRemind.remindObj[k]['id_list'] = [];
|
|
|
|
MyRemind.remindObj[k]['time_list'] = [];
|
|
|
|
MyRemind.remindObj[k]['format_time_list'] = [];
|
|
|
|
}
|
|
|
|
if(MyRemind.remindObj[k]['id_list'].indexOf(list[i]['id']) == -1){
|
|
|
|
MyRemind.remindObj[k]['id_list'].push(list[i]['id']);
|
|
|
|
}
|
|
|
|
if(MyRemind.remindObj[k]['time_list'].indexOf(list[i]['tasks_time']*1000) == -1){
|
|
|
|
MyRemind.remindObj[k]['time_list'].push(list[i]['tasks_time']*1000);
|
|
|
|
// MyRemind.remindObj[k]['format_time_list'].push(list[i]['tasks_time']*1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for(k in MyRemind.remindObj){
|
|
|
|
MyRemind.remindObj[k]['time_list'].sort(function(a,b){
|
|
|
|
return a > b ? 1 : -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 0; i < MyRemind.remindObj[k]['time_list'].length; i++) {
|
|
|
|
MyRemind.remindObj[k]['format_time_list'].push((new Date(MyRemind.remindObj[k]['time_list'][i])).toString().match(/\d{2}:\d{2}/)[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
MyRemind.remindList.push(MyRemind.remindObj[k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
MyRemind.remindList.sort(function(a,b){
|
|
|
|
return (new Date(a['date'].replace(/\-/gi,'/'))).getTime() > (new Date(b['date'].replace(/\-/gi,'/')).getTime()) ? 1 : -1;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
formatHoursDate : function(time){
|
|
|
|
var date = new Date(time),
|
|
|
|
h = date.getHours(),
|
|
|
|
m = date.getMinutes();
|
|
|
|
if(m < 10){
|
|
|
|
m = '0' + m;
|
|
|
|
}
|
|
|
|
return h + ':'
|
|
|
|
},
|
|
|
|
setHtmlList : function(){
|
|
|
|
var html = '',
|
|
|
|
obj={};
|
|
|
|
|
|
|
|
for (var i = 0,len = MyRemind.remindList.length; i < len; i++) {
|
|
|
|
obj = MyRemind.remindList[i];
|
|
|
|
html += '<li>';
|
|
|
|
html += '<div class="mr_title"><a class="pull_right" data-ids="'+obj['id_list'].join(',')+'"><i class="icon_remove"></i></a><i class="icon_clock"></i>'+(new Date(obj['date'].replace(/\-/gi,'/'))).format('M月d日')+'</div>';
|
|
|
|
html += '<div class="stations_info"><div class="station_info"><strong>'+obj['fromName']+'</strong></div><div class="station_info"><strong>'+obj['toName']+'</strong></div></div>';
|
|
|
|
html += '<div class="mr_text">起售时间:'+obj['format_time_list'].join('、')+'</div>';
|
|
|
|
html += '</li>';
|
|
|
|
};
|
|
|
|
$('#myremind_list').html(html);
|
|
|
|
}
|
|
|
|
}
|