<template>
    <section class="rank-container">
        <Header
			:is-scroll="isScroll"
			:share-title="shareTitle1"
			:share-title2="shareTitle2"
            :prePage="prePage"
		/>
        <!-- 我的排名 -->
        <div class="rank-info">
            <div class="rank-con">
                <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>{{rankNum}}<span v-if="rank > 100">+</span></p>
                        <span class="text">我的排名</span>
                    </div>
                </div>
                <div class="rank-detail">
                    <div class="rank-num" v-if="firstScore">
                        <span class="dlot" v-if="firstScore && lastScore"></span>
                        <span class="num">前一名：<span class="score">{{firstScore}}</span>勤奋分</span>
                    </div>
                    <div class="line" v-if="firstScore && lastScore"></div>
                    <div class="rank-num" v-if="lastScore">
                        <span class="dlot" v-if="firstScore && lastScore"></span>
                        <span class="num">后一名：<span class="score">{{lastScore}}</span>勤奋分</span>
                    </div>
                </div>
            </div>
            
        </div>
        <!-- 排行榜 -->
        <div class="main-content">
            <div class="description"><span>排行榜</span>排名每5分钟更新1次</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">全部奖品<img src="../../static/images/right.png"/></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 { ENV_CONFIG } from '@/utils/enumerate';
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,
            rankNum: 0,
            firstScore: 0,
            lastScore: 0
        }
    },
    created() {
        this.activityId = this.$route.query.id;
        this.token = this.$route.query.token;
        this.getRankData();
        this.getSelfAllScore();
    },
    mounted() {
        this.$sendBuriedData({ 
            action: '查看量',
            component_tag: '362#360011'
        });
    },
    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.rankNum = res.data.rank > 100 ? 100 : res.data.rank;
                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(){
            const { NUXT_ENV_APP } = process.env;
            let url = ENV_CONFIG[NUXT_ENV_APP]['shareUrl'] + '/template_v2/?id=703';
            let itemData={
                "title":"",
                "imageUrl":"",
                "appModuleInfo":{
                    "code":"M300",
                    "type":4,
                    "name":"wwww",
                    "paramFlag":1,
                    "paramList":[
                        {
                            "key":"pageUrl",
                            "value": url,
                            "type":4,
                            "seqNo":1
                        }
                    ]
                }
            };
            rocNative.dispatchEventByModuleCode({
                modeCode: itemData.appModuleInfo.code,
                jsonString: itemData.appModuleInfo.paramList
            })
        },
        goBack() {
            this.$sendBuriedData({ 
                action: '更多勤奋分按钮',
                component_tag: '362#360012'
            });
            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;
        .rank-con {
            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: 10px 9px;
                    font-size: 14px;
                    color: #fff;
                    span {
                        display: block;
                    }
                    span.ft {
                        font-weight: 700;
                        padding-bottom: 2px;
                        line-height: 12px; 
                    }
                    span.cl {
                        display: inline-block;
                        color: #FFE8A5;
                    }
                }
            }
            .info-score {
                color: #FFE8A5;
                p {
                    position: relative;
                    font-size: 26px;
                    text-align: center;
                    font-weight: 700;
                    line-height: 26px;
                    span {
                        position: absolute;
                        right: 0;
                        top: 0;
                        font-size: 14px;
                    }
                }
                span.text {
                    display: inline-block;
                    width: 68px;
                    height: 18px;
                    margin-top: 3px;
                    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: 6px 16px;
                // line-height: 31px;
                font-size: 13px;
                color: #fff;
                span.num {
                    padding-left: 3px;
                }
                span.dlot {
                    float: left;
                    width: 8px;
                    height: 8px;
                    margin-top: 5px;
                    border-radius: 50%;
                    transform: scale(.5);
                    transform-origin: 0% center;
                    background: #fff;
                }
                span.score {
                    color: #FFE8A5;
                }
            }
            .line {
                margin-top: 8px;
                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;
                font-family: Alibaba-PuHuiTi-H,Alibaba-PuHuiTi !important;
            }
        }
        .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 {
                    margin-left: 4px;
                    width: 11px;
                    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;
                img {
                    float: right;
                    margin-top: 4px;
                    margin-left: 2px;
                    width: 10px;
                }
            }
        }
        .awards {
            img {
                width: 100%;
            }
        }
    }
}
</style>