<template>
    <div class="imageTextLive">
        <div class="list-box" ref="listBox"  @scroll="_getMore">
            <ul class="list" ref="listDom">
                <li class="item" v-for="(item,index) in newList" :key="index">
                    <div class="time">● {{item.createTime*1000 | formatDate}}</div>
                    <div class="content">
                        <div class="text">{{item.text}}</div>
                        <div class="imgs" v-if="item.image">
                            <img :src="item.image" class="seeImg" v-photoswipe="{group:'imageText'}">
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>
<script>
    import {getImgTextLive} from '@/plugins/API/apiOld'
    import {mapGetters} from 'vuex'

    export default {
        data(){
            return {
                list: [],
                page: 1,
                num: 15,
                isAjax: true,
            }
        },
        computed: {
            ...mapGetters({
                'channelInfo': 'channelInfo',
            }),
            newList(){
                return this.list.sort((a,b)=>{
                    return b.createTime - a.createTime
                })
            }
        },
        mounted(){
            this._getList();
        },
        methods: {
            async _getList(){
                if(!this.isAjax){
                    return false;
                }
                this.isAjax = false;
                const res = await getImgTextLive({
                    uin: this.channelInfo.uin,
                    id: this.channelInfo.id,
                    num: this.num,
                    page: this.page
                })
                this.isAjax = true;
                if(res.code == 200 && res.errorCode == 0){
                    this.page ++;
                    if(res.data.length < this.num){
                        this.isAjax = false;
                    }
                    this.list = [...this.list,...res.data]
                }
            },
            _getMore(){
                let listBoxHieght = this.$refs.listBox.clientHeight;
                let listBoxScrollY = this.$refs.listBox.scrollTop;
                let listDomHieght = this.$refs.listDom.clientHeight;
                if(listBoxHieght + listBoxScrollY > listDomHieght -250){
                    this._getList();
                }

            },
        },
    }
</script>

<style lang="less" scoped>
    .imageTextLive{
        height: 100%;
        padding: 10px;

        .list-box{
            height: 100%;
            overflow: auto;

            .item{
                .time{
                    line-height: 30px;
                    color: #008DF6;
                }
                .content{
                    padding: 5px;
                    background: #fff;
                    border-radius: 5px;
                    border: 1px solid #E5E5E5;

                    .text{
                        line-height: 25px;
                        color: #4B4B4B;
                        word-break: break-word;
                    }
                    .imgs{
                        max-width: 600px;

                        img{
                            display: block;
                            width: 100%;
                            height: auto;
                        }
                    }
                }
            }
        }
    }
</style>
