<template>
  <div class="activity-item" @click="onClick">
    <div class="activity-item-index" :class="topClass" v-if="showIndex && index < 3"></div>
    <div class="activity-item-pic">
      <img :src="data.activity_image" v-if="data.activity_image" />
    </div>
    <div class="activity-item-main">
      <div class="activity-item-title">{{ data.activity_name }}</div>
      <div class="activity-item-content">
        <p>{{ data.activity_city }} · {{ data.org_name }} · {{ data.stu_nums }}人参与</p>
        <p>{{ data.activity_time | dateFormat }}</p>
      </div>
    </div>
    <div class="activity-item-status" v-html="statusText"></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}` : ''
    },
    statusText() {
      if (this.data.approve_status === '-1') {
        return '<span class="is-processing">待审核</span>'
      }
      if (this.data.approve_status === '0') {
        return '<span class="is-finish">已结束</span>'
      }
      return dayjs().isAfter(dayjs(this.data.activity_time), 'day')
        ? '<span class="is-finish">已结束</span>'
        : '<span class="is-processing">进行中</span>'
    }
  },
  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 {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}
.activity-item-pic {
  width: 120px;
  height: 75px;
  margin-right: 15px;
  background-color: #f3f4f5;
  border-radius: 4px;
  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;
  padding: 10px 0;
}
.activity-item-title {
  font-size: 15px;
  color: #1b1b1b;
  line-height: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.activity-item-content {
  p {
    margin-top: 4px;
    font-size: 12px;
    color: #a0a0a0;
    line-height: 18px;
  }
}
.activity-item-index {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 25px;
  height: 25px;
  z-index: 2;
}
.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;
}
.activity-item-status {
  margin-left: 10px;
  ::v-deep span {
    height: 15px;
    padding: 0 4px;
    font-size: 12px;
    line-height: 15px;
    border-radius: 2px;
    display: inline-block;
  }
  ::v-deep .is-finish {
    color: #ce0022;
    background: #ffedf0;
  }
  ::v-deep .is-processing {
    color: #1f78d4;
    background: #e2f0ff;
  }
}
</style>
