<template>
    <section class="rank-container">
        <Header
			:is-scroll="isScroll"
			:share-title1="shareTitle1"
			:share-title2="shareTitle2"
            :prePage="prePage"
		/>
        <!-- 我的排名 -->
        <div class="rank-info">
            <div class="info-text">
                <div class="info-detail">
                    <img :src="avatarImage" />
                    <div class="info-name">
                        <span class="ft">{{name}}</span>
                        <span><span class="cl">{{allScore}}</span>勤奋分</span>
                    </div>
                </div>
                <div class="info-score">
                    <p>{{rank}}</p>
                    <span>我的排名</span>
                </div>
            </div>
            <div class="rank-detail">
                <div class="rank-num" v-if="rank != 1">
                    <span class="dlot"></span>
                    <span class="num">前一名：<span class="score">{{firstScore}}</span>勤奋分</span>
                </div>
                <div class="line" v-if="rank != 1"></div>
                <div class="rank-num">
                    <span class="dlot"></span>
                    <span class="num">后一名：<span class="score">{{lastScore}}</span>勤奋分</span>
                </div>
            </div>
        </div>
        <!-- 排行榜 -->
        <div class="main-content">
            <div class="description"><span>排行榜</span>排名每5分钟更新1次 最后更新时间 7-15 12:05</div>
            <div class="ranking-title">
                <span>TOP10</span>
                <span class="marginL">用户名称</span>
                <span class="marginAuto">勤奋分</span>
            </div>
            <div class="ranking-list">
                <div class="item" v-for="(item,index) in topRankList" :key="index">
                    <img v-if="index<=2" :src="dealRankIcon(index)" alt="" class="ranking-icon">
                    <p v-else class="icon-num" >{{index+1}}</p>
                    <p class="doctor-name">{{item.name}}</p>
                    <p class="num">{{item.score}}</p>
                </div>
            </div>
        </div>
        <!-- 奖品 -->
        <div class="award-container">
            <div class="award-title">
                <div>排名前10名奖品</div>
                <span @click="allAward">全部奖品 ></span>
            </div>
            <div class="awards"><img src="../../static/images/all-award.png" /></div>
        </div>
        <DetailBtn 
        v-show="true" 
        :needBT="needBT" 
        @btnClick="goBack" />
    </section>
</template>
<script>
import Header from '../../components/header';
import DetailBtn from '../../components/bussiness/detail-btn';
import { getRankData, getSelfAllScore } from '@/service';
export default {
    components: {
       Header,
       DetailBtn
    },
    data() {
        return {
            prePage: true,
            token:'',
            needBT: false,
            shareTitle1: '我的排名',
            shareTitle2: '',
            isScroll: true,
            topRankList: [],
            activityId: '',
            avatarImage: '',
            name: '',
            allScore: 0,
            rank: 0,
            firstScore: 0,
            lastScore: 0
        }
    },
    created() {
        this.activityId = this.$route.query.id;
        this.token = this.$route.query.token;
        this.getRankData();
        this.getSelfAllScore();
    },
    methods: {
        // 获取个人信息
        getSelfAllScore() {
            getSelfAllScore({ id: this.activityId, token: this.token }).then(res => {
                this.avatarImage = res.data.avatarImageUrl;
                this.allScore = res.data.totalScore;
                this.userId = res.data.id;
                this.name = res.data.name;
                this.rank = res.data.rank;
                this.firstScore = res.data.firstScore;
                this.lastScore = res.data.lastScore;
            })
        },
        // 获取排行榜数据
        getRankData() {
            getRankData({id: this.activityId}).then(res => {
                if(res.code == '000000') {
                    this.topRankList = res.data;
                }
            })
        },
        dealRankIcon(index) {
            if(index == 0) {
                return require('../../static/images/icon-gold.png')
            } else if(index == 1) {
                return require('../../static/images/icon-silver.png')
            } else if(index == 2) {
                return require('../../static/images/icon-copper.png')
            }
        },
        // 全部奖品
        allAward(){
            
        },
        goBack() {
            this.$router.go(-1);
            // if(this.$rocNative.isWeb) {
            //     this.$router.go(-1);
            // } else {
            //     this.$rocNative.goBack();
            // }
        },
    }
}
</script>
<style lang="less" scoped>
.rank-container {
    .rank-info {
        padding-top: 70px;
        height: 150px;
        background-image:url('../../static/images/rank_head.png');
        background-size: 100% 100%;
        .info-text {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            padding: 15px 30px 13px 15px;
            .info-detail {
                img {
                    float: left;
                    width: 50px;
                    height: 50px;
                }
                .info-name {
                    display: inline-block;
                    padding: 9px;
                    font-size: 14px;
                    color: #fff;
                    span {
                        display: block;
                    }
                    span.ft {
                        font-weight: 700;
                        padding-bottom: 3px;
                    }
                    span.cl {
                        display: inline-block;
                        color: #FFE8A5;
                    }
                }
            }
            .info-score {
                color: #FFE8A5;
                p {
                    font-size: 26px;
                    text-align: center;
                }
                span {
                    display: inline-block;
                    width: 68px;
                    height: 18px;
                    text-align: center;
                    border-radius: 9px;
                    border:1PX solid rgba(255,232,165,1);
                }
            }
        }
        .rank-detail {
            display: flex;
            flex-direction: row;
            justify-content: center;
            margin: 0 15px 15px;
            height: 30px;
            background: rgba(153,31,51,1);
            border-radius: 15px;
            .rank-num{
                padding: 0px 16px;
                line-height: 30px;
                font-size: 13px;
                color: #fff;
                span.num {
                    padding-left: 5px;
                }
                span.dlot {
                    float: left;
                    width: 4px;
                    height: 4px;
                    margin-top: 14px;
                    border-radius: 50%;
                    background: #fff;
                }
                span.score {
                    color: #FFE8A5;
                }
            }
            .line {
                margin-top: 10px;
                background: #fff;
                width: 1PX;
                height: 15px;
            }
        }
    }
    .main-content {
        margin: -20px 10px 30px;
        border-radius: 12px;
        background: #fff;
        box-shadow:0px 2px 20px 0px rgba(0,0,0,0.15);
        .description {
            border-radius: 12px 12px 0px 0px;
            padding-left: 15px;
            height: 48px;
            line-height: 48px;
            color: #979899;
            font-size: 12px;
            background: #FFF7F2;
            span {
                font-size: 16px;
                color: #373839;
                padding-right: 6px;
                font-weight: 700;
            }
        }
        .ranking-title {
            display: flex;
            align-items: center;
            color: #373839;
            font-size: 12px;
            padding: 10px 40px 8px 30px;
            border-bottom: 1px solid #F8F9FA;
            .marginL {
                margin-left: 40px;
            }
            .marginAuto {
                margin-left: auto;
            }
        }
        .ranking-list {
            padding: 0 15px;
            .item {
                display: flex;
                font-size: 12px;
                align-items: center;
                padding: 10px 26px;
                border-bottom: 1px solid #F8F9FA;
                .ranking-icon {
                    width: 15px;
                    height: 15px;
                }
                .icon-num {
                    width: 15px;
                    color: #373839;
                }
                .doctor-name {
                    color: #373839;
                    font-size: 12px;
                    margin-left: 55px;
                    // width: 130px;
                }
                .num {
                    color:#FD5A2F;
                    font-size: 12px;
                    margin-left: auto;
                    text-align: center;
                    width: 38px;
                }
            }
        }
    }
    .award-container {
        margin: 0px 0px 60px 0px;
        .award-title {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            padding: 0px 15px 10px;
            div {
                font-size: 18px;
                color: #28344C;
                font-weight: 700;
            }
            span {
                font-size: 12px;
                color: #979899;
            }
        }
        .awards {
            img {
                width: 100%;
            }
        }
    }
}
</style>