<template>
  <div class="group-item" @click="onClick">
    <div class="group-item-index" :class="topClass" v-if="showIndex">
      <template v-if="!topClass">
        {{ currentIndex }}
      </template>
    </div>
    <div class="group-item-pic" v-if="data.logo">
      <img :src="data.logo" />
    </div>
    <div class="group-item-main">
      <div class="group-item-title line-clamp">{{ data.org_name }}</div>
      <div class="group-item-content">
        <p class="group-item-content__num">
          <template v-if="data.num">{{ data.num }}人</template>
        </p>
        <p class="group-item-content__city">{{ data.org_city }}</p>
        <p class="group-item-content__hot">{{ data.hot }}</p>
      </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 {
  display: flex;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #f5f5f5;
}
.group-item-pic {
  width: 120px;
  height: 62px;
  margin-right: 10px;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
}
.group-item-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.group-item-title {
  font-size: 14px;
  color: #222;
}
.group-item-content {
  display: flex;
  color: #999;
}
.group-item-content__num {
  flex: 1;
}
.group-item-content__city {
  margin: 0 10px;
  max-width: 70px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.group-item-content__hot {
  background: url('~@/assets/img/icon_hot.png') no-repeat left center;
  background-size: 8px auto;
  padding-left: 10px;
}
.group-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>
