ann0707
2018-08-16 c9bc8ec61cff4076132f6396d99d383a2cdf5a03
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
<template>
    <div class="message-center-page">
        <x-header :left-options="{backText: ''}">消息通知</x-header>
        <scroller lock-x height="-40px" :scrollbar-y=false ref="scroller" @on-pulldown-loading="refresh" :pulldown-config="pulldownConfig" use-pulldown>
            <MessageList :list="noticeList" :unRead="unRead" :showNone="showNone" @on-click-notice="handleNoticeJump"></MessageList>
        </scroller>
    </div>
</template>
<script>
/**
 * Created by c.y on 2018/3/22.
 * 我的--消息中心
 */
import { XHeader, Scroller } from 'vux';
import MessageList from '../../components/MessageList';
import system from '../../api/api';
import statusCodeManage from '../../api/statusCodeManage';
import FSpace from '../../components/common/FSpace.vue';
export default {
    name: 'f-message-center',
    data() {
        return {
            pulldownConfig: {
                content: '下拉刷新',
                height: 40,
                autoRefresh: false,
                downContent: '释放刷新',
                upContent: '释放刷新',
                loadingContent: '加载中...'
            },
            noticeList: [],
            showNone: false,
            unRead: [] //未读的消息数组的ID
        };
    },
    methods: {
        // 初始化通知列表
        init() {
            let _this = this;
            let _noticeIdArr = _this.$store.state.noticeIdArr;
            system.fetchNoticeList().then(
                res => {
                    _this.noticeList = res.body.notice;
                    if (!_this.noticeList.length) {
                        _this.showNone = true;
                    }
                    _this.unRead = JSON.parse(
                        window.sessionStorage.getItem('unRead')
                    );
                    _this.noticeList.forEach((val, index) => {
                        _this.unRead.forEach((v, i) => {
                            if (val.id === v) {
                                val.unRead = true;
                            }
                        });
                    });
                },
                error => {
                    statusCodeManage.showTipOfStatusCode(error, _this);
                }
            );
        },
        // type 1:跳转第三方(地址) 2:直接展示文案(html)
        handleNoticeJump(noticeItem) {
            if (noticeItem.type === 1) {
                // 获取资讯的详情, detailContent内容,有可能是地址,有可能是 html 代码片段
                system.fetchNoticeDetail({ noticeId: noticeItem.id }).then(
                    res => {
                        window.location.href = res.body.detailContent;
                    },
                    error => {
                        statusCodeManage.showTipOfStatusCode(error, _this);
                    }
                );
            } else if (noticeItem.type === 2) {
                // 返回html片段,跳转到我们的页面
                this.$router.push({
                    path: '/f-message/' + noticeItem.id
                });
            }
        },
        //下拉加载
        refresh() {
            system.fetchNoticeList().then(
                res => {
                    this.$nextTick(() => {
                        this.$refs.scroller.reset();
                        this.$refs.scroller.donePulldown();
                    });
                },
                err => {
                    this.$refs.scroller.donePulldown();
                    statusCodeManage.showTipOfStatusCode(err, this);
                }
            );
        }
    },
    components: {
        XHeader,
        MessageList,
        Scroller,
        FSpace
    },
    activated: function() {
        this.$store.commit('UPDATE_DIRECTION', { direction: 'in' });
        this.init();
    },
    deactivated() {
        this.showNone = false;
        this.$store.commit('UPDATE_DIRECTION', { direction: 'none' });
    }
};
</script>
<style lang="less">
@import '../../style/mixin.less';
.message-center-page {
    background-color: @color-background-default;
    .vux-header {
        .color-linear-gradient(@color-primary-light, @color-primary, 90deg);
        .vux-header-title {
            font-size: 18px;
        }
        .vux-header-left {
            .left-arrow:before {
                border: solid 1px @color-white;
                border-width: 2px 0 0 2px;
            }
        }
    }
    .message-body {
        padding: 0 12px;
        .message-body-header {
            height: 40px;
            margin-top: @font-size-tiny;
            line-height: 40px;
            font-size: @font-size-medium;
            .ellipsis();
        }
        .message-body-con {
            margin: 0 0 10px 0;
            color: @color-text-third;
            font-size: @font-size-small;
            .ellipsisLn(3);
        }
        .message-body-foot {
            height: 33px;
            border-top: solid 1px @color-background-default;
            line-height: 33px;
            text-align: right;
            padding-right: @font-size-tiny;
            color: @color-text-third;
        }
    }
    .scroller-box {
        padding-bottom: 40px;
    }
}
</style>