<template>
  <div class="container">
    <div class="user">
      <img class="user-avatar" :src="userData.avatar" />
      <div>
        <p class="user-name">{{ userData.name }}</p>
        <span class="user-score">{{ userData.totalScore }}积分</span>
      </div>
    </div>
    
    <van-button 
      round 
      hairline 
      size="mini" 
      icon="arrow-down" 
      color="#ff5d23"
      @click="showPicker = true"
    >
      {{ date.text }}
    </van-button>
    
    <van-popup v-model:show="showPicker" round position="bottom">
      <van-picker 
        :columns="dateList" 
        @cancel="cancel" 
        @confirm="confirm" 
      />
    </van-popup>
  </div>
</template>

<script>
import axios from "axios";

export default {
  props: ["dateList", "date"],
  data() {
    return {
      showPicker: false,
      userData: {},
    };
  },
  methods: {
    fetchUserData() {
      const that = this;
      axios.get("/api/service/userScore").then(function (response) {
        const { error, data = {} } = response.data;
        if (error === 0) {
          that.userData = data || {};
        }
      });
    },
    cancel() {
      this.showPicker = false;
    },
    confirm({ selectedOptions }) {
      const data = selectedOptions[0];
      this.showPicker = false;
      this.$emit("updateYear", data);
    },
  },
  mounted() {
    this.fetchUserData();
  },
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  margin: 0;
  background: transparent !important;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent !important;
}

.user > div,
.user > div > p,
.user > div > span {
  background: transparent !important;
}

:deep(.van-button) {
  background: transparent !important;
}

.user-avatar {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.user-score {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
</style>
