<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>

<script>
import { roadshowInterence } from "@/api/api.js";
import calendar from "@/components/calendar.vue";
import { researcherCalendarConfig } from "./roleConfig";
export default {
  components: {
    calendar
  },
  data() {
    return {
      // 活动列表
      eventList: [],
      // 点击单元格对应日期时间
      cellDate: null,
      
    };
  },
  methods: {
    // 获取会议列表
    async getEventList() {

      //当前的起始日期
      const { currentStart,currentEnd } = this.$refs.calendarRef.calendarApi.view;

      const { formateDate } = this.$refs.calendarRef;

      // 获取本周日程
      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) => this.$moment(`${a.StartDate} ${a.StartTime}`).valueOf() -  this.$moment(`${b.StartDate} ${b.StartTime}`).valueOf())
      }) : []

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

  },
  mounted() {
  },
};
</script>

<style>
</style>