<template>
  <view class="content">
    <u-sticky offsetTop="0rpx" customNavHeight="0rpx">
      <div class="header-title-sticky">
        <text class="title-text">健康总览</text>
      </div>
    </u-sticky>
    <div class="app-container">
    <div class="header-con" ref="searchHeightRef">
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #4facfe 0%, #2196f3 100%);">
          <uni-icons type="person-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">成员总数</div>
          <div class="num">{{ personCount }}<span>人</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #667eea 0%, #5b6cdb 100%);">
          <uni-icons type="compose" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">档案数量</div>
          <div class="num">{{ healthRecordCount }}<span>份</span></div>
        </div>
      </div>
    </div>
    
    <div class="header-con"  ref="searchHeightRef">
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #f59a23 0%, #f57c00 100%);">
          <uni-icons type="calendar-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">活动次数</div>
          <div class="num">{{ activityCount }}<span>次</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #fa709a 0%, #ec407a 100%);">
          <uni-icons type="wallet" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">活动费用</div>
          <div class="num">{{ activityCost }}<span>元</span></div>
        </div>
      </div>
    </div>
    <div class="header-con"  ref="searchHeightRef">
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #43e97b 0%, #2d8f3c 100%);">
          <uni-icons type="home-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">就医医院</div>
          <div class="num">{{ hospitalCount }}<span>个</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #667eea 0%, #5b6cdb 100%);">
          <uni-icons type="person" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">就诊大夫</div>
          <div class="num">{{ doctorTotalCount }}<span>个</span></div>
        </div>
      </div>
    </div>
<div class="header-con"  ref="searchHeightRef">
  <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #f57c00 0%, #e65100 100%);">
          <uni-icons type="list" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">就医次数</div>
          <div class="num">{{ doctorCount }}<span>次</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #e64545 0%, #d32f2f 100%);">
          <uni-icons type="wallet-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">就医费用</div>
          <div class="num">{{ doctorCost }}<span>元</span></div>
        </div>
      </div>
</div>

<div class="header-con"  ref="searchHeightRef">
  <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #5b6cdb 0%, #4527a0 100%);">
          <uni-icons type="calendar" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">用药天数</div>
          <div class="num">{{ marDayCount }}<span>天</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #fa709a 0%, #ec407a 100%);">
          <uni-icons type="gear-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">用药次数</div>
          <div class="num">{{ marCount }}<span>次</span></div>
        </div>
      </div>
</div>

<div class="header-con"  ref="searchHeightRef">
  <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #4facfe 0%, #2196f3 100%);">
          <uni-icons type="medal" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">用药种类</div>
          <div class="num">{{ medicalTypeCount }}<span>种</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #f57c00 0%, #e65100 100%);">
          <uni-icons type="flag" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">测量体温次数</div>
          <div class="num">{{ temperatureTotalCount }}<span>次</span></div>
        </div>
      </div>
</div>

<div class="header-con"  ref="searchHeightRef">
  <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #e64545 0%, #d32f2f 100%);">
          <uni-icons type="fire" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">发烧天数（>=37℃）</div>
          <div class="num">{{ feverDayCount }}<span>天</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #f59a23 0%, #f57c00 100%);">
          <uni-icons type="notification" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">低烧（36.9~37.5℃）</div>
          <div class="num">{{ lowerTempCount }}<span>次</span></div>
        </div>
      </div>
</div>

<div class="header-con"  ref="searchHeightRef">
  <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #fa709a 0%, #ec407a 100%);">
          <uni-icons type="eye" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">中烧（37.5~38.5℃）</div>
          <div class="num">{{ middleTempCount }}<span>次</span></div>
        </div>
      </div>
      <div class="item">
        <view class="item-icon" style="background: linear-gradient(135deg, #e64545 0%, #d32f2f 100%);">
          <uni-icons type="fire-filled" size="20" color="#ffffff"></uni-icons>
        </view>
        <div class="info-sum">
          <div class="title">高烧（>=38.5℃）</div>
          <div class="num">{{ higherTempCount }}<span>次</span></div>
        </div>
      </div>
</div>
<div v-for="(item, index) in personList" :key="index">
      <div class="header-title" ref="searchHeightRef">
        <view class="title-line"></view>
        <text class="title-text">{{ item.personName + '-健康档案概览' }}</text>
      </div>
      <div class="header-con" ref="searchHeightRef">
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #667eea 0%, #5b6cdb 100%);">
            <uni-icons type="compose" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">档案数量</div>
            <div class="num">{{ item.healthRecordCount }}<span>份</span></div>
          </div>
        </div>
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #43e97b 0%, #2d8f3c 100%);">
            <uni-icons type="home-filled" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">就医医院</div>
            <div class="num">{{ item.hospitalCount }}<span>个</span></div>
          </div>
        </div>
      </div>
      <div class="header-con" ref="searchHeightRef">
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #667eea 0%, #5b6cdb 100%);">
            <uni-icons type="person" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">就诊大夫</div>
            <div class="num">{{ item.doctorTotalCount }}<span>个</span></div>
          </div>
        </div>
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #f57c00 0%, #e65100 100%);">
            <uni-icons type="list" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">就医次数</div>
            <div class="num">{{ item.doctorCount }}<span>次</span></div>
          </div>
        </div>
      </div>
      <div class="header-con" ref="searchHeightRef">
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #e64545 0%, #d32f2f 100%);">
            <uni-icons type="wallet-filled" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">就医费用</div>
            <div class="num">{{ item.doctorCost }}<span>元</span></div>
          </div>
        </div>
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #5b6cdb 0%, #4527a0 100%);">
            <uni-icons type="calendar" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">用药天数</div>
            <div class="num">{{ item.marDayCount }}<span>天</span></div>
          </div>
        </div>
      </div>
      <div class="header-con" ref="searchHeightRef">
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #fa709a 0%, #ec407a 100%);">
            <uni-icons type="gear-filled" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">用药次数</div>
            <div class="num">{{ item.marCount }}<span>次</span></div>
          </div>
        </div>
        <div class="item">
          <view class="item-icon" style="background: linear-gradient(135deg, #e64545 0%, #d32f2f 100%);">
            <uni-icons type="fire" size="20" color="#ffffff"></uni-icons>
          </view>
          <div class="info-sum">
            <div class="title">发烧天数（>=37℃）</div>
            <div class="num">{{ item.feverDayCount }}<span>天</span></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</view>
  <!-- 悬停按钮返回工作台-->
  <refresh></refresh>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { getHealthAnalysis } from '@/api/health/statisticAnalysis.js'
import auth from "@/plugins/auth"; // 建议使用auth进行鉴权操作

//信息
const personCount = ref(0) //成员总数
const healthRecordCount = ref(0) //健康档案总数
const activityCount = ref(0) //活动总数
const activityCost = ref(0) //活动费用
const doctorCount = ref(0) //就医总数
const doctorCost = ref(0) //就医费用
const hospitalCount = ref(0) //医院总数
const doctorTotalCount = ref(0) //医生总数
const marDayCount = ref(0) //用药天数
const marCount = ref(0) //用药次数
const medicalTypeCount = ref(0) //用药类别
const feverDayCount = ref(0) //发烧天数
const temperatureTotalCount = ref(0) //体温测量次数
const lowerTempCount = ref(0) //低烧次数
const middleTempCount = ref(0) //中烧次数
const higherTempCount = ref(0) //高烧次数
const personList = ref([]) //人员记录

const getHealthAnalysisData = () => {
  getHealthAnalysis().then((res) => {
    personCount.value = res.data.personCount
    healthRecordCount.value = res.data.healthRecordCount
    activityCount.value = res.data.activityCount
    activityCost.value = res.data.activityCost
    doctorCount.value = res.data.doctorCount
    doctorCost.value = res.data.doctorCost
    hospitalCount.value = res.data.hospitalCount
    doctorTotalCount.value = res.data.doctorTotalCount
    marCount.value = res.data.marCount
    feverDayCount.value = res.data.feverDayCount
    marDayCount.value = res.data.marDayCount
    medicalTypeCount.value = res.data.medicalTypeCount
    temperatureTotalCount.value = res.data.temperatureTotalCount
    lowerTempCount.value = res.data.lowerTempCount
    middleTempCount.value = res.data.middleTempCount
    higherTempCount.value = res.data.higherTempCount
    personList.value = res.data.personList
  })
}

onMounted(() => {
  getHealthAnalysisData()
})
</script>

<style lang="scss" scoped>
page {
  height: 100%;
  overflow: auto;
  padding: 0;
  margin: 0;
}

.content {
  background-color: #f5f7fa;
  min-height: 100%;
  padding: 0;
  margin: 0;
}

.header-title-sticky {
  display: flex;
  align-items: center;
  padding: 120rpx 24rpx 16rpx 24rpx;
  margin: 0;
  background-color: #ffffff;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  position: relative;
  z-index: 999;
  
  .title-text {
    font-size: 32rpx;
    font-weight: 600;
    color: #2c3e50;
  }
}

.app-container {
  background-color: #f5f7fa;
  padding: 0;
  padding-top: 0;
  margin-top: 0;
  overflow: visible;
  
  .header-title {
    display: flex;
    align-items: center;
    padding: 16rpx 24rpx;
    margin-bottom: 8rpx;
    background-color: #ffffff;
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 100;
    
    .title-line {
      width: 6rpx;
      height: 32rpx;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 3rpx;
      margin-right: 12rpx;
      flex-shrink: 0;
    }
    
    .title-text {
      font-size: 32rpx;
      font-weight: 600;
      color: #2c3e50;
    }
  }
  
  .header-con {
    width: calc(100% - 32rpx);
    margin: 0 16rpx 8rpx 16rpx;
    background-color: transparent;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    padding: 0;
    gap: 12rpx;
    
    .item {
      flex: 1;
      display: flex;
      align-items: center;
      padding: 20rpx 16rpx;
      transition: all 0.3s ease;
      border: 2rpx solid #e8edf3;
      border-radius: 16rpx;
      background: linear-gradient(135deg, #ffffff 0%, #f8f9fb 100%);
      box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
      
      &:hover {
        border-color: #d0d7de;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
      }
      
      &:active {
        transform: scale(0.98);
        opacity: 0.9;
      }
      
      .item-icon {
        width: 72rpx;
        height: 72rpx;
        border-radius: 16rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 16rpx;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
        flex-shrink: 0;
      }
      
      .info-sum {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        
        .title {
          color: #7f8c8d;
          margin-bottom: 8rpx;
          font-size: 24rpx;
        }
        
        .num {
          color: #2c3e50;
          font-size: 32rpx;
          font-weight: 600;
          
          span, .unit {
            font-size: 20rpx;
            color: #95a5a6;
            margin-left: 4rpx;
          }
        }
      }
    }
  }
}
</style>