<template>
  <card title="项目公告">
    <template #header-aside><nuxt-link to="/about/news?type=article_news">查看更多+</nuxt-link></template>
    <div class="future">
      <!-- <div class="future-left">即将开始的<br />课程日期</div> -->
      <div class="future-right">
        <swiper ref="mySwiper" :options="swiperOptions" class="my-swiper">
          <template v-for="(item, index) in futureList">
            <swiper-slide :key="index">
              <div class="future-item">
                <div class="future-item__title">{{ item.title }}</div>
                <div class="future-item__date">{{ item.created_time }}</div>
              </div>
            </swiper-slide>
          </template>
        </swiper>
      </div>
    </div>
    <div class="list">
      <template v-for="(item, index) in list">
        <new-link :item="{ news: { data: item, path: '/about/news' } }" :key="index">
          <div class="list-item">
            <div class="list-item__date">
              <p class="t1">{{ formatMD(item.start_time) }}</p>
              <p class="t2">{{ formatYY(item.start_time) }}</p>
            </div>
            <div class="list-item__title">{{ item.title }}</div>
          </div>
        </new-link>
      </template>
    </div>
  </card>
</template>

<script>
import Card from '@/components/Card'
import NewLink from '@/components/NewLink'

export default {
  components: { Card, NewLink },
  data() {
    return {
      swiperOptions: {
        autoplay: true,
        delay: 5000,
        loop: true,
        direction: 'vertical',
        slidesPerView: 2
      },
      futureList: [
        { title: '后疫情时代的数字化转型与线上营销', created_time: '06月17日' },
        { title: '中国PRP二期班核心课程', created_time: '07月17日' }
      ],
      list: []
    }
  },
  methods: {
    // 2月14日
    formatDate(value) {
      const date = new Date(value * 1000)
      return date.getMonth() + 1 + '月' + date.getDate() + '日'
    },
    // 2021
    formatYY(value) {
      const date = new Date(value * 1000)
      return date.getFullYear()
    },
    // 2/14
    formatMD(value) {
      const date = new Date(value * 1000)
      return date.getMonth() + 1 + '/' + date.getDate()
    }
  },
  async fetch() {
    const params = { project_id: process.env.projectId, type_tag: 'article_news', page: 1, limit: 3 }
    this.list = await this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => res.data.data)
  }
}
</script>

<style lang="scss" scoped>
.future {
  display: flex;
  align-items: center;
  background-color: #fff;
  padding: 0.15rem 0.22rem;
}
.future-left {
  width: 0.75rem;
  font-size: 0.15rem;
  text-align: center;
}
.future-right {
  flex: 1;
  // padding-left: 0.28rem;
}
.my-swiper {
  height: 1rem;
}
.future-item {
  display: flex;
  align-items: center;
  padding: 0.15rem 0;
}
.future-item + .future-item {
  border-top: 1px solid #999;
}

::v-deep {
  .swiper-slide-active {
    .future-item {
      border-bottom: 1px solid #999999;
    }
  }
}
.future-item__title {
  flex: 1;
  font-size: 0.1rem;
  text-align: center;
}
.future-item__date {
  width: 0.8rem;
  font-size: 0.15rem;
  color: #aa1941;
  text-align: center;
}

.list-item {
  display: flex;
  align-items: center;
  padding: 0.13rem 0;
  border-bottom: 1px solid #e3e3e3;
  &:hover {
    color: #aa1941;
  }
}
.list-item__date {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  flex: 0 0 0.7rem;
  height: 0.54rem;
  color: #fff;
  background-color: #aa1941;
  border-radius: 0.04rem;
  .t1 {
    font-size: 0.16rem;
    opacity: 0.8;
  }
  .t2 {
    font-size: 0.13rem;
    opacity: 0.8;
  }
}
.list-item__title {
  margin-left: 0.13rem;
  font-size: 0.13rem;
  line-height: 0.26rem;
}
</style>
