<template>
  <div class="go-examine">
    <div class="panel">
      <div class="store-name">
        <el-image :src="homeIcon" class="homeIcon" />
        <div>{{ storeName }}</div>
      </div>
      <div class="expire">店铺到期时间：{{ expireDate }}</div>
    </div>

    <div class="verify-row">
      <el-input outline="none" v-model="voucherCode" placeholder="请输入劵码" class="verify-input" clearable />
      <el-button type="primary" class="verify-btn" @click="handleVerify"> 验 券 </el-button>
    </div>

    <div class="stats">
      <div class="wallet">
        <div class="stat-card">
          <div class="stat-title">店铺钱包（元）</div>
          <div class="stat-value">
            {{ walletAmount }}
          </div>
        </div>
        <el-image :src="homeWallet" class="walletImg" />
      </div>
      <div class="wallet">
        <div class="stat-card">
          <div class="stat-title">今日订单量（单）</div>
          <div class="stat-value">
            {{ todayOrders }}
          </div>
        </div>
        <el-image :src="homeOrder" class="walletImg" />
      </div>
      <div class="wallet">
        <div class="stat-card">
          <div class="stat-title">今日收益（元）</div>
          <div class="stat-value">
            {{ todayRevenue }}
          </div>
        </div>
        <el-image :src="homeIncome" class="walletImg" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import homeIcon from "../../../assets/images/home-icon.png";
import homeWallet from "../../../assets/images/home-wallet.png";
import homeOrder from "../../../assets/images/home-order.png";
import homeIncome from "../../../assets/images/home-income.png";
import { verifyOrder, verifyCoupon, getTodayOrderCount, getTodayIncome } from "@/api/modules/homeEntry.ts";
import { localGet } from "@/utils/index";
// 数据（可根据实际接口替换）
const storeName = ref("时间图书馆");
const expireDate = ref("2027/10/29");
const voucherCode = ref("");

const walletAmount = ref(0);
const todayOrders = ref(0);
const todayRevenue = ref(0);
onMounted(() => {
  getOrder();
  getInCome();
});
const getOrder = async () => {
  const res: any = await getTodayOrderCount({ storeId: localGet("geeker-user").storeId });
  if (res.code == 200) {
    todayOrders.value = res.data;
  }
};
const getInCome = async () => {
  const res: any = await getTodayIncome({ storeId: localGet("geeker-user").storeId });
  if (res.success) {
    todayRevenue.value = res.data;
  }
};
const handleVerify = async () => {
  // 调用验券接口
  if (!voucherCode.value) return;
  const res: any = await verifyOrder({ orderCode: voucherCode.value });
  if (res.code == 200) {
    let i = {
      quanCode: voucherCode.value,
      storeId: 120
    };
    const res1 = await verifyCoupon(i);
    if (res && res.data.code === "true") {
      ElMessage.success(res.msg);
    }
  }
  console.log("verify voucher:", voucherCode.value);
};
</script>

<style scoped lang="scss">
.go-examine {
  box-sizing: border-box;
  width: 100%;
  height: calc(100vh - 105px);
  overflow: hidden;
  background: url("../../../assets/images/home-bg.png") center center no-repeat;
  background-size: cover;
  .panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 105px;
    padding: 16px;
    margin-bottom: 16px;
    background: #ffffff;
    background: linear-gradient(90deg, #6c8ff8 0%, rgb(255 255 255 / 0%) 100%);
    border: 1px solid #e4e7ed;
    border-radius: 10px;
    .store-name {
      display: flex;
      align-items: center;
      font-size: 24px;
      font-weight: 600;
      color: #ffffff;
      .homeIcon {
        width: 76px;
        height: 76px;
        margin-right: 8px;
        margin-left: 25px;
      }
    }
    .expire {
      font-size: 13px;
      color: #606266;
    }
  }
  .verify-row {
    display: flex;
    align-items: center;
    height: 228px;
    padding: 0 50px;
    background: linear-gradient(90deg, #6c8ff8 0%, rgb(255 255 255 / 0%) 100%);
    border-radius: 10px;
    .verify-input {
      height: 132px;
      font-size: 30px;

      // 去除输入框获得焦点时的默认蓝框
      :deep(.el-input__wrapper) {
        outline: none;
        box-shadow: none;
      }
    }
    .verify-btn {
      width: 356px;
      height: 132px;
      font-size: 30px;
      background: #6c8ff8;
      border: none;
    }
  }
  .stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 30px;
    .wallet {
      display: flex;
      align-items: center;
      justify-content: center;
      background: #ffffff;
      border: 1px solid #e4e7ed;
      border-radius: 6px;
      .stat-card {
        padding: 26px 12px;
        text-align: center;
        .stat-title {
          margin-bottom: 14px;
          font-size: 14px;
          color: #606266;
        }
        .stat-value {
          font-size: 22px;
          font-weight: 600;
          color: #303133;
        }
      }
      .walletImg {
        width: 211px;
        height: 211px;
      }
    }
  }
}
</style>
