<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">
        <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 class="reply-btn" @click="_reply(info.id, info.userNick, info.filterContent)">回复</div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
  name: 'pc-chat-test',
  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, userNick, filterContent) {
      const obj = {
        id: id,
        userNick: userNick,
        filterContent: filterContent
      };
      this.$Bus.$emit('bus-setReply', obj);
    }
  }
};
</script>
<style lang="less" scoped>
.chat-text {
  display: flex;
  .user-head {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .right {
    flex: 1;
    padding: 0px 10px;
    .name {
      line-height: 25px;
      color: #9b9b9b;
      font-size: 14px;
      .isTop {
        display: inline-block;
        padding: 0 6px;
        height: 20px;
        line-height: 20px;
        border-radius: 4px;
        background: var(--main-color);
        color: #fff;
        font-size: 12px;
      }
    }
    .content {
      margin-right: 10px;
      position: relative;
      padding: 6px 12px;
      display: inline-block;
      min-height: 25px;
      line-height: 25px;
      background: var(--chat-bg);
      border-radius: 4px;
      border: 1px solid var(--chat-border-color);
      font-size: 15px;
      color: var(--chat-color);
      word-break: break-word;
      .text {
        position: relative;
        z-index: 2;
        ::v-deep {
          .emoji {
            display: inline-block;
            width: 24px;
            height: 24px;
            vertical-align: middle;
          }
        }
        .quote {
          padding: 5px 0;
          border-bottom: 1px solid #e0e0e0;
          color: #999;
        }
        .reply {
          padding: 5px 0;
        }
      }
    }
    .reply-btn {
      vertical-align: top;
      margin: 5px 0;
      display: none;
      width: 52px;
      height: 32px;
      line-height: 32px;
      text-align: center;
      border-radius: 4px;
      background: #383940;
      font-size: 16px;
      color: #409eff;
      cursor: pointer;
    }
    &:hover {
      .reply-btn {
        display: inline-block;
      }
    }
  }
}
</style>
