<template>
  <card title="公开课">
    <template #header-aside><nuxt-link to="/about/news">查看更多+</nuxt-link></template>
    <img src="/images/home_class_banner.png" class="class-banner" />
    <div class="list">
      <div class="list-item" v-for="(item, index) in list" :key="index">
        <nuxt-link :to="`/about/news/${item.id}`">
          <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.summary }}</p>
          </div>
          <div class="list-item-ft">
            <span class="list-item__date">{{ formatDate(item.created_time) }}</span>
            <span class="list-item__view">{{ item.count || 36023 }}</span>
            <span class="list-item__btn">免费学习</span>
          </div>
        </nuxt-link>
      </div>
    </div>
  </card>
</template>

<script>
import Card from '@/components/Card'
export default {
  components: { Card },
  data() {
    return {
      list: []
    }
  },
  async fetch() {
    const params = { page: 1, per_page: 2, type: 72, project_id: 1013 }
    this.list = await this.$axios.$get('/api/zws/v1/cms/news', { params }).then(res => res)
  },
  methods: {
    // 2020-01-22
    formatDate(value) {
      const date = new Date(value.replace(/\-/g, '/'))
      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>
