<template>
  <div class="ranking">
    <img class="activityTitle" :src="require('../../../assets/img/vote.png')" />
    <div class="subTitle">123</div>
    <div class="topThree">
      <div class="topUser">
        <div
          class="flexEnd"
          v-if="vote[0][1]"
          @click="() => toNewPage(vote[0][1].phone)"
        >
          <div class="userImg">
            <img
              :src="require('../../../assets/img/2.png')"
              alt=""
              class="hg"
            />
          </div>
          <div class="userName" v-text="vote[0][1].name"></div>
          <div class="userP" v-text="vote[0][1].votes"></div>
        </div>
      </div>
      <div class="topUser">
        <div
          class="flexEnd flexCenter"
          v-if="vote[0][0]"
          @click="() => toNewPage(vote[0][0].phone)"
        >
          <div class="userImg">
            <img
              :src="require('../../../assets/img/1.png')"
              alt=""
              class="hg"
            />
          </div>
          <div class="userName" v-text="vote[0][0].name"></div>
          <div class="userP" v-text="vote[0][0].votes"></div>
        </div>
      </div>
      <div class="topUser">
        <div
          class="flexEnd"
          v-if="vote[0][2]"
          @click="() => toNewPage(vote[0][2].phone)"
        >
          <div class="userImg">
            <img
              :src="require('../../../assets/img/3.png')"
              alt=""
              class="hg"
            />
          </div>
          <div class="userName" v-text="vote[0][2].name"></div>
          <div class="userP" v-text="vote[0][2].votes"></div>
        </div>
      </div>
    </div>
    <van-cell-group class="list" inset v-if="vote[1] && vote[1].length">
      <van-row
        justify="center"
        class="van-hairline--bottom"
        v-for="(i, o) in (vote[1] || [])"
        :key="o"
        @click="() => toNewPage(i.phone)"
      >
        <van-col span="2">
          <div class="jp" v-text="i.top"></div>
        </van-col>
        <van-col span="7" v-text="i.name"></van-col>
        <van-col span="8" v-text="i.votes + '票'"></van-col>
        <van-col span="7">详情</van-col>
      </van-row>
    </van-cell-group>
    <van-search
      shape="round"
      left-icon=""
      right-icon="search"
      v-model="search"
      @search="searchuser"
      placeholder="搜索感兴趣的选手"
    />
  </div>
</template>
<script setup>
import { ref } from "vue";
import { voteList } from "@/api/worldCup.js";
import { Dialog } from "vant";
// import { onMounted, reactive } from "vue";
// import { isIpad, isIpod, isIphone } from "../../utils/isTerminal";
/**
 * window.$originData.orginParames.title 页面标题
 * window.$originData.orginParames.parameters 固定参数值
 * window.$originData.urlParames url参数
 */
const search = ref("");
const vote = ref([[], []]);
voteList().then(r => {
  const list = r || [];
  const top3 = [];
  const orther = [];
  for (let i = 0; i < list.length; i++) {
    const v = list[i];
    if (i < 3) top3.push(v);
    else orther.push(v);
  }
  vote.value = [top3, orther];
});

function toNewPage(phone) {
  location.href = "./WorldCupDetail.html?phone=" + phone;
}

function searchuser() {
  console.log(search.value);
  voteList({
    name: search.value,
  }).then(r => {
    console.log(r);
    const searchDetail = [];
    for (let i = 0; i < (r || []).length; i++) {
      const v = (r || [])[i];
      searchDetail.push(
        <van-row
          justify="center"
          class="van-hairline--bottom"
          onclick={() => toNewPage(v.phone)}
        >
          <van-col span="9">{v.name}</van-col>
          <van-col span="8">{v.votes + '票'}</van-col>
          <van-col span="7">详情</van-col>
        </van-row>
      );
    }

    Dialog.alert({
      title: "",
      messageAlign: "left",
      confirmButtonText: "关闭查询结果",
      message: () => (
        <van-cell-group class="list" inset>
          {searchDetail}
        </van-cell-group>
      ),
    });
  });
}
</script>
<style lang="scss">
.ranking {
  $colorFFF: #ffffff;
  .topThree {
    position: relative;
    z-index: 1;
    background-image: url(../../../assets/img/topThree.png);
    background-size: 100% 100%;
    margin: 0 16px;
    height: 206px;
    display: flex;
    .topUser {
      flex: 1;
      text-align: center;
      flex-direction: row-reverse;
      display: flex;
      .flexEnd {
        align-self: flex-end;
        flex: 1;
        padding-bottom: 20px;
      }
      .flexCenter {
        padding-bottom: 50px;
      }
      .userImg {
        width: 70px;
        height: 95px;
        margin: 0 auto;
        overflow: hidden;
        .hg {
          width: 100%;
          height: 100%;
        }
      }
      .userName {
        font-size: 12px;
        padding: 5px 0 5px 0;
        font-family: PingFang SC;
        font-weight: 400;
        color: #ffffff;
      }
      .userP {
        color: #ffc834;
        font-size: 19px;
        font-family: PingFang SC;
        font-weight: 600;
        color: #ffc834;
      }
    }
  }
  .activityTitle {
    padding-top: 34px;
    padding-bottom: 21px;
  }
  .subTitle {
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 17px;
    margin: 0 21px;
  }
  .list {
    position: relative;
    z-index: 0;
    margin: -25px 25px 0 25px;
    padding-top: 20px;
    background-color: #00872c;
    border: 1px solid #000;
    .van-row {
      margin: 0 6px;
    }
    .van-hairline--bottom:after {
      border-color: #333;
    }
    .van-col {
      color: $colorFFF;
      font-size: 14px;
      height: 3em;
      line-height: 3em;
      position: relative;
      text-align: center;
    }
    .jp {
      width: 23px;
      height: 28px;
      line-height: 23px;
      display: block;
      margin: 0 auto;
      position: absolute;
      color: #956116;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-image: url("../../../assets/img/jp.png");
      background-size: 100% 100%;
    }
  }
  .van-search {
    background-color: transparent;
  }
}
</style>
