<template>
  <div class="activity-item" @click="onClick">
    <div class="activity-item-index" :class="topClass" v-if="showIndex">
      <template v-if="!topClass">
        {{ currentIndex }}
      </template>
    </div>
    <div class="activity-item-pic" v-if="data.activity_image">
      <img :src="data.activity_image" />
    </div>
    <div class="activity-item-main">
      <div class="activity-item-title">{{ data.activity_name }}</div>
      <div class="activity-item-content">
        <p class="activity-item-content__city">{{ data.activity_city }}</p>
        <p class="activity-item-content__ft">
          <span>{{ data.activity_time | dateFormat }}</span>
          <span>{{ data.stu_nums }}人报名</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'

export default {
  name: 'ActivityItem',
  props: {
    data: Object,
    index: Number,
    showIndex: { type: Boolean, default: false }
  },
  computed: {
    currentIndex() {
      return this.index + 1
    },
    topClass() {
      return this.currentIndex <= 3 ? `top${this.currentIndex}` : ''
    }
  },
  filters: {
    dateFormat(value) {
      return dayjs(value).format('YYYY-MM-DD')
    }
  },
  methods: {
    onClick() {
      this.$router.push({ name: 'activityItem', params: { id: this.data.id } })
    }
  }
}
</script>
<style lang="scss" scoped>
.activity-item {
  display: flex;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #f5f5f5;
}
.activity-item-pic {
  width: 120px;
  height: 62px;
  margin-right: 10px;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.activity-item-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.activity-item-title {
  font-size: 14px;
  color: #222;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.activity-item-content {
  p {
    color: #999;
  }
}
.activity-item-content__ft {
  display: flex;
  justify-content: space-between;
}
.activity-item-index {
  width: 25px;
  margin-right: 10px;
  font-size: 14px;
  color: #999;
  line-height: 62px;
  text-align: center;
}
.top1 {
  background: url('~@/assets/img/top_01.png') no-repeat center;
  background-size: contain;
}
.top2 {
  background: url('~@/assets/img/top_02.png') no-repeat center;
  background-size: contain;
}
.top3 {
  background: url('~@/assets/img/top_03.png') no-repeat center;
  background-size: contain;
}
</style>
