<!--
 * @Author: chris
 * @Date: 2025-09-15 09:51:59
 * @LastEditors: chris
 * @LastEditTime: 2026-01-19 16:43:21
-->
<script setup>
import { getOrchardInfo } from '@/api/orchard'
import { getWarningList } from '@/api/pest/warning'
import BasicInfo from './components/basicInfo.vue'
import Monitor from './components/monitor.vue'
import Title from './components/title.vue'
import Warning from './components/warning.vue'

definePage({
  style: {
    navigationBarTitleText: '主页',
  },
})

const loading = ref(false)
const orchardInfo = ref(null)
const orchardId = '105'
const warningList = ref([])

getBaseInfo()
getWarningListData()

// 获取果园基本信息
function getBaseInfo() {
  loading.value = true
  return getOrchardInfo(orchardId).then((res) => {
    orchardInfo.value = res.data
  }).finally(() => {
    loading.value = false
  })
}

// 获取虫情预警列表
function getWarningListData() {
  return getWarningList({
    deptId: orchardInfo.value?.deptId,
    pageNum: 1,
    pageSize: 5,
  }).then((res) => {
    warningList.value = res.data
  })
}

// 处理更多预警点击事件
function handleMoreWarning() {
  uni.navigateTo({
    url: '/pages-sub/warning/warning',
    // url: '/pages/auth/auth',
  })
}
</script>

<template>
  <view class="home-page">
    <!-- 页面标题 -->
    <view class="home-title">
      <view class="title-container">
        <text class="title-text">荔枝园监控系统</text>
        <view class="title-accent" />
      </view>
    </view>
    <!-- 首页内容区域 -->
    <view v-if="!loading" class="home-content">
      <!-- 基本信息区域 -->
      <Title title="基本信息" />
      <basic-info />
      <!-- 监控模块区域 -->
      <Title title="实时监控" />
      <monitor />
      <!-- 虫情预警模块 -->
      <Title title="预警信息">
        <wd-button size="small" type="text" @tap="handleMoreWarning">
          <text class="more-btn-text">查看更多</text>
        </wd-button>
      </Title>
      <Warning />
    </view>
    <wd-loading v-else />
  </view>
</template>

<style lang="scss" scoped>
@import './variables.scss';

// 基础样式
.home-page {
  min-height: 100%;
  background-color: $bg-color;
}

// 标题样式
.home-title {
  background: linear-gradient(135deg, $primary-color, $primary-color-dark);
  padding: 22px 0;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 4px 20px rgba($primary-color, 0.35),
    $glow-effect;

  // 添加科技感网格背景
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
      linear-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: -1px -1px;
    z-index: 1;
  }

  // 发光圆点装饰
  &::after {
    content: '';
    position: absolute;
    top: 20%;
    right: 10%;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    filter: blur(20px);
    z-index: 0;
    animation: glowPulse 4s infinite alternate;
  }

  .title-container {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .title-text {
    font-size: 28px;
    font-weight: 600;
    color: $card-bg;
    text-align: center;
    letter-spacing: 0.8px;
    position: relative;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    // 添加科技感下划线效果
    &::after {
      content: '';
      position: absolute;
      bottom: -8px;
      left: 50%;
      transform: translateX(-50%);
      width: 60%;
      height: 2px;
      background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
    }
  }

  .title-accent {
    width: 50px;
    height: 3px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 3px;
    opacity: 0.9;
    backdrop-filter: blur(2px);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  }
}

// 发光脉冲动画
@keyframes glowPulse {
  0% {
    opacity: 0.6;
    transform: scale(1);
  }
  100% {
    opacity: 0.9;
    transform: scale(1.1);
  }
}

// 内容区域
.home-content {
  padding-top: 15px;
  padding-bottom: 15px;
}

.section-title {
  margin-left: 15px;
  font-size: 18px;
  font-weight: 600;
  color: $text-primary;
  display: block;
  padding-left: 15px;
  margin-bottom: 16px;
  position: relative;
  // 添加科技感标题装饰
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 16px;
    background: linear-gradient(180deg, $primary-color, $primary-color-dark);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba($primary-color, 0.3);
  }
}

.more-btn-text {
  color: $-color-theme;
}
</style>
