<template>
  <div class="chat-text">
    <div class="user-head">
      <img :src="userHead" alt="" />
    </div>
    <div class="right">
      <div class="name">
        {{ info.userNick }}
        <div class="isTop" v-if="isTop">置顶</div>
      </div>
      <div class="content" @click="_reply(info.id, info.userNick)">
        <div class="text">
          <template v-if="info.replyContent">
            <div class="quote">
              「 {{ info.replyNick }}：
              <span v-html="$options.filters.emojiParse(info.replyContent)"></span>
              」
            </div>
            <div class="reply">
              回复：
              <span
                :style="{ color: info.contentColor }"
                v-html="$options.filters.emojiParse(info.filterContent)"
              ></span>
            </div>
          </template>
          <div
            v-else
            :style="{ color: info.contentColor }"
            v-html="$options.filters.emojiParse(info.filterContent)"
          ></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
  name: 'chat-text',
  props: {
    info: {},
    isTop: {}
  },
  computed: {
    ...mapGetters({
      channelInfo: 'channelInfo'
    }),
    userHead() {
      const userHeadImg = this.info.userHeadImg;
      if (userHeadImg === 'phoneHead') {
        return this.channelInfo.defaultPhoneHeadAva;
      } else if (userHeadImg === 'default') {
        return this.channelInfo.defaultUserAva;
      } else if (!userHeadImg) {
        return this.channelInfo.defaultUserAva;
      } else {
        return userHeadImg;
      }
    }
  },
  methods: {
    _reply(id, name) {
      const obj = {
        id: id,
        name: name
      };
      this.$Bus.$emit('bus-setReply', obj);
    }
  }
};
</script>
<style lang="less" scoped>
.chat-text {
  display: flex;
  .user-head {
    flex: 0 0 auto;
    width: 0.36rem;
    height: 0.36rem;
    border-radius: 0.04rem;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .right {
    flex: 1;
    padding: 0 0.1rem;
    .name {
      line-height: 0.2rem;
      color: #9b9b9b;
      font-size: 0.12rem;
      .isTop {
        display: inline-block;
        padding: 0 0.06rem;
        height: 0.2rem;
        line-height: 0.2rem;
        border-radius: 0.04rem;
        background: var(--main-color);
        color: #fff;
        font-size: 0.12rem;
        transform: scale(0.5);
        transform-origin: 0 auto;
      }
    }
    .content {
      position: relative;
      padding: 0.05rem 0.1rem;
      display: inline-block;
      min-height: 0.2rem;
      line-height: 0.2rem;
      background: var(--chat-bg);
      border-radius: 0.05rem;
      border: 0.01rem solid var(--chat-border-color);
      font-size: 0.14rem;
      color: var(--chat-color);
      word-break: break-word;
      .text {
        position: relative;
        z-index: 2;
        ::v-deep {
          .emoji {
            display: inline-block;
            width: 0.3rem;
            height: 0.3rem;
            vertical-align: middle;
          }
        }
        .quote {
          padding: 0.05rem 0;
          border-bottom: 0.01rem solid #e0e0e0;
          color: #999;
        }
        .reply {
          padding: 0.05rem 0;
        }
      }
      &::after {
        content: '';
        position: absolute;
        bottom: -0.04rem;
        right: -0.04rem;
        display: block;
        width: 0.2rem;
        height: 0.2rem;
        background: var(--chat-icon-br) no-repeat bottom right;
        background-size: contain;
      }
    }
  }
}
</style>
