message.js
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var $ = require('jquery'),
loading = require('../plugin/loading'),
dialog = require('./dialog');
var $page = $('.massage-page'),
page = 1,
stopLoading = false;
function massageAJAX(page) {
loading.showLoadingMask();
$.ajax({
type: 'POST',
url: '/home/ajaxMessage',
dataType: 'html',
data: {
page: page
},
success: function(data) {
if (data === ' ') {
stopLoading = true;
if (page === 1) {
data = '<p style="text-align:center">您没有消息</p>';
}
}
$('.massage-page').append(data);
window.rePosFooter();
loading.hideLoadingMask();
}
});
}
function scrollHandler() {
if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
page++;
massageAJAX(page);
}
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// 删除消息
$page.on('touchstart', '.del', function() {
var $good = $(this).closest('.massage-list'),
$id = $good.data('id');
dialog.showDialog({
dialogText: '确定删除这条消息吗?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
$.ajax({
type: 'POST',
url: '/home/ajaxDelMes',
data: {
id: $id
},
success: function(data) {
if (data.code === 200) {
dialog.showDialog({
dialogText: '删除消息成功',
autoHide: 2000,
fast: true
});
setTimeout(function() {
window.history.go(0);
}, 1200);
} else {
dialog.showDialog({
dialogText: data.message,
autoHide: 2000,
fast: true
});
}
}
});
});
});
massageAJAX(page);