<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 @scrolltolower="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 === 0"></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();
|
},
|
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?index=${index}`
|
});
|
// 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;
|
// });
|
}
|
});
|
} else {
|
uni.navigateTo({
|
url: `/pages/public-page/messageDetails/messageDetails?index=${index}`
|
});
|
}
|
},
|
// 删除消息
|
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>
|