<template>
	<div class="detail">
        <mt-header class="detail_head" fixed title="我的消息">
            <router-link to="" slot="left">
                <mt-button icon="back" v-on:click="jumpBack()"></mt-button>
            </router-link>
        </mt-header>
        <div class="detail_body">
            <div class="noList" v-if="list.length==0">
                <img src="../../assets/image/noList.png">
            </div>  
            <ul v-else class="recordBox" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="10">
                <li v-for="item in list" class="one_recordBox detailBox">
                    <div class="record_head">
                        <div>{{item.content}}</div>
                    </div>
                    <div class="record_body">
                        <div>时间：{{item.indate}}</div>
                    </div>
                </li>
                <div class="order" v-if="haveMore">
                    <span class="line"></span>
                    <span class="txt">没有更多了</span>
                    <span class="line"></span>
                </div>
            </ul>
        </div>
    </div>
</template>

<script>
	export default {
		data() {
			return {
                user: JSON.parse(sessionStorage.getItem("user")),
                list: [],
                pageNum: 1,
                pages: 1,
                haveMore: false,
			}
		},
		methods: {
            // 消息列表
            getList() {
                this.$indicator.open();
                this.http.post(this.port.my.newList, {
                    'uid': this.user.id,
                    'pageNum': this.pageNum
                } , 
                res => {
                    this.$indicator.close();
                    if (res.code == "ok") {
                        this.list = res.data.list;
                        this.pages = res.data.pages==0?1:res.data.pages;
                    } else {
                        this.$toast({
                            message: res.msg,
                            duration: 2000
                        });
                    }
                }, error => {
                    this.$indicator.close();
                    this.$toast({
                        message: error,
                        duration: 2000
                    });
                })
            },

            loadMore() {
                if(this.pageNum == this.pages) {
                    this.haveMore = true;
                } else if(this.pageNum < this.pages) {
                    this.$indicator.open();
                    this.http.post(this.port.my.newList, {
                        'id': this.id,
                        'pageNum': ++this.pageNum
                    } , 
                    res => {
                        this.$indicator.close();
                        if (res.code == "ok") {
                            this.pages = res.data.pages==0?1:res.data.pages;
                            if(res.data.list.length != 0) {
                                for(var i in res.data.list) {
                                    this.list.push(res.data.list[i]);
                                }
                            }
                        } else {
                            this.$toast({
                                message: res.msg,
                                duration: 2000
                            });
                        }
                    }, error => {
                        this.$indicator.close();
                        this.$toast({
                            message: error,
                            duration: 2000
                        });
                    })
                }
            },

            jumpBack() {
                this.http.post(this.port.my.noReadNum, {
                    'uid': this.user.id,
                } , 
                res => {
                    if (res.code == "ok") {
                        sessionStorage.setItem('noRead', res.data==null?0:res.data);
                         this.$router.go(-1);
                    } else {
                        this.$toast({
                            message: res.msg,
                            duration: 2000
                        });
                    }
                }, error => {
                    this.$toast({
                        message: error,
                        duration: 2000
                    });
                })
            }
        },
        created() {
            this.getList();
        },
		mounted() {
            
		}
	}

</script>

<style scoped>
    body {
        background: #EFEFEF;
    }

    .detail_head {
        background: #fff;
        color: #333;
        height: 0.4rem;
    }

    .detail_body {
        margin-top: 0.4rem;
        padding-bottom: 0.15rem;
    }

    .tab_head {
        position: fixed;
        width: 100%;
        top: 0.4rem;
        z-index: 110;
    }

    .detail {
        background: #EFEFEF;
    }

    .detailBox {
        background: #fff;
        margin-bottom: 0.11rem;
    }

    .recordBox {
        margin: 0.12rem 0 0 0;
    }

    .one_recordBox {
        padding: 0.12rem 0.2rem;
    }

    .record_head {
        color: #5FA1F0;
        padding: 0 0 0.1rem 0;
        border-bottom: 1px solid #ccc;
    }

    .record_head > div {
        width: 100%;
        display: inline-block;
        vertical-align: middle;
    }

    .record_head span {
        color: #939393;
        float: right;
        vertical-align: middle;
    }

    .record_body {
        color: #777;
        font-size: 0.12rem;
        line-height: 0.23rem;
        margin-top: 0.12rem;
    }

    .noList {
        text-align: center;
        padding: 1.5rem 0;
    }

    .noList img {
        width: 1.2rem;
        height: 1.2rem;
    }

    .order {
        height: 0.6rem;
        line-height: 0.6rem;
        text-align: center;
    }

    .order .line {
        display: inline-block;
        width: 1.2rem;
        border-top: 1px solid #ccc ;
        vertical-align: middle;
    }

    .order .txt {
        color: #ccc;
        font-size: 0.13rem;
        vertical-align: middle;
    }
</style>