<template>
  <Calendar @changeTime="changeTime" />
  <Projects />
</template>

<script setup>
import { useStore } from 'vuex';
import dayjs from 'dayjs';
import { getProjects } from 'apis';
import Calendar from './Calendar.vue';
import Projects from './Projects.vue';

const store = useStore();

// 获取项目列表
const getProjectsList = async (startTime, endTime) => {
  const params = { param: { startTime, endTime } };

  try {
    const res = await getProjects(params);

    if (res.err) {
      console.error('err: ', res.err);
    } else {
      res.data.forEach(item => {
        item.show = false;
      });
      store.commit('projects/setProjects', res.data);
    }
  } catch (error) {
    console.log(error);
  }
};

getProjectsList(dayjs().startOf('day').format('x'), dayjs().endOf('day').format('x'));

function changeTime(data) {
  getProjectsList(data.startTime, data.endTime);
}
</script>

<script>
export default { name: 'LeftIndex' };
</script>
