<template>
    <div class="luck-info" @click.stop>
        <div class="content-box">
            <div class="head">
                <img v-if="!luckInfo.userHeadImg" :src="channelInfo.defaultPhoneHeadAva" />
                <img v-else-if="luckInfo.userHeadImg=='default'" :src="channelInfo.chatAdminAvaUrl" />
                <img v-else :src="luckInfo.userHeadImg" />
            </div>
            <div class="name">{{luckInfo.userNick}}的红包</div>
            <div class="text">{{luckInfo.content}}</div>
        </div>
        <div class="num-sum-box">
            <span>{{luckInfo.num}}</span>个红包共
            <i>{{luckInfo.amount | floatNum}}</i>元
        </div>
        <div class="luck-list">
            <ul class="list">
                <li class="item" v-for="(item,index) in luckInfo.detail" :key="index">
                    <div class="head">
                        <img v-if="item.userHeadImg" :src="item.userHeadImg" />
                        <img v-else :src="channelInfo.defaultPhoneHeadAva" />
                    </div>
                    <div class="content">
                        <div class="name">{{item.userNick}}</div>
                        <div class="time">{{item.createTime}}</div>
                    </div>
                    <div class="money">
                        <div>{{item.amount | floatNum}}元</div>
                        <div class="best" v-if="bestUser == item.userId">手气最佳</div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        luckInfo: {},
        channelInfo: {}
    },
    data() {
        return {};
    },
    computed: {
        bestUser() {
            let arr = [];
            let num = this.luckInfo.num || 1;
            let detail = this.luckInfo.detail || {};
            for (let key in detail) {
                arr.push(detail[key]);
            }
            if (arr.length < num) {
                return "";
            } else {
                arr.sort((a, b) => {
                    return b.amount - a.amount;
                });
                return arr[0].userId || "";
            }
        }
    },
    mounted() {},
    methods: {}
};
</script>

<style lang="less" scoped>
.luck-info {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #ffffff url("../img/luck-bg.png") no-repeat 0 0;
    background-size: 100% auto;

    .content-box {
        flex: 0 0 auto;
        padding-top: 50px;
        width: 100%;
        height: 200px;
        text-align: center;
        font-size: 14px;

        .head {
            margin: 0 auto 10px;
            width: 90px;
            height: 90px;
            border-radius: 50%;
            overflow: hidden;
            img {
                display: block;
                width: 100%;
                height: 100%;
            }
        }
        .name {
            padding: 5px 20px;
            color: #333333;
            color: #b2b2b2;
        }
    }
    .num-sum-box {
        flex: 0 0 auto;
        padding-left: 10px;
        height: 40px;
        line-height: 40px;
        overflow: hidden;
        background-color: #faf6f1;
        border-top: 1px solid #dfdfdd;
        border-bottom: 1px solid #dfdfdd;
        color: #b2b2b2;
        font-size: 14px;
    }
    .luck-list {
        flex: 1;
        width: 100%;
        overflow: auto;
        .list {
            padding: 0 5px;
            .item {
                display: flex;
                padding: 10px 5px;
                border-bottom: 1px solid #b9b9b9;
                font-size: 0;
                .head {
                    flex: 0 0 auto;
                    width: 40px;
                    height: 40px;
                    vertical-align: top;
                    border-radius: 50%;
                    overflow: hidden;
                    img{
                        display: block;
                        width: 100%;
                        height: 100%;
                    }
                }
                .content {
                    flex: 1;
                    line-height: 20px;
                    margin: 0 10px;
                    vertical-align: top;
                    .name {
                        font-size: 16px;
                        color: #333333;
                    }
                    .time {
                        font-size: 12px;
                        color: #b2b2b2;
                    }
                }
                .money {
                    flex: 0 0 auto;
                    line-height: 20px;
                    text-align: right;
                    font-size: 14px;
                    .best {
                        height: 20px;
                        padding-left: 20px;
                        font-size: 12px;
                        color: #f4c600;
                        background: url("../img/icon-best.png") no-repeat 0 0;
                        background-size: 18px 18px;
                    }
                }
                &:last-child {
                    border-bottom-color: transparent;
                }
            }
        }
    }
}
</style>
