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 = {
|
2014-09-03 19:25:32 +08:00
|
|
|
// 'did': "020000000000|FFFFFFFF8C61465AA89F4FA78D8767DC0B7F531C",
|
2014-09-01 13:50:43 +08:00
|
|
|
// 'device_type': 1
|
|
|
|
// };
|
|
|
|
|
|
|
|
if (!MyRemind.deviceInfo) {
|
2014-09-09 12:41:28 +08:00
|
|
|
// Public.alert('订阅功能仅请使用手机猎豹浏览器', function() {
|
|
|
|
// location.href = './';
|
|
|
|
// });
|
|
|
|
|
|
|
|
Remind.showLeibaoAD();
|
2014-09-01 13:50:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
MyRemind.getMyRemind();
|
|
|
|
|
|
|
|
|
|
|
|
},
|
2014-09-04 14:46:15 +08:00
|
|
|
deleteRemind: function(ids, $ele) {
|
2014-09-01 13:50:43 +08:00
|
|
|
var loading = Public.showLoading('正在删除提醒'),
|
|
|
|
data = {
|
2014-09-04 14:46:15 +08:00
|
|
|
'device_id': MyRemind.deviceInfo['did'],
|
|
|
|
'id_list': ids
|
|
|
|
}
|
2014-09-01 13:50:43 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2014-09-04 14:46:15 +08:00
|
|
|
type: 'POST',
|
|
|
|
url: 'http://12306.liebao.cn/index.php?r=Api/UpdateRss',
|
|
|
|
data: data,
|
|
|
|
success: function() {
|
|
|
|
$('.loading', loading).html('删除提醒成功');
|
2014-09-01 13:50:43 +08:00
|
|
|
$ele.remove();
|
2014-09-04 14:46:15 +08:00
|
|
|
setTimeout(function() {
|
2014-09-01 13:50:43 +08:00
|
|
|
Public.hideLoading(loading);
|
2014-09-04 14:46:15 +08:00
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
error: function() {
|
2014-09-01 13:50:43 +08:00
|
|
|
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) {
|
2014-09-03 17:09:04 +08:00
|
|
|
if (data['resCode'] == 0) {
|
2014-09-04 14:46:15 +08:00
|
|
|
if (data['data'].length > 0) {
|
2014-09-03 17:09:04 +08:00
|
|
|
MyRemind.formatJson(data['data']);
|
|
|
|
MyRemind.setHtmlList();
|
|
|
|
$('.list_tip').hide();
|
2014-09-05 00:34:08 +08:00
|
|
|
$('#myremind_box').show();
|
2014-09-04 14:46:15 +08:00
|
|
|
} else {
|
2014-09-05 00:34:08 +08:00
|
|
|
$('#myremind_box').hide();
|
|
|
|
$('.list_tip').html('暂无提醒<br><a href="remind.html" class="btn btn_success btn_block btn_lg">抢票闹钟</a>').show();
|
2014-09-03 17:09:04 +08:00
|
|
|
}
|
2014-09-01 13:50:43 +08:00
|
|
|
} 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++) {
|
2014-09-04 14:46:15 +08:00
|
|
|
if (list[i]['ispush'] == 1) {
|
2014-09-01 13:50:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-04 14:46:15 +08:00
|
|
|
if (list[i]['tasks_left'] > 0) {
|
|
|
|
list[i]['tasks_time'] = parseInt(list[i]['tasks_time']) + (list[i]['tasks_left'] * 60);
|
2014-09-03 19:25:32 +08:00
|
|
|
}
|
2014-09-01 13:50:43 +08:00
|
|
|
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'] = [];
|
|
|
|
}
|
2014-09-04 14:46:15 +08:00
|
|
|
if (MyRemind.remindObj[k]['id_list'].indexOf(list[i]['id']) == -1) {
|
2014-09-01 13:50:43 +08:00
|
|
|
MyRemind.remindObj[k]['id_list'].push(list[i]['id']);
|
|
|
|
}
|
2014-09-04 14:46:15 +08:00
|
|
|
if (MyRemind.remindObj[k]['time_list'].indexOf(list[i]['tasks_time'] * 1000) == -1) {
|
|
|
|
MyRemind.remindObj[k]['time_list'].push(list[i]['tasks_time'] * 1000);
|
2014-09-01 13:50:43 +08:00
|
|
|
// MyRemind.remindObj[k]['format_time_list'].push(list[i]['tasks_time']*1000);
|
|
|
|
}
|
|
|
|
};
|
2014-09-04 14:46:15 +08:00
|
|
|
for (k in MyRemind.remindObj) {
|
|
|
|
MyRemind.remindObj[k]['time_list'].sort(function(a, b) {
|
2014-09-01 13:50:43 +08:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2014-09-04 14:46:15 +08:00
|
|
|
MyRemind.remindList.sort(function(a, b) {
|
|
|
|
return (new Date(a['date'].replace(/\-/gi, '/'))).getTime() > (new Date(b['date'].replace(/\-/gi, '/')).getTime()) ? 1 : -1;
|
2014-09-01 13:50:43 +08:00
|
|
|
});
|
|
|
|
},
|
2014-09-04 14:46:15 +08:00
|
|
|
formatHoursDate: function(time) {
|
2014-09-01 13:50:43 +08:00
|
|
|
var date = new Date(time),
|
|
|
|
h = date.getHours(),
|
|
|
|
m = date.getMinutes();
|
2014-09-04 14:46:15 +08:00
|
|
|
if (m < 10) {
|
2014-09-01 13:50:43 +08:00
|
|
|
m = '0' + m;
|
|
|
|
}
|
2014-09-04 14:46:15 +08:00
|
|
|
return h + ':'
|
2014-09-01 13:50:43 +08:00
|
|
|
},
|
2014-09-04 14:46:15 +08:00
|
|
|
setHtmlList: function() {
|
2014-09-01 13:50:43 +08:00
|
|
|
var html = '',
|
2014-09-04 14:46:15 +08:00
|
|
|
obj = {},
|
|
|
|
d = '';
|
2014-09-01 13:50:43 +08:00
|
|
|
|
2014-09-04 14:46:15 +08:00
|
|
|
for (var i = 0, len = MyRemind.remindList.length; i < len; i++) {
|
2014-09-01 13:50:43 +08:00
|
|
|
obj = MyRemind.remindList[i];
|
2014-09-04 20:32:24 +08:00
|
|
|
d = (new Date(obj['date'].replace(/\-/gi, '/'))).addDays(-19).format('M月d日');
|
2014-09-01 13:50:43 +08:00
|
|
|
html += '<li>';
|
2014-09-04 14:46:15 +08:00
|
|
|
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">起售时间:' + d + ' ' + obj['format_time_list'].join('、') + '</div>';
|
|
|
|
html += '</li>';
|
2014-09-01 13:50:43 +08:00
|
|
|
};
|
|
|
|
$('#myremind_list').html(html);
|
2014-09-05 00:34:08 +08:00
|
|
|
$('#myremind_box').show();
|
|
|
|
$('.list_tip').hide();
|
|
|
|
// <a href="remind.html" class="btn btn_success btn_block btn_lg">抢票闹钟</a>
|
2014-09-04 14:46:15 +08:00
|
|
|
$('[data-ids]').on('click', function() {
|
2014-09-03 19:25:32 +08:00
|
|
|
var $this = $(this),
|
|
|
|
ids = $(this).attr('data-ids');
|
2014-09-04 14:46:15 +08:00
|
|
|
Public.confirm('删除提醒后,你将不会收到放票提醒,确定删除吗?', function() {
|
|
|
|
MyRemind.deleteRemind(ids, $this.closest('li'));
|
2014-09-03 19:25:32 +08:00
|
|
|
});
|
|
|
|
});
|
2014-09-01 13:50:43 +08:00
|
|
|
}
|
|
|
|
}
|