<template>
  <div class="order-stats">
    <el-row :gutter="20">
      <el-col :span="12">
        <div class="order-stats-item flex-column">
          <div class="order-stats-value">
            {{ currentChoose[0].value }}<span>{{ currentChoose[0].unit }}</span>
          </div>
          <div class="order-stats-label">{{ currentChoose[0].label }}</div>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="order-stats-item flex-column">
          <div class="order-stats-value">
            {{ currentChoose[1].value }}<span>{{ currentChoose[1].unit }}</span>
          </div>
          <div class="order-stats-label">{{ currentChoose[1].label }}</div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { reactive, onMounted, watch, ref } from 'vue';
import { isEmpty } from '@/utils/index.js';

const props = defineProps({
  data: {
    type: String,
    default: () => '3',
  },
});

const state = reactive({
  year: [
    {
      label: '订单金额',
      value: '548.86',
      unit: '万元',
    },
    {
      label: '订单数量',
      value: '110554',
      unit: '笔',
    },
  ],
  day: [
    {
      label: '订单金额',
      value: '0.95',
      unit: '万元',
    },
    {
      label: '订单数量',
      value: '583',
      unit: '笔',
    },
  ],
  month: [
    {
      label: '订单金额',
      value: '34.85',
      unit: '万元',
    },
    {
      label: '订单数量',
      value: '16517',
      unit: '笔',
    },
  ],
  quarter: [
    {
      label: '订单金额',
      value: '117.51',
      unit: '万元',
    },
    {
      label: '订单数量',
      value: '46120',
      unit: '笔',
    },
  ],
});

const currentChoose = ref(state.year);

watch(
  () => props.data,
  (val) => {
    if (!isEmpty(val)) {
      if (val === '3') {
        currentChoose.value = state.year;
      } else if (val === '2') {
        currentChoose.value = state.quarter;
      } else if (val === '1') {
        currentChoose.value = state.month;
      } else if (val === '0') {
        currentChoose.value = state.day;
      }
    }
  },
  {
    deep: true,
    immediate: true,
  }
);
</script>

<style lang="scss" scoped>
.order-stats {
  padding: 20px;

  &-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  &-value {
    width: 160px;
    height: 160px;
    line-height: 100px;
    text-align: center;
    margin: 0 auto;
    background-image: url('@/assets/images/inputs/order.webp');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    font-size: 24px;
    font-weight: 400;
    color: #fff;
    position: relative;
    border-radius: 8px;
    overflow: hidden;

    span {
      font-size: 16px;
    }
  }

  &-label {
    width: 120px;
    height: 24px;
    line-height: 24px;
    margin: 10px auto 0;
    font-size: 16px;
    color: #fff;
    text-align: center;
    background: url('@/assets/images/inputs/bg_label.png') center center no-repeat;
    text-shadow:
      0 0 10px #01eeff,
      0 0 20px #01eeff,
      0 0 30px #01eeff;
  }
}
</style>
