<template>
    <view class="news">
        <block v-if="lists.length > 0">
            <view  class="list-item" v-for="(item,index) in lists" :key="index" @click="goUrl(item.notification_id,index)">
                <u-badge class="bell_fill_dot" :isDot="item.read_at === ''" type="error" />
                <image src="/static/news/news.png" mode="widthFix" />
                <view class="list-item-right">
                    <view class="top">
                        <view class="title">
                            <view class="titl"> 系统反馈 </view>
                            <view class="des">官方</view>
                        </view>
                        <view class="date">{{item.created_at}}</view>
                    </view>
                    <view class="sub-title">快捷反馈:{{item.content}}</view>
                </view>
            </view>
        </block>
        <view class="no-list" v-else>
            <u-empty mode="message" icon="http://cdn.uviewui.com/uview/empty/message.png" text="暂无消息~" textColor="#999" />
        </view>
    </view>
</template>

<script>
    import {list,readAll} from '@/apis/interfaces/news.js'
    export default {
        data() {
            return {
                lists:[],
                type:'FeedbackNotification',
                has_more: true,
                page: 1,
            }
        },
        onLoad() {
          this.getList();  
        },
        onReachBottom() {
          if(this.has_more){
              this.page = this.page + 1;
              this.getList();
          } else{
              uni.showToast({
                  title:'没有更多啦~',
                  icon:'none',
                  mask:true,
              })
          } 
        },
        onNavigationBarButtonTap() {
            readAll(this.type).then(res=>{
                uni.showToast({
                    title:'全部已读',
                    icon:"none",
                    mask:true,
                    duration:3000
                });
                this.page = 1;
                this.has_more = true;
                this.getList();
            }).catch(err=>{
                uni.showToast({
                    title:err.message,
                    icon:"none",
                    mask:true,
                    duration:3000
                })
            })
           
        },
        methods: {
            goUrl(id,index){
              this.lists[index].read_at = '11111'
              this.$Router.push({name:'newsDetail',params:{id:id}});
            },
            getList(){
                list(this.type,{page:this.page}).then(res=>{
                    if(this.page ===  1){
                        this.lists = []
                    }
                    this.lists = this.lists.concat(res.data)
                    this.has_more = res.page.has_more
                }).catch(err=>{
                    uni.showToast({
                        title:err.message,
                        icon:"none",
                        mask:true,
                        duration:3000
                    })
                })
            }
        }
    }
</script>

<style lang="scss">
    .list-item {
        padding: $padding - 10 $padding;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        box-sizing: border-box;
        border-bottom: solid 1rpx #f0f0f0;

        image {
            width: 100rpx;
            height: 100rpx;
        }

        .list-item-right {
            padding-left: $padding - 10;
            flex: 1;

            .top {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: space-between;
                box-sizing: border-box;

                .title {
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    justify-content: center;
                    box-sizing: border-box;

                    .titl {
                        font-size: 32rpx;
                        font-weight: bold;
                    }

                    .des {
                        margin-left: 10rpx;
                        border-radius: 6rpx;
                        border: solid 1rpx #F76260;
                        font-size: 24rpx;
                        font-weight: bold;
                        color: #F76260;
                        padding: 0 10rpx;
                    }
                }

                .date {
                    font-size: 26rpx;
                    color: grey;
                    padding-right: 10rpx;
                }
            }

            .sub-title {
                font-size: 26rpx;
                color: grey;
                padding-top: 10rpx;
                display: -webkit-box;
                overflow: hidden;
                text-overflow: ellipsis;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
            }
        }
    }

    .no-list {
        height: 80vh;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
    }
</style>
