<template>
    <div id="share-skin" class="share">
        <div class="tab-box">
            <ul class="tab">
                <li class="item" @click="_tab(0)" :class="{'z-active': tabIndex == 0}">分享榜</li>
                <li class="item" v-if="isRed == 1" @click="_tab(1)" :class="{'z-active': tabIndex == 1}">红包榜</li>
            </ul>
        </div>
        <div class="tab-content">
            <div class="tab-pane share-list" :class="{'z-active': tabIndex == 0}">
                <ul class="list">
                    <li class="item" v-for="(item, index) in shareList" :key="index">
                        <div class="rank-box">
                            <div class="bg"></div>
                            <div class="rank">{{index+1}}</div>
                        </div>
                        <div class="head">
                            <img v-if="item.userHeadImg" :src="item.userHeadImg" alt="">
                            <img v-else :src="channelInfo.defaultPhoneHeadAva" alt="">
                        </div>
                        <div class="name">{{item.userNick}}</div>
                        <div class="num">分享了<i>{{item.num | formatNum}}</i>次</div>
                    </li>
                </ul>
            </div>
            <div class="tab-pane red-list" v-if="isRed == 1" :class="{'z-active': tabIndex == 1}">
                <ul class="list">
                    <li class="item" v-for="(item,index) in redList" :key="index">
                        <div class="rank-box">
                            <div class="bg"></div>
                            <div class="rank">{{index+1}}</div>
                        </div>
                        <div class="head">
                            <img v-if="item.userHeadImg" :src="item.userHeadImg" alt="">
                            <img v-else :src="channelInfo.defaultPhoneHeadAva" alt="">
                        </div>
                        <div class="name">{{item.userNick}}</div>
                        <div class="num">获得了<i>{{item.redAmount}}</i>元红包</div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>
<script>
    import {getShareList} from '@/plugins/API/apiAll'
    import {mapGetters} from 'vuex'
    export default {
        props: {
            isRed: {}
        },
        data(){
            return {
                tabIndex: 0,
                shareList: [],
                redList: []
            }
        },
        computed: {
            ...mapGetters({
                'channelInfo': 'channelInfo',
            }),
        },
        mounted(){
            this.$Bus.$on('bus-shareSuccess', this._getShareList)
            this._getShareList();
        },
        methods: {
            _tab(key){
                this.tabIndex = key;
            },
            async _getShareList(){
                const res = await getShareList({
                    uin: this.channelInfo.uin,
                    id: this.channelInfo.id,
                    isRed: parseInt(this.isRed) || 0,
                })
                if(res.code == 200 && res.errorCode == 0){
                    this.shareList = res.data.numShareList || [];
                    this.redList = res.data.amountShareList || [];
                }
            },
        },
        beforeDestroy(){
            this.$Bus.$off('bus-shareSuccess', this._getShareList)
        },
    }
</script>

<style lang="less" scoped>
    .share{
        height: 100%;
        overflow: auto;

        .tab-box{
            padding: 10px 0;
            text-align: center;

            .tab{
                display: inline-block;
                border: 1px solid #008DF6;
                font-size: 0px;
                border-radius: 5px;
                overflow: hidden;

                .item{
                    display: inline-block;
                    width: 80px;
                    height: 30px;
                    line-height: 30px;
                    text-align: center;
                    font-size: 14px;
                    background: #fff;
                    color: #008DF6;

                    &.z-active{
                        background: #008DF6;
                        color: #fff;
                    }
                }
            }
        }
        .tab-content{
            .tab-pane{
                display: none;

                &.z-active{
                    display: block;
                }
                .item{
                    display: flex;
                    position: relative;
                    height: 60px;
                    padding: 5px 15px;
                    line-height: 50px;
                    border-bottom: 1px solid #DCDCDC;
                    overflow: hidden;
                    &:first-child{
                        border-top: 1px solid #DCDCDC;
                    }
                    .rank-box{
                        position: absolute;
                        top: 0;
                        left: 0;
                        width: 50px;
                        height: 50px;

                        .bg{
                            position: absolute;
                            top: -50%;
                            left: -50%;
                            width: 100%;
                            height: 100%;
                            transform: rotate(45deg);
                            background: #858688;
                        }
                        .rank{
                            position: relative;
                            line-height: 25px;
                            width: 40%;
                            height: 50%;
                            color: #fff;
                            text-align: center;
                        }
                    }
                    &:nth-child(1){
                        .rank-box{
                            .bg{
                                background: #F80B04;
                            }
                        }
                    }
                    &:nth-child(2){
                        .rank-box{
                            .bg{
                                background: #F99507;
                            }
                        }
                    }
                    &:nth-child(3){
                        .rank-box{
                            .bg{
                                background: #008DF6;
                            }
                        }
                    }

                    .head{
                        flex: 0 0 50px;
                        width: 50px;

                        img{
                            display: block;
                            width: 50px;
                            height: 50px;
                            border-radius: 50%;
                        }
                    }
                    .name{
                        flex: 0 0 100px;
                        width: 100px;
                        margin-left: 10px;
                        color: #333333;
                        font-size: 14px;
                    }
                    .num{
                        flex: 1;
                        text-align: right;
                        font-size: 12px;
                        color: #333333;

                        i{
                            color: #008DF6;
                        }
                    }
                }
            }
        }
    }
</style>
