<template>
  <div class="quota-control-container">
    <div class="page-header">
      <PageTitle title="额度控制" />
      <el-button type="danger" @click="handleApplyQuota">额度申请</el-button>
    </div>

    <!-- 额度统计卡片 -->
    <div class="quota-cards">
      <div class="quota-card">
        <div class="card-icon"><el-icon><CreditCard /></el-icon></div>
        <div class="card-info">
          <div class="card-label">当前额度 ></div>
          <div class="card-value">32</div>
        </div>
      </div>
      <div class="quota-card">
        <div class="card-info">
          <div class="card-label">剩余可用额度 ></div>
          <div class="card-value">8,831.00</div>
        </div>
      </div>
      <div class="quota-card">
        <div class="card-info">
          <div class="card-label">已使用额度 ></div>
          <div class="card-value">8,831.00</div>
        </div>
      </div>
    </div>

    <!-- 信用额度申请记录 -->
    <div class="section-title">信用额度申请记录</div>
    <el-table :data="recordList" border>
      <el-table-column prop="applyTime" label="申请时间" min-width="120" align="center" />
      <el-table-column prop="monthAmount" label="月度采购金额" min-width="120" align="center" />
      <el-table-column prop="yearAmount" label="预估年度采购金额" min-width="140" align="center" />
      <el-table-column prop="creditAmount" label="申请信用金额" min-width="120" align="center" />
      <el-table-column prop="category" label="主要采购类目" min-width="120" align="center" />
      <el-table-column prop="status" label="申请状态" min-width="100" align="center">
        <template #default="{ row }">
          <span :class="['status-text', getStatusClass(row.status)]">{{ row.status }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { CreditCard } from '@element-plus/icons-vue'
import { PageTitle } from '@/components'

const router = useRouter()

const recordList = ref([
  { id: 1, applyTime: '2025-11-30', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '待审批' },
  { id: 2, applyTime: '2025-11-29', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '已通过' },
  { id: 3, applyTime: '2025-11-25', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '已通过' },
  { id: 4, applyTime: '2025-12-05', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '已通过' },
  { id: 5, applyTime: '2025-12-07', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '已通过' },
  { id: 6, applyTime: '2025-12-07', monthAmount: '0.00', yearAmount: '0.00', creditAmount: '0.00', category: '食品饮料', status: '已通过' }
])

const getStatusClass = (status: string) => {
  if (status === '已通过') return 'success'
  if (status === '待审批') return 'warning'
  return ''
}

const handleApplyQuota = () => {
  router.push('/cost/quotaControl/apply')
}
</script>

<style scoped lang="scss">
.quota-control-container {
  padding: 20px;
  background: #fff;
  min-height: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  :deep(.page-title) { margin-bottom: 0; }
}

.quota-cards {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;

  .quota-card {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 4px;

    .card-icon {
      width: 40px;
      height: 40px;
      background: #409eff;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-size: 20px;
    }

    .card-info {
      .card-label { font-size: 13px; color: #999; margin-bottom: 5px; }
      .card-value { font-size: 24px; font-weight: bold; color: #333; }
    }
  }
}

.section-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 15px;
}

:deep(.el-table) {
  th.el-table__cell {
    background: #fafafa;
    font-weight: 500;
    color: #333;
  }
  .el-table__cell {
    padding: 10px 0;
  }
}

.status-text {
  &.success { color: #67c23a; }
  &.warning { color: #e6a23c; }
}
</style>
