<template>
  <card :title="$t('home.openLesson.title')">
    <template #header-aside><nuxt-link to="/about/news?type=article_publish_class">{{ $t('viewMore') }}</nuxt-link></template>
    <new-link :item="{ news: { data: list.first, path: '/about/news' } }">
      <img :src="list.first.web_img_uri" class="class-banner" />
    </new-link>
    <div class="list">
      <div class="list-item" v-for="(item, index) in list.list" :key="index">
        <new-link :item="{ news: { data: item, path: '/about/news' } }">
          <div class="list-item-hd">
            <h3 class="list-item__title">{{ item.title }}</h3>
          </div>
          <div class="list-item-bd">
            <p class="list-item__content">{{ item.abstract }}</p>
          </div>
          <div class="list-item-ft">
            <span class="list-item__date">{{ formatDate(item.start_time) }}</span>
            <span class="list-item__view">{{ item.remarks || 36023 }}</span>
            <span class="list-item__btn">{{ $t('home.openLesson.btn') }}</span>
          </div>
        </new-link>
      </div>
    </div>
  </card>
</template>

<script>
import NewLink from '@/components/NewLink'
import Card from '@/components/Card'
export default {
  components: { Card, NewLink },
  data() {
    return {
      data: []
    }
  },
  async fetch() {
    const params = {
      project_id: process.env.projectId,
      type_tag: 'article_publish_class',
      page: 1,
      limit: 2
    }
    await this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => {
      this.data = res.data.data || []
    })
  },
  computed: {
    list() {
      const [first = {}, ...list] = this.data
      return { first, list: list || [] }
    }
  },
  methods: {
    // 2020-01-22
    formatDate(value) {
      const date = new Date(value * 1000)
      return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
    }
  }
}
</script>

<style lang="scss" scoped>
.class-banner {
  display: block;
  width: 100%;
  height: 1.17rem;
  margin-bottom: 0.09rem;
  object-fit: cover;
}

.list-item {
  padding: 0.14rem 0.1rem;
  margin-bottom: 0.09rem;
  background-color: #fff;
}
.list-item-hd {
}
.list-item__title {
  font-size: 0.14rem;
  color: #333;
}
.list-item-bd {
  padding: 0.1rem 0;
}
.list-item__content {
  font-size: 0.11rem;
  color: #666;
  line-height: 0.2rem;
}
.list-item-ft {
  display: flex;
  align-items: center;
  color: #a8a8a8;
}
.list-item__date {
  font-size: 0.1rem;
}
.list-item__view {
  flex: 1;
  font-size: 0.1rem;
  margin-left: 0.14rem;
  padding-left: 0.14rem;
  background: url('https://zws-imgs-pub.ezijing.com/static/public/948410ca5d8663ef4e80d4913df8a9b4.png') no-repeat left
    center;
  background-size: 0.11rem 0.07rem;
}
.list-item__btn {
  min-width: 0.56rem;
  height: 0.16rem;
  padding: 0 0.08rem;
  font-size: 0.1rem;
  line-height: 0.16rem;
  color: #fff;
  background-color: #aa1941;
  text-align: center;
  border-radius: 0.03rem;
  cursor: pointer;
}
</style>
