绿满眶商城微信小程序-uniapp
zhanghua
5 天以前 1113721c0e068c57adbc15149cce15563960a7f2
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<template>
    <view>
        <view>
            <u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
            <view v-if="showLoading" style="width:500rpx;margin:0 auto;text-align: center;height:800rpx;line-height: 800rpx;">
                <u-loading mode="flower" ></u-loading>
                <text>正在加载中</text>
            </view>
            <u-cell-group v-if="current == 0">
                <view v-for="(item,index) in lists" :key="index">
                    <u-cell-item :arrow="false" v-if="item.status =='UN_READY'" style="position: relative;"
                        @click="linkMsgDetail(item)">
                        <template slot="label">
                            <view style="display: inline-block;
                width: 100%;
                height: auto;
                font-family: Gibson;
                font-size: 25rpx;
                word-break: break-all;
                text-overflow: ellipsis;
                word-wrap: break-word;
                white-space: pre-wrap;">
                                <view style="color:black;font-size:30rpx;font-weight:500;">{{item.title}}</view>
                                <view>{{item.content}}</view>
                                <view style="width:400rpx;padding: 10rpx 0;">{{item.createTime}}</view>
                            </view>
                        </template>
                        <!-- <button  style="width:100rpx;height:60rpx;float:right;font-size:20rpx;line-height:60rpx;background:#000000;color:white;">未读</button> -->
                    </u-cell-item>
                </view>
 
            </u-cell-group>
            <u-cell-group v-if="current == 1">
                <view v-for="(item,index) in lists" :key="index">
                    <u-cell-item :arrow="false" v-if="item.status == 'ALREADY_READY'" style="position: relative;"
                        @click="linkMsgDetail(item)">
                        <template slot="label">
                            <view style="display: inline-block;
                              width: 100%;
                              height: auto;
                              font-family: Gibson;
                              font-size: 25rpx;
                              word-break: break-all;
                              text-overflow: ellipsis;
                              word-wrap: break-word;
                              
                              white-space: pre-wrap;">
                              <view style="color:black;font-size:30rpx;font-weight:500;">{{item.title}}</view>
                              <view>{{item.content}}</view>
                              <view style="width:400rpx;padding: 10rpx 0;">{{item.createTime}}</view>
                            </view>
                        </template>
                        <!-- <button  style="width:100rpx;height:60rpx;float:right;font-size:20rpx;line-height:60rpx;background:#F3F3FA;color:black;">已读</button> -->
                    </u-cell-item>
                </view>
            </u-cell-group>
        </view>
 
    </view>
</template>
 
<script>
    import '@/components/uview-components/uview-ui'
    import {
        messages,
        editMessages
    } from "@/api/message.js"
    export default {
        data() {
            return {
                showLoading:true,
                params: {
                    pageSize: 20,
                    pageNumber: 1,
                    memberId: "",
                    messageId: "",
                    status:"UN_READY"
                },
                loadText: {
                    loadmore: '轻轻上拉',
                    loading: '努力加载中',
                    nomore: '实在没有了'
                },
                list: [{
                    name: "未读"
                }, {
                    name: "已读"
                }],
                current: 0,
                lists: [],
                status: "loadmore"
            }
        },
        onShow() {
            this.getMessage()
        },
        onReachBottom() {
            this.params.pageNumber++;
            this.statuss = "loading";
            this.getMessage()
        },
        methods: {
            linkMsgDetail(v) {
 
                if (v.status == 'UN_READY') {
                    let params = {}
                    params.messageId = v.memberId
                    editMessages(v.id, params).then(res => {
                        if (res.data.success) {
                            console.log( this.lists)
                            this.lists.forEach((item,index)=>{
                                console.log(item)
                                if(item.id == v.id){
                                    this.lists.splice(index, 1)
                                }
                            })
                        }
                    })
                }
                
                // uni.navigateTo({
                //     url:`/pages/tabbar/home/messageDetail?data=${encodeURIComponent(JSON.stringify(v))}`
                // })
                
 
            },
            /**
             * 返回
             */
            back() {
                if (getCurrentPages().length == 1) {
                    uni.switchTab({
                        url: "/pages/tabbar/home/index",
                    });
                } else {
                    uni.navigateBack();
                }
            },
            change(e) {
                this.showLoading = true;
                console.log(e)
                this.current = e;
                if (e == 0) {
                    this.params.status = "UN_READY"
                    this.params.pageNumber = 1;
                } else if (e == 1) {
                    this.params.status = "ALREADY_READY"
                    this.params.pageNumber = 1;
                }
                this.lists = []
                this.getMessage()
            },
            getMessage() {
                this.params.memberId = this.$options.filters.isLogin().id;
                
                messages(this.params).then(res => {
                    console.log(res)
                    if (res.data.success) {
                        this.showLoading = false
                        if (res.data.result.records == '') {
                            console.log(11111)
                            this.status = "nomore"
                        }
                        res.data.result.records.forEach(item => {
                            this.lists.push(item)
                            let obj = {};
                            this.lists = this.lists.reduce(
                                (cur, next) => {
                                    //对象去重
                                    if (next.id != undefined) {
                                        obj[next.id] ?
                                            "" :
                                            (obj[next.id] = true && cur.push(next));
                                    }
                                    console.log(cur);
                                    return cur;
                                },
                                []
                            )
                        })
 
                    }
                })
            }
        },
    }
</script>
<style>
    .foot {
        position: fixed;
        bottom: 0;
    }
</style>