<template>
  <view class="container">
    <!-- 总览卡片 -->
    <view class="summary-card">
      <view class="summary-title-container">
        <view class="summary-icon"></view>
        <text class="summary-title">今日实发合计</text>
      </view>
      <view class="summary-amount">
        <text class="currency-symbol">¥</text>
        <text>{{ bonusData.realIncomeTotal || '0.00' }}</text>
      </view>
    </view>

    <!-- 奖金明细列表 -->
    <view class="details-card">
      <view class="detail-item">
        <text class="detail-label">奖金日期</text>
        <text class="detail-value date">{{
          bonusData.settleDate || formatDate
        }}</text>
      </view>
      <view v-for="(label, key) in detailLabels" :key="key" class="detail-item">
        <template
          v-if="key === 'repurRangeIncome' && bonusData.repurRangeIncome"
        >
          <text class="detail-label">{{ label }}</text>
          <text class="detail-value">
            <text class="currency-symbol-small">¥</text>
            {{ bonusData[key] || '0.00' }}
          </text>
        </template>
        <template v-else>
          <text class="detail-label">{{ label }}</text>
          <text class="detail-value">
            <text class="currency-symbol-small">¥</text>
            {{ bonusData[key] || '0.00' }}
          </text>
        </template>
      </view>
      <!-- 分割线 -->
      <view class="divider"></view>
      <!-- 小计 -->
      <view class="detail-item total">
        <text class="detail-label total-label">小计(¥)</text>
        <text class="detail-value total-value">
          <text class="currency-symbol-small">¥</text>
          {{ bonusData.retailRealSubtotal || '0.00' }}
        </text>
      </view>
    </view>
  </view>
</template>

<script>
import { realTimeBonus } from '@/config/bonus.js'
import dayjs from 'dayjs'
export default {
  data() {
    return {
      // 使用截图中的数据作为示例
      bonusData: {
        totalIssued: 0,
        date: '',
        retailRangeIncome: 0,
        retailSameLevelIncome: 0.0,
        retailAreaIncome: 0.0,
        // welfareLevelDifferenceIncome: 0.0,
        // welfareDividendIncome: 0.0,
        backPoints: 0,
        subtotal: 0,
      },
      detailLabels: {
        retailRangeIncome: '直推收益(¥)',
        retailSameLevelIncome: '平级收益(¥)',
        retailAreaIncome: '区域收益(¥)',
        repurRangeIncome: '复购级差收益(¥)',
        // welfareLevelDifferenceIncome: '福利级差收益(¥)',
        // welfareDividendIncome: '福利分红收益(¥)',
        backPoints: '重消收益(¥)',
      },
    }
  },
  onLoad() {},
  onShow() {
    this.getRealTimeBonus()
  },
  computed: {
    formatDate() {
      return dayjs(new Date()).format('YYYY-MM-DD')
    },
  },
  methods: {
    getRealTimeBonus() {
      realTimeBonus().then(res => {
        this.bonusData = res.rows?.[0] || {}
      })
    },
  },
}
</script>

<style scoped>
/* 主题色 */
:root {
  --primary-color: #005bac;
}

.container {
  background-color: #f7f8fa;
  min-height: 100vh;
  padding: 12px;
  box-sizing: border-box;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
    Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.summary-card {
  background: linear-gradient(45deg, #005bac, #0077d9);
  color: #ffffff;
  padding: 24px;
  border-radius: 16px;
  margin-bottom: 16px;
  box-shadow: 0 8px 16px rgba(0, 91, 172, 0.2);
  text-align: left;
}

.summary-title-container {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.summary-icon {
  width: 4px;
  height: 16px;
  background-color: #fff;
  border-radius: 2px;
  margin-right: 8px;
}

.summary-title {
  font-size: 16px;
  opacity: 0.9;
}

.summary-amount {
  font-size: 38px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
}

.currency-symbol {
  font-size: 22px;
  font-weight: 500;
  margin-right: 4px;
}

.currency-symbol-small {
  font-size: 14px;
  font-weight: 400;
  color: #666;
  margin-right: 2px;
}

.details-card {
  background-color: #ffffff;
  padding: 8px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 0;
}

.divider {
  height: 1px;
  background-color: #f2f2f2;
  margin: 0;
}

.detail-label {
  font-size: 15px;
  color: #333;
}

.detail-value {
  font-size: 16px;
  color: #333;
  font-weight: 500;
  display: flex;
  align-items: center;
}

.detail-value.date {
  color: #999;
  font-weight: 400;
}

.total {
  padding-top: 18px;
}

.total-label {
  font-weight: 600;
}

.total-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--primary-color);
}

.total-value .currency-symbol-small {
  color: var(--primary-color);
  font-size: 16px;
}
</style>
