<template>
  <div class="user-vip-list-container">
    <h2 class="page-title">VIP用户管理</h2>
    
    <el-card shadow="never" class="table-card">
      <el-table v-loading="loading" :data="list" stripe>
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="nickname" label="昵称" width="120" />
        <el-table-column prop="vipLevel" label="VIP等级" width="100">
          <template #default="{ row }">
            <el-tag type="warning" size="small">VIP {{ row.vipLevel }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="vipStartTime" label="开通时间" width="180" />
        <el-table-column prop="vipEndTime" label="到期时间" width="180" />
        <el-table-column prop="remainingDays" label="剩余天数" width="100">
          <template #default="{ row }">
            <span :class="{ 'text-danger': row.remainingDays < 7 }">
              {{ row.remainingDays }} 天
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button type="primary" size="small" link @click="handleRenew(row)">续费</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next"
          @size-change="loadList"
          @current-change="loadList"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import request from '@/utils/request'
import { API_ENDPOINTS } from '@/config/api'

const loading = ref(false)
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
const list = ref([])

const loadList = async () => {
  loading.value = true
  try {
    const response = await request.get(API_ENDPOINTS.USER_VIP_LIST, {
      params: { page: currentPage.value, pageSize: pageSize.value }
    })
    if (response.code === 200) {
      list.value = response.data.list || response.data || []
      total.value = response.data.total || list.value.length
    }
  } catch (error) {
    console.error('加载失败:', error)
    ElMessage.error('加载失败')
  } finally {
    loading.value = false
  }
}

const handleRenew = (row) => {
  ElMessage.info('续费功能开发中')
}

onMounted(() => loadList())
</script>

<style scoped>
.user-vip-list-container { padding: 0; }
.page-title { font-size: 24px; font-weight: bold; color: #333; margin: 0 0 20px 0; }
.table-card { margin-top: 20px; }
.pagination-container { display: flex; justify-content: flex-end; margin-top: 20px; }
.text-danger { color: #f56c6c; font-weight: bold; }
</style>

