<script setup>
import { ref } from 'vue';
import moment from 'moment';

import { roadshowInterence } from "@/api/api.js";
import calendar from "@/components/calendar.vue";

// 活动列表
const eventList=ref([])

const calendarRef=ref(null)

// 获取会议列表
const getEventList=async()=>{
  //当前的起始日期
  const { currentStart,currentEnd } = calendarRef.value.calendarApi.view;

  const { formateDate } = calendarRef.value;

  // 获取本周日程
  const { Data,Ret } = await roadshowInterence.meetCalendarDetail({
    StartDate: formateDate(currentStart),
    EndDate: formateDate(new Date(currentEnd.getTime()- 24*60*60*1000)),
  });

  if(Ret !== 200) return

  //按开始时间重新排序
  Data.Group ? Data.Group.forEach(item => {
    item.CalendarList = item.CalendarList.sort((a,b) => moment(`${a.StartDate} ${a.StartTime}`).valueOf() -  moment(`${b.StartDate} ${b.StartTime}`).valueOf())
  }) : []

  eventList.value =  Data.Group?Data.Group.map((item, index) => {
    return { ...item, id: index };
  }):[];
}

</script>

<template>
  <div class="researcher-calendar">
    <el-card class="researcher-calendar-context">
      <!-- 日程组件 -->
      <calendar
        ref="calendarRef"
        :eventList="eventList"
        @weekChange="getEventList"
        fromCode="meet"
      >
      </calendar>
    </el-card>
  </div>
</template>

<style>
</style>