<template>
  <div class="stat-cards-container">
    <div class="stat-card" v-for="(item, idx) in props.numberList" :key="idx">
      <div class="stat-card-title">{{ item.title }}</div>
      <div class="stat-card-value">
        <div class="card-value-top">
          <div>
            <p class="pro-title">{{ item.protitle }}</p>
            <p class="pro-value">
              {{ item.proValue }}<span v-if="item.proValue !== '*'">亿元</span>
            </p>
          </div>
          <div>
            <p class="pro-title">{{ item.thirdTtile }}</p>
            <p class="pro-value">
              {{ item.thirdValue }}
              <span v-if="item.thirdValue !== '*'">亿元</span>
            </p>
          </div>
        </div>
        <div class="card-value-bottom">
          <div>
            <p class="pro-title">2025年累计完成</p>
            <p class="pro-value">
              {{ item.cumulativeValue
              }}<span v-if="item.cumulativeValue !== '*'">亿元</span>
            </p>
          </div>
          <div class="value-bottom-right">
            <p class="comparison">累计同期环比</p>
            <p
              class="comparison-value"
              :class="{ 'down-trend': isDownTrend(item.compareValue) }"
            >
              {{ item.compareValue }}
              <el-icon
                class="trend-icon"
                :class="{ 'down-trend': isDownTrend(item.compareValue) }"
              >
                <span v-if="item.compareValue !== '*'">
                  <Bottom v-if="isDownTrend(item.compareValue)" />
                  <Top v-else />
                </span>
              </el-icon>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive, watch, ref } from "vue";
import { Top, Bottom } from "@element-plus/icons-vue";

const props = defineProps({
  numberList: {
    type: Array,
    default: () => [],
  },
});

// 判断是否为下降趋势
const isDownTrend = (compareValue) => {
  if (!compareValue || compareValue === '*') return false;
  
  // 处理百分比值
  const value = compareValue.toString();
  
  // 如果包含负号，表示下降
  if (value.includes('-')) {
    return true;
  }
  
  // 如果包含百分号，提取数值判断
  if (value.includes('%')) {
    const numValue = parseFloat(value.replace('%', ''));
    return numValue < 0;
  }
  
  // 如果是纯数字
  const numValue = parseFloat(value);
  if (!isNaN(numValue)) {
    return numValue < 0;
  }
  
  // 默认情况下，根据业务逻辑判断（运营成本下降是好的，显示绿色）
  // 这里简化处理，如果负数则下降，正数则上升
  return false;
};
</script>

<style scoped lang="less">
.stat-cards-container {
  display: flex;
  justify-content: center;
  align-items: center;
  .stat-card {
    .vw(width, 180);
    .vw(border-radius, 5);
    .vw(margin-right,10);
    .vw(padding, 10);
    background-image: url("@/assets/images/complete.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    .stat-card-title {
      .font(16);
      .vh(margin-top,-8);
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .stat-card-value {
      .font(12);
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .vh(margin-top,10);
      .card-value-top {
        // .vh(margin-bottom,10);
      }
      .card-value-top,
      .card-value-bottom {
        display: flex;
        justify-content: space-between;
        .pro-title {
          .font(10);
        }
        .pro-value {
          .font(16);
          font-family: "DIN";
          color: @Color;
          span {
            .font(10);
            // font-weight: 400;
          }
        }
      }
      .value-bottom-right {
        .vh(margin-top,10);
        .font(10);
        .comparison {
          font-family: "Alibaba PuHuiTi";
        }
        .comparison-value {
          color: #ff4757;
          display: flex;
          align-items: center;
          gap: 2px;

          &.down-trend {
            color: #32d25a;
          }

          .trend-icon {
            .font(12);
            color: #ff4757;

            &.down-trend {
              color: #32d25a;
            }
          }
        }
      }
    }
  }
}
</style>
