guoshilong
2023-10-27 2311b03aee9db1bebacdd2ced13c071efda6a011
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
<template>
    <view class="u-page">
        <view v-if="list.length<=0" class="line-center">
            <u-empty mode="data" />
        </view>
        <u-list @scrolltolower="scrolltolower" v-else>
            <u-list-item v-for="(item, index) in list" :key="item.id">
                <u-cell isLink :url='`./detail/index?data=${JSON.stringify(item)}`'
                    :title="`${item.createTime} ${item.theme}`" @click="clickMessage(item)">
                    <view v-show="item.status != 1" slot="right-icon">
                        <!-- <u-badge :absolute="false" :isDot="true" type="error"></u-badge> -->
                        <view class="badge"></view>
                        <!-- 未读 -->
                    </view>
                </u-cell>
            </u-list-item>
        </u-list>
 
 
        <u-loading-page :loading="loading"></u-loading-page>
 
 
    </view>
</template>
 
<script>
    import {
        getMessageList,
        readMessage,
    } from '@/api/system/message'
 
    export default {
        data() {
            return {
                loading: false,
                list: [],
                query: {
                    current: 1,
                    size: 15,
                    recipient: uni.getStorageSync("userInfo").user_id,
                },
            }
        },
        onShow() {
            // this.loadmore()
            this.initList()
        },
        methods: {
            //初始化
            async initList(query = this.query) {
                this.loading = true
                const {
                    code,
                    data,
                    msg
                } = await getMessageList(query)
                if (code != 200) {
                    uni.showToast({
                        title: msg,
                        icon: "none"
                    })
                    return
                }
 
 
                if (this.query.current == 1) {
                    this.list = data.records
                } else {
 
                    this.list = [...this.list, ...data.records]
                }
                this.loading = false
            },
            scrolltolower() {
                this.query.current += 1
                this.initList()
            },
            clickMessage(item) {
                if (item.status != 1) {
                    readMessage({
                        id: item.id
                    })
                }
            },
        },
    }
</script>
 
<style lang="scss" scoped>
    .line-center {
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .badge {
        height: 10rpx;
        width: 10rpx;
        border-radius: 50%;
        border: 2rpx solid #ff0000;
        background-color: #ff0000;
    }
</style>