<template>
  <div class="group-item" @click="onClick">
    <div class="group-item-index" :class="topClass" v-if="showIndex && index < 3"></div>
    <div class="group-item-pic">
      <img :src="data.logo" v-if="data.logo" />
    </div>
    <div class="group-item-main">
      <div class="group-item-title line-clamp">{{ data.org_name }}</div>
      <div class="group-item-content">{{ data.act_num }}活动 · {{ data.num }}成员 · {{ data.hot }}热度</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'GroupItem',
  props: {
    data: Object,
    index: Number,
    showIndex: { type: Boolean, default: false }
  },
  computed: {
    currentIndex() {
      return this.index + 1
    },
    topClass() {
      return this.currentIndex <= 3 ? `top${this.currentIndex}` : ''
    }
  },
  methods: {
    onClick() {
      this.$router.push({ name: 'groupItem', params: { id: this.data.id } })
    }
  }
}
</script>
<style lang="scss" scoped>
.group-item {
  position: relative;
  display: flex;
  margin-bottom: 15px;
}
.group-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;
  }
}
.group-item-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 10px 0;
}
.group-item-title {
  font-size: 15px;
  color: #1b1b1b;
  line-height: 1;
}
.group-item-content {
  font-size: 12px;
  color: #a0a0a0;
  line-height: 1;
}
.group-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;
}
</style>
