<template>
  <div class="message-item" :class="classes" @click="onClick">
    <div class="message-item-pic" :class="`message-item-pic-${type}`"></div>
    <div class="message-item-content">
      <div class="message-item-content-hd">
        <div class="message-item-content__title">{{ data.title }}</div>
        <div class="message-item-content__time">{{ data.created_time }}</div>
      </div>
      <div class="message-item-content-bd" v-html="data.contents"></div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'MessageItem',
  props: { type: String, data: Object },
  computed: {
    isRead() {
      return this.data.status === '1'
    },
    classes() {
      return {
        'un-read': !this.isRead
      }
    }
  },
  methods: {
    onClick() {
      this.$router.push({ name: 'messageItem', params: { id: this.data.id } })
    }
  }
}
</script>

<style lang="scss" scoped>
.message-item {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #f1f1f1;
}
.message-item-pic {
  width: 40px;
  height: 40px;
  background-size: contain;
}
.message-item-pic-1 {
  background-image: url('~@/assets/img/message_group_icon.png');
}
.message-item-pic-2 {
  background-image: url('~@/assets/img/message_activity_icon.png');
}
.message-item-pic-3 {
  background-image: url('~@/assets/img/message_settings_icon.png');
}
.message-item-content {
  flex: 1;
  margin-left: 10px;
}
.message-item-content-hd {
  display: flex;
  justify-content: space-between;
}
.message-item-content__title {
  font-size: 14px;
  color: #222;
  flex: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.message-item-content__time {
  font-size: 14px;
  color: #999;
}
.message-item-content-bd {
  margin-top: 8px;
  font-size: 14px;
  color: #999;
}
.un-read .message-item-content__title {
  font-weight: bold;
}
</style>
