<template>
  <div class="team-report">
    <h2>今日团队实时战报</h2>
    <div class="report-grid">
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">团队总通话</span>
          <span class="card-trend positive">{{ weekTotalData.week_total_call?.team_data?.current_rate_last_current || '0%' }} vs 上期</span>
        </div>
        <div class="card-value">{{ weekTotalData.week_total_call?.team_data?.total_current_week_call || 0 }} 次</div>
      </div>
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">有效通话时长</span>
          <span class="card-trend negative">{{ weekTotalData.week_total_call?.team_data?.current_rate_last_current || '0%' }} vs 上期</span>
        </div>
        <div class="card-value">{{ formatDuration(weekTotalData.week_total_call?.team_data?.total_call_duration)||0 }} 小时</div>
      </div>
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">新增意向客户</span>
          <span class="card-trend positive">{{ weekTotalData.week_add_customer_total?.team_data?.week_rate_last_week || '0%' }} vs 上期</span>
        </div>
        <div class="card-value">{{ weekTotalData.week_add_customer_total?.team_data?.total_week_add_customer || 0 }} 人</div>
      </div>
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">新增成交</span>
          <span class="card-trend positive">{{ weekTotalData.week_add_deal_total?.team_data?.week_rate_last_week || '0%' }} vs 上期</span>
        </div>
        <div class="card-value">{{ weekTotalData.week_add_deal_total?.team_data?.total_week_add_deal || 0 }} 单</div>
      </div>
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">月度总业绩</span>
          <span class="card-trend positive">+8% vs 上月</span>
        </div>
        <div class="card-value">{{ formatCurrency(weekTotalData.week_add_fee_total?.total_add_fee || 0) }} 元</div>
      </div>
      <div class="report-card">
        <div class="card-header">
          <span class="card-title">定金转化率</span>
          <span class="card-trend positive">{{ weekTotalData.pay_deposit_to_money_rate?.team_data?.week_vs_last_week || '0%' }} vs 上期</span>
        </div>
        <div class="card-value">{{ weekTotalData.pay_deposit_to_money_rate?.team_data?.week_pay_deposit_to_money_rate || '0%' }} </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { watch } from 'vue'

// 定义props
const props = defineProps({
  weekTotalData: {
    type: Object,
    default: () => ({
      week_total_call: {},
      week_add_customer_total: {},
      week_add_deal_total: {},
      week_add_fee_total: {},
      pay_deposit_to_money_rate: {}
    })
  }
})

// 监听数据变化，用于调试
watch(() => props.weekTotalData, (newData) => {
  console.log('TeamReport 收到的数据:', newData)
}, { deep: true, immediate: true })

// 格式化时长（分钟转小时）
const formatDuration = (minutes) => {
  if (!minutes) return '0'
  const hours = (minutes / 60).toFixed(1)
  return hours
}

// 格式化货币
const formatCurrency = (amount) => {
  if (!amount) return '0'
  return amount.toLocaleString()
}
</script>

<style lang="scss" scoped>
// Team Report
.team-report {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  
  h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 1.5rem 0;
  }
  
  .report-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
  
  .report-card {
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0.5rem;
    }
    
    .card-title {
      color: #64748b;
      font-size: 0.85rem;
    }
    
    .card-trend {
      font-size: 0.75rem;
      font-weight: 500;
      
      &.positive {
        color: #059669;
      }
      
      &.negative {
        color: #dc2626;
      }
    }
    
    .card-value {
      font-size: 1.5rem;
      font-weight: bold;
      color: #1e293b;
    }
  }
}

// 移动端适配
@media (max-width: 768px) {
  .team-report {
    padding: 1rem;
    
    h2 {
      font-size: 1.1rem;
      margin-bottom: 1rem;
    }
    
    .report-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 0.75rem;
    }
    
    .report-card {
      padding: 0.75rem;
      
      .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
      }
      
      .card-title {
        font-size: 0.8rem;
      }
      
      .card-trend {
        font-size: 0.7rem;
      }
      
      .card-value {
        font-size: 1.25rem;
      }
    }
  }
}

@media (max-width: 480px) {
  .team-report {
    padding: 0.75rem;
    border-radius: 8px;
  }
}
</style>