<template>
  <div class="settlement-card">
    <div class="card-header">
      <div class="title-container">
        <h2 class="card-title">交易结算数据</h2>
        <div class="title-tibetan">ཚོང་འདུས་རྩིས་ཞིབ་གྲངས་ཐོ།</div>
      </div>
      <div class="pagination-info">
        <span>第 {{ currentPage + 1 }} 页 / 共 {{ totalPages }} 页</span>
        <span class="total-count">总计 {{ settlementData.length }} 条记录</span>
      </div>
    </div>
    
    <div class="table-container">
      <table class="settlement-table">
        <thead>
          <tr>
            <th>
              <div class="header-text">结算方</div>
              <div class="header-tibetan">རྩིས་ཞིབ་པ།</div>
            </th>
            <th>
              <div class="header-text">车牌号</div>
              <div class="header-tibetan">མོ་ཏ་ཨང་གྲངས།</div>
            </th>
            <th>
              <div class="header-text">结算牦牛数</div>
              <div class="header-tibetan">རྩིས་ཞིབ་གཡག་གྲངས།</div>
            </th>
            <th>
              <div class="header-text">结算时间</div>
              <div class="header-tibetan">རྩིས་ཞིབ་དུས་ཚོད།</div>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(record, index) in currentPageData" :key="record.id">
            <td>
              <div class="seller-name">{{ record.settler }}</div>
            </td>
            <td>
              <div class="license-plate">{{ record.licensePlate }}</div>
            </td>
            <td>
              <div class="yak-count">{{ record.yakCount }}头</div>
            </td>
            <td>
              <div class="settlement-time">{{ record.settlementTime }}</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    
    <div class="table-footer">
      <div class="auto-flip-indicator">
        <div class="flip-icon">⏰</div>
        <span>{{ countdown }}秒后自动翻页</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'

// 分页相关
const currentPage = ref(0)
const pageSize = 8
const countdown = ref(10)
let timer = null
let countdownTimer = null

// 模拟交易结算数据
const settlementData = ref([
  { id: 1, settler: '扎西多吉', licensePlate: '藏A·12345', yakCount: 15, settlementTime: '09:30' },
  { id: 2, settler: '次仁央吉', licensePlate: '藏B·67890', yakCount: 8, settlementTime: '09:45' },
  { id: 3, settler: '洛桑旺堆', licensePlate: '藏C·11111', yakCount: 22, settlementTime: '10:15' },
  { id: 4, settler: '普布扎西', licensePlate: '藏A·22222', yakCount: 12, settlementTime: '10:30' },
  { id: 5, settler: '德吉梅朵', licensePlate: '藏B·33333', yakCount: 18, settlementTime: '11:00' },
  { id: 6, settler: '格桑平措', licensePlate: '藏C·44444', yakCount: 6, settlementTime: '11:20' },
  { id: 7, settler: '拉巴次仁', licensePlate: '藏A·55555', yakCount: 25, settlementTime: '11:45' },
  { id: 8, settler: '卓玛央金', licensePlate: '藏B·66666', yakCount: 14, settlementTime: '12:10' },
  { id: 9, settler: '索朗多吉', licensePlate: '藏C·77777', yakCount: 20, settlementTime: '12:30' },
  { id: 10, settler: '白玛曲珍', licensePlate: '藏A·88888', yakCount: 9, settlementTime: '13:00' },
  { id: 11, settler: '丹增诺布', licensePlate: '藏B·99999', yakCount: 16, settlementTime: '13:25' },
  { id: 12, settler: '央吉拉姆', licensePlate: '藏C·00000', yakCount: 11, settlementTime: '13:50' },
  { id: 13, settler: '土登群培', licensePlate: '藏A·12121', yakCount: 28, settlementTime: '14:15' },
  { id: 14, settler: '曲珍旺姆', licensePlate: '藏B·23232', yakCount: 7, settlementTime: '14:40' },
  { id: 15, settler: '阿旺洛桑', licensePlate: '藏C·34343', yakCount: 19, settlementTime: '15:05' },
  { id: 16, settler: '措姆拉姆', licensePlate: '藏A·45454', yakCount: 13, settlementTime: '15:30' },
  { id: 17, settler: '平措扎西', licensePlate: '藏B·56565', yakCount: 24, settlementTime: '15:55' },
  { id: 18, settler: '桑杰卓玛', licensePlate: '藏C·67676', yakCount: 10, settlementTime: '16:20' },
  { id: 19, settler: '尼玛次仁', licensePlate: '藏A·78787', yakCount: 17, settlementTime: '16:45' },
  { id: 20, settler: '央金拉姆', licensePlate: '藏B·89898', yakCount: 21, settlementTime: '17:10' }
])

// 计算总页数
const totalPages = computed(() => {
  return Math.ceil(settlementData.value.length / pageSize)
})

// 当前页数据
const currentPageData = computed(() => {
  const start = currentPage.value * pageSize
  const end = start + pageSize
  return settlementData.value.slice(start, end)
})

// 当前页合计
const currentPageTotal = computed(() => {
  return currentPageData.value.reduce((sum, record) => sum + record.yakCount, 0)
})

// 翻页函数
const nextPage = () => {
  currentPage.value = (currentPage.value + 1) % totalPages.value
  countdown.value = 10
}

// 启动定时器
const startTimer = () => {
  // 翻页定时器
  timer = setInterval(() => {
    nextPage()
  }, 10000)
  
  // 倒计时定时器
  countdownTimer = setInterval(() => {
    countdown.value--
    if (countdown.value <= 0) {
      countdown.value = 10
    }
  }, 1000)
}

// 停止定时器
const stopTimer = () => {
  if (timer) {
    clearInterval(timer)
    timer = null
  }
  if (countdownTimer) {
    clearInterval(countdownTimer)
    countdownTimer = null
  }
}

onMounted(() => {
  startTimer()
})

onUnmounted(() => {
  stopTimer()
})
</script>

<style scoped>
.settlement-card {
  height: 100%;
  background: rgba(15, 25, 45, 0.4);
  backdrop-filter: blur(20px) saturate(180%);
  border-radius: 32px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 
    0 16px 64px rgba(0, 0, 0, 0.3),
    0 8px 32px rgba(64, 158, 255, 0.1),
    inset 0 2px 0 rgba(255, 255, 255, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.title-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.card-title {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #409EFF 0%, #67C23A 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
}

.title-tibetan {
  font-size: 28px;
  color: #67C23A;
  font-weight: 600;
  opacity: 0.8;
}

.pagination-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 14px;
  color: #ffffff;
  opacity: 0.8;
}

.total-count {
  color: #409EFF;
  font-weight: 500;
}

.table-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.settlement-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 20px;
  flex: 1;
}

.settlement-table thead th {
  background: rgba(64, 158, 255, 0.2);
  color: #409EFF;
  font-weight: 600;
  padding: 16px 12px;
  text-align: center;
  border-bottom: 2px solid rgba(64, 158, 255, 0.3);
  vertical-align: middle;
}

.header-text {
  font-size: 22px;
  line-height: 1.2;
  margin-bottom: 4px;
}

.header-tibetan {
  font-size: 18px;
  opacity: 0.8;
  line-height: 1.2;
}

.settlement-table tbody tr {
  transition: background-color 0.3s ease;
}

.settlement-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.05);
}

.settlement-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.settlement-table tbody td {
  padding: 14px 12px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 20px;
  vertical-align: middle;
}

.seller-name {
  font-weight: 600;
  font-size: 22px;
  color: #67C23A !important;
}

.license-plate {
  font-family: 'Courier New', monospace;
  font-weight: 500;
  font-size: 20px;
  color: #409EFF !important;
}

.yak-count {
  font-size: 26px;
  font-weight: 700;
  color: #F56C6C !important;
}

.settlement-time {
  font-size: 20px;
  color: #E6A23C !important;
}

.table-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.auto-flip-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: #ffffff;
  opacity: 0.8;
}

.flip-icon {
  font-size: 16px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.summary-stats {
  font-size: 18px;
  font-weight: 600;
  color: #67C23A;
}
</style> 