<template>
  <card title="项目公告">
    <template #header-aside><nuxt-link to="/about/news?type=75">查看更多+</nuxt-link></template>
    <div class="future">
      <div class="future-left">即将开始的<br />课程日期</div>
      <div class="future-right">
        <div class="future-item" v-for="(item, index) in futureList" :key="index">
          <div class="future-item__title">{{ item.title }}</div>
          <div class="future-item__date">{{ formatDate(item.created_time) }}</div>
        </div>
      </div>
    </div>
    <div class="list">
      <nuxt-link :to="`/about/news/${item.id}?type=75`" v-for="(item, index) in list" :key="index">
        <div class="list-item">
          <div class="list-item__date">
            <p class="t1">{{ formatMD(item.created_time) }}</p>
            <p class="t2">{{ formatYY(item.created_time) }}</p>
          </div>
          <div class="list-item__title">{{ item.title }}</div>
        </div>
      </nuxt-link>
    </div>
  </card>
</template>

<script>
import Card from '@/components/Card'
export default {
  components: { Card },
  data() {
    return {
      futureList: [
        { title: 'KELLEY商学院金融硕士（MSF）开学典礼', created_time: '2020-03-23 14:41:08' },
        { title: '酒店管理HMBA报名截止日', created_time: '2020-04-10 14:41:08' }
      ],
      list: []
    }
  },
  methods: {
    // 2月14日
    formatDate(value) {
      const date = new Date(value.replace(/\-/g, '/'))
      return date.getMonth() + 1 + '月' + date.getDate() + '日'
    },
    // 2021
    formatYY(value) {
      const date = new Date(value.replace(/\-/g, '/'))
      return date.getFullYear()
    },
    // 2/14
    formatMD(value) {
      const date = new Date(value.replace(/\-/g, '/'))
      return date.getMonth() + 1 + '/' + date.getDate()
    }
  },
  async fetch() {
    const params = { page: 1, per_page: 2, type: 75, project_id: 1013 }
    this.list = await this.$axios.$get('/api/zws/v1/cms/news', { params }).then(res => res)
  }
}
</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;
}
.future-item {
  display: flex;
  align-items: center;
  padding: 0.15rem 0;
}
.future-item + .future-item {
  border-top: 1px solid #999;
}
.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>
