<template>
    <div class="message">
        <group gutter="0">
            <cell title="消息中心" is-link @click="toMsg">
                <badge :text="message.total" v-if="message.total"></badge>
            </cell>
        </group>
        <div class="marquee">
            <div class="swiper-container" ref="list">
                <div class="swiper-wrapper">
                    <div class="swiper-slide item" v-for="(item, index) in message.top_five" :key="index" @click="linkTo(item.ResourceUrl)">
                        <span class="text ellipsis">{{item.ResourceTitle}}</span>
                        <span class="time tx-gray">{{item.ResourceDate}}</span>
                    </div>
                    <div class="empty" v-if="!message.top_five || !message.top_five.length">暂无数据</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Swiper from 'swiper'
import { Group, Cell, Badge } from 'vux'
import { urlTest } from '@/assets/utils/regexp.js'
export default {
    name: 'Message',
    props: ['message'],
    components: { Group, Cell, Badge },
    mounted () {
        // eslint-disable-next-line no-new
        new Swiper(this.$refs.list, {
            direction: 'vertical',
            slidesPerView: 3,
            slidesPerGroup: 3,
            autoplay: { delay: 5000 },
            observer: true,
            observeParents: true
        })
    },
    methods: {
        // 跳转到消息中心
        toMsg () {
            location.href = this.$common.exportHostName() + '/Weixin/App/Teacher/InfoCenter/InfoCenterGather.aspx'
        },
        // 跳转到消息的链接
        linkTo (url) {
            location.href = (urlTest(url) ? '' : this.$common.exportHostName()) + url
        }
    }
}
</script>

<style lang="less" scoped>
@import 'swiper/dist/css/swiper.css';
/deep/ p {
    color: inherit;
    font-size: inherit;
    margin-bottom: 0;
}
.marquee {
    height: 100px;
    background-color: #fff;
    padding: 5px 15px;
    .swiper-container {
        height: 100%;
    }
}
.item {
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .text {
        flex-grow: 1;
        font-size: 14px;
        padding-right: 15px;
        &::before {
            content: '';
            display: inline-block;
            width: 10px;
            height: 10px;
            margin-right: 5px;
            background-color: #f00;
            border-radius: 50%;
        }
    }
    .time {
        flex-shrink: 0;
        font-size: 12px;
        text-align: right;
    }
}
.empty {
    text-align: center;
    line-height: 80px;
    font-size: 14px;
    color: #999;
}
</style>
