<template>
  <section class="yesterday-prize-wrap">
    <normal-header
      :title="title"
      :rightText="rightText"
      :backType="1"
      @handleRightBtn="rightBtn">
    </normal-header>
    <div class="prize-list" :style="{ marginTop: `${44+statusBarHeight}Px`,marginBottom: `${50+homeIndicatorHeight}Px`}">
      <div class="item" v-for="(item, index) in rewardsList" :key="index">
        <img v-if="index<=2" :src="dealRankIcon(index)" alt="" class="ranking-icon">
        <p v-else class="icon-num" >{{index+1}}</p>
        <div class="item-right">
          <img :src="item.avatarImageUrl" alt="" class="doctor-photo">
          <div class="doctor-info">
            <p class="name">{{item.name}}</p>
            <p class="grade">昨日勤奋分:<span>{{item.score}}</span></p>
          </div>
          <p class="awards" v-if="index==0">{{firstAwards}}*1台</p>
          <p class="awards" v-if="1<=index&&index<=2">血压计*1支</p>
          <p class="awards" v-if="index>2">体温计*1支</p>
        </div>
      </div>
      <div class="no-more" v-if="rewardsList.length>=10">
        <span class="line"></span>
        <span class="text">到底啦</span>
        <span class="line"></span>
      </div>
    </div>
    <footer-button
      :btnText="btnText"
      :btnType="btnType">
    </footer-button>
  </section>
</template>

<script>
  import NormalHeader from '@/components/normal-header';
  import FooterButton from '@/components/footer-button';

  import { getYesterdayRanking } from '@/service/detailsAndRanking'

  import { getFirstAwards } from '@/utils'
  export default {
    name: "index",
    components: {
      NormalHeader,
      FooterButton
    },
    data() {
      return {
        showPop: false,
        title: '昨日获奖名单',
        rightText: '如何领奖',
        rewardsList: [],
        btnText: '今日我要拿奖',
        btnType: true,
        yesterdayDate: '',
        firstAwards: ''
      };
    },
    mounted() {
      this.getRewardList();

    },
    methods: {
      dealRankIcon(index) {
        if(index == 0) {
          return require('../../assets/img/icon-gold.png')
        } else if(index == 1) {
          return require('../../assets/img/icon-silver.png')
        } else if(index == 2) {
          return require('../../assets/img/icon-copper.png')
        }
      },
      rightBtn() {
        let url = 'https://phome.yunqueyi.com/template_v2/?id=599';
        let paramList = [
          {
            "key":"pageUrl",
            "value": url,
            "type":4,
            "seqNo":1
          }/*,{
            "key":"showTitle",
            "value": false,
            "type":1,
            "seqNo":2
          },{
            "key":"title",
            "value": '',
            "type":1,
            "seqNo":3
          }*/
        ]
        this.$rocNative.dispatchEventByModuleCode({
          modeCode: 'M300',
          jsonString: paramList
        });
      },
      getRewardList() {
        getYesterdayRanking().then(res => {
          if(res.code == '000000') {
            this.rewardsList = res.data.topRankList;
            this.yesterdayDate = res.data.yesterdayDate;
            this.firstAwards = getFirstAwards(this.yesterdayDate);
          }
        })
      }
    },
  }
</script>

<style scoped lang="less">
  @import 'index.less';
</style>