<template>
  <div class="leftPage">
    <div class="topPage">
      <Title title="项目公告" />

      <div class="content">
        <div class="content_item" v-for="item in news" :key="item.id">
          <div class="round">
            <div class="sub_round"></div>
          </div>
          <div class="ellipsis">{{ item.title }}</div>
        </div>
      </div>
    </div>
    <div class="endPage">
      <Title title="人员情况" />

      <div class="map">
        <img src="@/assets/projectLarge/map.svg" alt="">
        <!-- <div ref="mapChartRef"></div> -->
      </div>

      <div class="attendance_tag">
        <div class="tag_item" v-for="(item, index) in tagList" :key="index">
          <img src="@/assets/projectLarge/people.svg" alt="">
          <div class="tag_title">{{ item.title }}</div>
          <div class="tag_info">
            {{ item.number }}
            <span style="font-size: 14px;">{{ index === 2 ? '%' : '人' }}</span>
          </div>
        </div>
      </div>

      <div class="attendance_list">
        <div class="attendance_item subfont">
          <div class="attendance_item_title"></div>
          <div class="attendance_item_title">在岗人数</div>
          <div class="attendance_item_title">出勤率</div>
          <div class="attendance_item_title">出勤时间</div>
        </div>
        <div v-for="item in list" :key="item.title" class="attendance_item">
          <div class="attendance_item_title">{{ item.title }}</div>
          <div class="attendance_item_number">{{ item.number }} <span class="subfont">人/{{ item.number }}</span></div>
          <div class="attendance_item_rate">{{ item.attendanceRate }} %</div>
          <div class="attendance_item_date subfont">{{ item.date }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue"
import Title from './title.vue'
import { getScreenNews } from '@/api/projectScreen';
import { mapOption } from './optionList'
import * as echarts from 'echarts';

const props = defineProps({
  projectId: {
    type: String,
    default: ''
  }
})

let mapChart = null
const mapChartRef = ref<HTMLDivElement | null>(null);
const news = ref([])
const list = ref([
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
  { title: '智慧系统运维', number: 30, attendanceRate: 100, date: '2025-08-05 08:10' },
])
const tagList = ref([
  { title: '出勤人数', number: 259 },
  { title: '在岗人数', number: 100 },
  { title: '出勤率', number: 100 },
])

/**
 * 初始化地图
 */
const initMapChart = () => {
  if (!mapChartRef.value) {
    return;
  }
  mapChart = echarts.init(mapChartRef.value);
  mapChart.setOption(mapOption);
}

onMounted(() => {
  // nextTick(() => {
  //   initMapChart();
  // });
  getScreenNews(props.projectId).then(res => {
    const { data, code } = res
    if (code === 200) {
      news.value = data
    }
  })
})

onUnmounted(() => {
  // if (mapChart) {
  //   mapChart.dispose();
  //   mapChart = null;
  // }
});

</script>

<style scoped lang="scss">
.leftPage {
  display: flex;
  flex-direction: column;
  width: 25vw;
  height: 100%;

  .topPage,
  .endPage {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 15px 0;
    border: 1px solid rgba(29, 214, 255, 0.1);
    box-sizing: border-box;
  }

  .endPage {
    flex: 1;
    margin-top: 23px;
  }
}

.content {
  max-height: 100px;
  margin: 0 15px;
  padding: 0 10px;
  margin-top: 15px;
  box-sizing: border-box;
  overflow-y: auto;

  &::-webkit-scrollbar-track {
    background: rgba(204, 204, 204, 0.1);
    border-radius: 10px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(29, 214, 255, 0.78);
    border-radius: 10px;
  }

  .content_item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    // position: relative;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 400;
    color: rgba(230, 247, 255, 1);

    .ellipsis {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.5;
    }

    &:last-child {
      margin-bottom: 0;
    }

    .round {
      display: grid;
      place-items: center;
      margin-top: 3px;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: rgba(29, 214, 255, 0.3);

      .sub_round {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: #1DD6FF;
      }
    }
  }
}

.map {
  margin-top: 15px;
}

.attendance_tag {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 30px;
  margin-top: 15px;

  .tag_item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    border: 1px dashed rgba(29, 214, 255, 0.3);
    padding: 10px 25px;

    .tag_info {
      font-size: 20px;
      font-weight: 700;
      color: rgba(230, 247, 255, 1);
      text-shadow: 0px 1.24px 6.21px rgba(0, 190, 247, 1);
    }

    .tag_title {
      font-size: 14px;
      font-weight: 400;
      color: rgba(230, 247, 255, 1);
    }
  }
}

.attendance_list {
  padding: 0px 30px;
  font-size: 14px;

  .attendance_item {
    display: grid;
    grid-template-columns: 3fr 2fr 2fr 3fr;
    margin-top: 20px;
  }
}

.subfont {
  color: rgba(138, 149, 165, 1);
}
</style>
