<!--消息-->
<template>
    <div id="news">
        <Nav :title="$t('news.title')" :iconType="false"></Nav>
        <div class="content">
            <template v-if="newsList.length||noticeList.length">
                <div class="cell" v-for="item,index in newsList" :key="index">
                    <div class="top" @click="goDetails(item)">
                        <span>{{item.title}}</span>
                    </div>
                    <div class="center" @click="goDetails(item)">
                        <span v-html="item.content"></span>
                    </div>
                    <div class="bottom">
                        <span>{{item.createTime}}</span>
                        <!-- <van-icon @click="deletes(item)" name="delete-o" color="#999999" size="14" /> -->
                    </div>
                </div>
                <div class="cell" v-for="item,index in noticeList" :key="index+'s'">
                    <div class="top" @click="goDetails(item)">
                        <span>{{item.title}}</span>
                    </div>
                    <div class="center" @click="goDetails(item)">
                        <span v-html="item.content"></span>
                    </div>
                    <div class="bottom">
                        <span>{{item.createTime}}</span>
                        <!-- <van-icon @click="deletes(item)" name="delete-o" color="#999999" size="14" /> -->
                    </div>
                </div>
            </template>
            <template v-else>
                <van-empty :description="$t('news.none')"></van-empty>
            </template>
        </div>
        <van-overlay :show="loading" @click="loading = false">
            <div class="wrapper" @click.stop>
                <div class="block">
                    <van-loading color="#1989fa" size="50" />
                </div>
            </div>
        </van-overlay>
    </div>
</template>

<script>
import Nav from "@/components/pages/nav";
import { getCustomerNotice } from "@/api/comp/news.js";
export default {
    data() {
        return {
            newsList: [],
            noticeList: [],
            loading: true,
        };
    },
    mounted() {
        this.getData();
        // setTimeout(() => {
        //     for (let i = 0; i < 5; i++) {
        //         this.newsList.push({
        //             title: "活动信息标题",
        //             text: "活动信息活动信息活动信息活动信息活动信息活动信息活动信息活动信息活动信息活动信息",
        //             time: "2022-08-12",
        //             id: 1,
        //         });
        //     }
        //     this.loading = false;
        // }, 1000);
    },
    methods: {
        getData() {
            this.loading = true;
            getCustomerNotice().then((res) => {
                if (res.code == 200) {
                    this.newsList = res.data.notice;
                    this.noticeList = res.data.customerNotice;
                    this.loading = false;
                }
            });
        },
        goDetails(data) {
            if (data.title == this.$t('news.orderInformation')) {
                this.$router.push({
                    path: "/toBePaid",
                    query: { type: 2 }
                });
            } else {
                this.$router.push({ path: "/details", query: { data: data } });
            }
        },
        deletes(item) {
            this.$dialog
                .confirm({
                    title: this.$t('news.tips'),
                    message: this.$t('news.confirmTips'),
                    confirmButtonText: this.$t('news.delete'),
                    cancelButtonText: this.$t('news.cancel'),
                })
                .then(() => {
                    // this.loading = true;
                    // removeShopCarList(item.id).then((res) => {
                    //     if (res.code == 200) {
                    //         this.$toast({
                    //             type: "success",
                    //             message: "删除成功",
                    //         });
                    //         this.loading = false;
                    //         this.getData();
                    //     }
                    // });
                })
                .catch(() => {
                    this.$notify({ type: "warning", message: this.$t('news.massage') });
                });
        },
    },
    components: {
        Nav,
    },
};
</script>

<style lang="scss" scoped>
#news {
    .content {
        background: #f9f9f9;
        padding: 0.12rem /* 12/100 */;
        box-sizing: border-box;
        color: #333333;
        min-height: calc(100vh - 1.28rem /* 128/100 */);
        .cell {
            width: 100%;
            background: #fff;
            border-radius: 0.05rem /* 5/100 */;
            box-shadow: 0px 0px 5px #e9e9e9;
            padding: 0.12rem /* 12/100 */;
            box-sizing: border-box;
            text-align: left;
            margin-bottom: 0.12rem /* 12/100 */;
            .top {
                font-size: 0.15rem /* 15/100 */;
                font-weight: 600;
            }
            .center {
                font-size: 0.14rem /* 14/100 */;
                // padding: 0.12rem /* 12/100 */ 0;
                margin: 0.12rem 0;
                overflow: hidden;
                text-overflow: ellipsis;
                width: 100%;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 3; // 超过3行则显示省略号
                word-break: break-all;
            }
            .bottom {
                border-top: 1px solid #eeeeee;
                font-size: 0.10rem /* 13/100 */;
                padding: 0.06rem 0 0.12rem 0;
                display: flex;
                justify-content: space-between;
                align-items: center;
                > span {
                    color: #999999;
                }
            }
        }
    }
}
</style>
<style>
#news .content .cell .center p {
    margin: 0;
}
#news img{
    display: none!important;
}
</style>