<template>
  <div class="container">
    <!-- 导航栏 -->
    <div class="nav-bar">
      <div class="back-btn" @click="$router.back()">
        <i class="arrow-left"></i>
      </div>
      <div class="title">礼品福利</div>
    </div>

    <!-- 记录列表 -->
    <div class="content">
      <div class="records-card">
        <div class="card-header">
          <div class="header-title">礼品福利记录</div>
        </div>
        <div class="record-list">
          <div v-if="records.length === 0" class="empty-state">
            <div class="empty-text">暂无礼品记录</div>
          </div>
          <div v-else class="table-container">
            <div class="table-header">
              <div class="header-item prize">奖品名称</div>
              <div class="header-item status">领取状态</div>
              <div class="header-item date">中奖日期</div>
            </div>
            <div class="table-body">
              <div class="record-item" v-for="(item, index) in records" :key="index">
                <div class="record-main">
                  <div class="record-prize">{{ item.prize_name }}</div>
                  <div class="record-status">
                    <div class="status-badge" :class="getStatusClass(item.status)">
                      {{ getStatusText(item.status) }}
                    </div>
                  </div>
                  <div class="record-date">{{ item.addtime }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/home';
import { getPrizeRecords } from '@/api/profile';

export default {
  name: 'LeverList',
  data() {
    return {
      userInfo: {},
      records: []
    }
  },
  created() {
    this.getUserInfo();
    this.getRecords();
  },
  methods: {
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        console.error('获取用户信息失败:', error);
      }
    },
    async getRecords() {
      try {
        const res = await getPrizeRecords();
        this.records = res.data || [];
      } catch (error) {
        console.error('获取礼品记录失败:', error);
      }
    },
    getStatusText(status) {
      return status === 0 ? '申请邮寄' : '已领取';
    },
    getStatusClass(status) {
      return status === 0 ? 'status-pending' : 'status-received';
    }
  }
}
</script>

<style scoped>
.container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
}

.nav-bar {
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 20px;
  min-height: calc(100vh - 56px);
}

.records-card {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.card-header {
  background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
  padding: 16px 20px;
}

.header-title {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.record-list {
  padding: 8px 0;
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
}

.empty-text {
  color: #9ca3af;
  font-size: 16px;
}

.table-container {
  padding: 0 20px;
}

.table-header {
  display: flex;
  align-items: center;
  padding: 16px 0;
  border-bottom: 2px solid #e5e7eb;
  background: #f8f9fa;
  margin: 0 -20px 0 -20px;
  padding-left: 20px;
  padding-right: 20px;
}

.header-item {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.prize {
  flex: 1;
  text-align: left;
}

.status {
  flex: 0 0 120px;
  text-align: center;
}

.date {
  flex: 0 0 140px;
  text-align: right;
}

.table-body {
  max-height: 60vh;
  overflow-y: auto;
}

.record-item {
  padding: 16px 0;
  border-bottom: 1px solid #f3f4f6;
  transition: all 0.3s ease;
}

.record-item:hover {
  background: #f8f9fa;
  margin: 0 -20px;
  padding-left: 20px;
  padding-right: 20px;
}

.record-item:last-child {
  border-bottom: none;
}

.record-main {
  display: flex;
  align-items: center;
}

.record-prize {
  flex: 1;
  font-size: 15px;
  color: #374151;
  font-weight: 500;
  text-align: left;
}

.record-status {
  flex: 0 0 120px;
  display: flex;
  justify-content: center;
}

.record-date {
  flex: 0 0 140px;
  font-size: 13px;
  color: #6b7280;
  text-align: right;
}

.status-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  border: 2px solid;
}

.status-pending {
  background: #fef3c7;
  color: #d97706;
  border-color: #f59e0b;
}

.status-received {
  background: #dcfce7;
  color: #166534;
  border-color: #22c55e;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .nav-bar {
    height: 50px;
    padding: 0 12px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
  }
  
  .title {
    font-size: 16px;
  }
  
  .content {
    padding: 16px;
  }
  
  .card-header {
    padding: 12px 16px;
  }
  
  .header-title {
    font-size: 15px;
  }
  
  .table-container {
    padding: 0 16px;
  }
  
  .table-header {
    margin: 0 -16px 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
  
  .header-item {
    font-size: 13px;
  }
  
  .status {
    flex: 0 0 80px;
  }
  
  .date {
    flex: 0 0 100px;
  }
  
  .record-item {
    padding: 14px 0;
  }
  
  .record-item:hover {
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
  
  .record-prize {
    font-size: 14px;
  }
  
  .record-status {
    flex: 0 0 80px;
  }
  
  .record-date {
    flex: 0 0 100px;
    font-size: 12px;
  }
  
  .status-badge {
    padding: 4px 12px;
    font-size: 11px;
  }
  
  .empty-state {
    padding: 40px 16px;
  }
  
  .empty-text {
    font-size: 14px;
  }
  
  .table-body {
    max-height: 50vh;
  }
}
</style> 