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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
| <template>
| <view class="message-body">
| <u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" v-if="messageList.length == 0" width="400" height="400" textSize="18"></u-empty>
| <u-list @scroll="scrolltolower" :height="1400">
| <u-list-item>
| <u-swipe-action>
| <u-swipe-action-item :options="options1" v-for="(item, index) in messageList" :key="item.id" @click="deleteMsg(item, index)">
| <u-badge :isDot="true" type="error" v-if="item.status !== 1"></u-badge>
| <u-cell size="large" :title="item.title" :label="item.content" @click="messageDetails(item, index)">
| <view class="prepose" slot="icon"><u-icon name="file-text" color="#a299a0" size="80"></u-icon></view>
| </u-cell>
| </u-swipe-action-item>
| </u-swipe-action>
| </u-list-item>
| <view class="more-text" v-if="showMoreData && messageList.length !== 0">没有数据了...</view>
| </u-list>
| <u-modal :show="show" :content="content" :showCancelButton="true" @confirm="confirm" @cancel="cancel"></u-modal>
| </view>
| </template>
|
| <script>
| export default {
| data() {
| return {
| pageNum: 1,
| pageSize: 10,
| total: '',
| messageList: [],
| showMoreData: false,
| options1: [
| {
| text: '删除'
| }
| ],
| show: false,
| content: '是否确认删除',
| id: '',
| index: ''
| };
| },
| onShow() {
| this.messageReq();
| },
| onHide() {
| this.messageList = [];
| this.pageNum = 1;
| },
| methods: {
| // 触底加载
| scrolltolower() {
| if (this.pageNum * this.pageSize >= this.total) return (this.showMoreData = true);
| this.pageNum++;
| this.messageReq();
| },
| // 获取消息列表
| messageReq() {
| uni.showLoading({
| title: '加载中'
| });
| this.$reqGet('getMessageByUser', { current: this.pageNum, size: this.pageSize }).then(res => {
| if (res.code == 0) {
| uni.hideLoading();
| this.total = res.data.total;
| if (this.pageNum > 1) {
| this.messageList = this.messageList.concat(res.data.records);
| } else if (this.pageNum == 1) {
| this.messageList = res.data.records;
| }
| } else {
| this.$u.toast('加载失败');
| }
| });
| },
| // 已读消息
| messageDetails(value, index) {
| if (value.status == 0) {
| this.$reqAllJson('readMessage', { id: value.id, status: value.status }, { method: 'PUT', 'Content-Type': 'application/json' }).then(res => {
| if (res.code == 0) {
| uni.navigateTo({
| url: `/pages/public-page/messageDetails/messageDetails?messageId=${value.messageId}&id=${value.id}`
| });
| }
| });
| } else {
| uni.navigateTo({
| url: `/pages/public-page/messageDetails/messageDetails?messageId=${value.messageId}&id=${value.id}`
| });
| }
| },
| // 删除消息
| deleteMsg(value, index) {
| this.show = true;
| this.id = value.id;
| },
| // 确认删除
| confirm() {
| this.show = false;
| this.$reqGet('delteMessage', { id: this.id }).then(res => {
| if (res.code == 0) {
| this.$u.toast('删除成功');
| setTimeout(() => {
| uni.showLoading({
| title: '加载中'
| });
| this.$reqGet('getMessageByUser', { current: 1, size: this.pageSize }).then(res => {
| uni.hideLoading();
| this.total = res.data.total;
| this.messageList = res.data.records;
| });
| }, 800);
| } else {
| this.$u.toast('删除失败');
| }
| });
| },
| cancel() {
| this.show = false;
| }
| }
| };
| </script>
|
| <style lang="scss">
| ::v-deep .u-list-item- {
| position: relative;
| .u-badge {
| position: absolute;
| right: vww(10);
| top: vww(10);
| }
| }
| .message-body {
| width: 100%;
| height: 100%;
|
| .more-text {
| color: #999;
| font-size: 24rpx;
| text-align: center;
| }
| }
| </style>
|
|