<template>
  <div class="rank-box">
    <div class="rank-list-open" @click="open(!listFlag)">
      <p ><span>{{!listFlag?'点击展开':'点击收起'}}</span><i :class="listFlag?'active':''"></i></p>
    </div>
    <div class="rank-list">
    <div class="title">
      <span>{{ title }}</span>
      <p v-if="city&&!userItem" @click="show=true" class="text"><span>地区：</span><span style="color: #fff;">{{city}}</span><img  src="@/assets/img/wap-down.png" alt="" /></p>
      <p v-if="userItem"><img src="@/assets/img/user-wap.png" alt="" /><a target="_blank" :href="`https://blog.csdn.net/${userItem.username}`">{{userItem.nickname||userItem.username}}</a></p>
    </div>
    <div class="rank-list-nav border">
      <span class="mar">排名</span>
      <p><span>明星成员</span></p>
      <span>城市</span><span>{{listTitle}}</span>
    </div>
    <ul class="user-list">
      <!-- <li class="border">
        <span class="mar">排名</span>
        <p><span>明星成员</span></p>
        <span>城市</span><span>{{listTitle}}</span>
      </li> -->
      <li class="rank-list-nav active" v-for="(item,index) in rankData" :key="index" @click="rankAdd(item)">
        <span class="mar">{{index+1}}</span>
        <p>
          <img :src="item.avatar" alt="" /><span
            >{{item.nickname || item.username}}</span
          >
        </p>
        <span>{{item.city}}</span><span>{{item.score}}</span>
      </li>
    </ul>
      <van-popup v-model="show"  position="bottom">
      <van-picker
        :columns="dropdownList"
        :show-toolbar="true"
        :default-index="0"
        :visible-item-count="3"
        @confirm="onConfirm"
        @cancel="show = false"
        />          
      </van-popup>
     <!-- @confirm="onConfirm"
  @cancel="onCancel"
  @change="onChange" -->
  </div>
  </div>
</template>
<script>
import Bus from "@/common/bus"
export default {
  data(){
    return {
      listFlag:false,
      userItem:'',
      show:false,
    }
  },
  methods: {
    onConfirm (val) {
      this.$emit('onConfirm',val)
      this.show = false
    },
    onCancel (){

    },
    open (val) {
      this.listFlag = val
      this.$emit('listOpen', this.listFlag)
    },
    clear () {
      this.$emit('clear')
    },
    rankAdd(item){
      if (this.title == '用户原力月榜') {
        window.open(`https://blog.csdn.net/`+item.username)
      }else{
        this.userItem = item
        this.$emit('rankFans',item)
        this.open(false)
      }
    }
  },
  mounted (){
    Bus.$on('clear',()=>{
      this.userItem = null
    })
  },
  props: ['title','rankData','city','listTitle','cityObj','dropdownList','defaultIndex']
}
</script>
<style >
/* .van-picker__columns{
  height: 200px !important;
} */
</style>
<style scoped lang="scss">
.rank-box{
  height: 100%;
}
.rank-list-open{
  height: 40px;
  display: flex;
  justify-content: center;
  p{
    display: flex;
    align-items: center;
    justify-content: center;
    // padding: 0 10px;
    height: 24px;
    background: #2B364F;
    border-radius: 16px;
    border: 1px solid #5C6E8E;
    width: 86px;
    span{
      font-size: 12px;
      font-weight: 500;
      color: #FFFFFF;
    }
    i{
      width: 16px;
      height: 16px;
      background-image:url('@/assets/img/up.png') ;
      background-size: cover;
      &.active{
        background-image:url('@/assets/img/down.png') ;
        background-size: cover;
      }
    }
  }
}
.rank-list {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #416095 0%, #364362 100%);
  border-radius: 20px 20px 0px 0px;
  padding-bottom: 10px;
  .title {
    display: flex;
    justify-content: space-between;
    height: 48px;
    align-items: center;
    padding: 0px 16px 0px 16px;
    padding-right: 26px;
    font-size: 14px;
    color: #b2bccf;
    &>span:nth-child(1){
      color: #fff;
    }
    span {
      font-size: 14px;
      font-weight: 500;
      color: #b2bccf;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      word-break: break-all;
    }
    .clear{
      cursor: pointer;
    }
    p {
      // flex: 1;
      display: flex;
      align-items: center;
      max-width: 150px;
      &>span:nth-child(1){
        width: 50px;
      }
      &.text img{
        width: 14px;
        height: 14px;
        margin-left: 3px;
      }
      img {
        width: 18px;
        height: 18px;
      }
      a{
        flex:1;
        font-size: 14px;
        color: #B2BCCF;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        word-break: break-all;
      }

    }
  }
  .rank-list-nav{
    border-radius:10px 10px 0 0;
  }
  li,.rank-list-nav {
      display: flex;
      align-items: center;
      height: 50px;
      padding: 0 10px;
      &.border {
        border-bottom: 1px solid #2b4670;
        background: #2B364F;
        margin: 0 10px;
        span{
          color: #b2bccf;
        }
      }
      // &.active:hover {
      //   background: #5f97d5;
      //   cursor: pointer;
      // }
      p {
        width: 160px;
        display: flex;
        align-items: center;
        img {
          width: 28px;
          height: 28px;
          border-radius: 50%;
          margin-right: 10px;
        }
      }
      & > span:nth-child(1) {
        margin-right: 20px;
        width: 40px;
        text-align: center;
      }
       & > span:nth-child(4){
        width: 50px;
       }
      & > span:nth-child(3) {
        margin-right: 10px;
        width: 50px;
        // text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        word-break: break-all;
      }
      &.active > span:nth-child(4) {
        font-size: 14px;
        font-weight: 500;
        color: rgba(41, 255, 163, 0.8);
      }
      &.active > span {
        font-size: 14px;
      }
      & > p {
        // flex: 1;
        margin-right: 10px;
        span {
          // width:160px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          word-break: break-all;
        }
      }

      span {
        font-size: 14px;
        font-weight: 500;
        color: #fff;
      }
    }
  .user-list {
    // height: 100%;
    margin: 0 10px;
    flex: 1;
    overflow: auto;
    background: #2B364F;
    // border-radius:0 0 10px 10px;
    margin-top: 0px;
    &::-webkit-scrollbar {
        width: 4px;
        height: 4px;
      }
    
  }
}
</style>