<template>
  <div class="comm-item" @click="goDetails">
    <div class="header flex-default">
      <div class="avatar">
        <img
          :src="itemData.commentVo.headUrl"
          style="width: 100%; height: 100%; border-radius: 50%"
        />
      </div>
      <div class="name">{{ itemData.commentVo.nickName }}</div>
      <div class="time">{{ itemData.commentVo.createTime | getTime }}</div>
    </div>
    <div class="star-sku flex-default">
      <div class="star">
        <m-star
          :value="itemData.commentVo.businessEvaluate"
          :size="14"
          :readonly="true"
        />
      </div>
      <div class="sku">{{ itemData.commentVo.list | getSkuStr }}</div>
    </div>
    <div class="content-text">
      {{ itemData.commentVo.content }}
    </div>
    <div class="content-img flex-default">
      <div v-for="(data, i) in getPrivewsList" :key="i">
        <div
          class="item"
          v-if="data.type === 'img'"
          @click.stop="previewItem(i)"
        >
          <img :src="data.url" style="width: 100%; height: 100%" />
        </div>
        <div
          class="item video-con"
          v-if="data.type === 'video'"
          @click.stop="previewItem(i)"
        >
         <video :src="data.video" :poster="data.video+'?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast'"/>
          <div class="mask" />
        </div>
      </div>
    </div>
    <div class="business-comment" v-show="itemData.commentVo.replyContent">
      <div class="comment-text" :class="{ ofh: !isOpen }">
        商家回复：{{ itemData.commentVo.replyContent }}
      </div>
      <div class="comment-text none" ref="allText">
        商家回复：{{ itemData.commentVo.replyContent }}
      </div>
      <div class="more" v-if="isMore">
        <span @click.stop="isOpen = !isOpen">
          {{ isOpen ? "收起" : "展开" }}
        </span>
      </div>
    </div>
    <div
      class="append-comment-con"
      v-if="
        Object.prototype.toString.call(itemData.commentAppend).slice(8, -1) ===
        'Object'
      "
    >
      <div class="title">
        <m-icon icon="icon-3dot" :size="12" />
        购买
        {{
          itemData.commentAppend.createTime
            | timeDifference(itemData.commentVo.createTime)
        }}
        天后追评
      </div>
      <div class="content-text">
        {{ itemData.commentAppend.content }}
      </div>
    </div>
  </div>
</template>

<script>
import { CommentMixin } from "@/mixins";
export default {
  mixins: [CommentMixin],
  props: {
    itemData: Object,
    goodsId: String,
  },
  data() {
    return {
      text: "店铺名称：尊敬的客户您好，非常抱歉给您带来不便，尊敬的客户您好，非常抱歉给您带来不便，尊敬的客户您好，非常抱歉给您带来不便，尊敬的客户您好，非常抱歉给您带来不便，尊敬的客户您好，非",
      isMore: false,
      isOpen: false,
    };
  },
  computed: {
    getPrivewsList() {
      let arr = [];
      if (
        this.itemData.imagesList &&
        Object.prototype.toString
          .call(this.itemData.imagesList)
          .slice(8, -1) === "Array"
      ) {
        for (let item of this.itemData.imagesList) {
          arr.push({ type: "img", url: item });
        }
      }
      if (this.itemData.commentVo.video) {
        arr.push({
          type: "video",
          url: this.itemData.commentVo.video,
          video: this.itemData.commentVo.video,
        });
      }
      return arr;
    },
  },
  mounted() {
    this.$nextTick(() => {
      if (this.$refs.allText.clientHeight > 96) {
        this.isMore = true;
      }
    });
  },
  methods: {
    goDetails() {
      let query = {
        goodsId: this.goodsId,
        commentId: this.itemData.commentVo.commentId,
      };
      this.$router.push({ name: "comment-detail", query });
    },
    previewItem(index) {
      this.$PreviewImage({
          sources:this.getPrivewsList,
          current:index
        })
    },
  },
};
</script>

<style lang="less">
.comm-item {
  width: 100%;
  padding: 11px 16px;
  margin-bottom: 10px;
  border-radius: 10px;
  background-color: #ffffff;
  .header {
    align-items: center;
    margin-bottom: 6px;
    .avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      background-color: #aeaeae;
      margin-right: 8px;
    }
    .name {
      color: #140603;
      font-size: 14px;
      font-weight: bold;
      flex: 1;
    }
    .time {
      color: #aeaeae;
      font-size: 12px;
      font-weight: normal;
    }
  }
  .content-text {
    color: #140603;
    font-size: 14px;
    line-height: 20px;
    margin-bottom: 12px;
  }
  .content-img {
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    // width: 570rpx;
    // overflow: hidden;
    .item {
      height: 90px;
      width: 90px;
      // background-color: #d8d8d8;
      border-radius: 4px;
      margin-right: 5px;
      margin-bottom: 5px;
    }
    .video-con {
      position: relative;
      video {
        width: 100%;
        height: 100%;
        ::v-deep.uni-video-cover-duration {
          display: none;
        }
      }
      .mask {
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
      }
    }
  }
  .star-sku {
    align-items: center;
    margin-bottom: 8px;
    height: 17px;
    > .star {
      position: relative;
      padding-right: 2px;
      margin-right: 8px;
      ::v-deep.star-fill {
        width: 14px !important;
        height: 14px !important;
      }
      &::after {
        content: "";
        width: 1px;
        height: 10px;
        display: block;
        background-color: #999999;
        position: absolute;
        top: 2px;
        right: 0;
      }
    }
    .sku {
      color: #aeaeae;
      font-size: 12px;
      line-height: 17px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .business-comment {
    position: relative;
    padding-top: 15px;
    border-top: 1px solid #f1f1f1;
    .comment-text {
      font-size: 11px;
      color: #999999;
      line-height: 16px;
      &.ofh {
        max-height: 48px;
        overflow: hidden;
      }
      &.none {
        position: absolute;
        opacity: 0;
        width: 100%;
        // left: 100vw;
      }
    }
    .more {
      font-size: 11px;
      color: #4148ff;
      line-height: 16px;
      margin-top: 6px;
      span {
        padding: 0 5px;
      }
    }
  }
  .append-comment-con {
    margin-top: 20px;
    .title {
      font-size: 15px;
      color: #140603;
      line-height: 21px;
      .m-icon {
        margin-right: 8px;
      }
      margin-bottom: 8px;
    }
    .img-box {
      height: 410px;
      background-color: #d8d8d8;
      border-radius: 10px;
      margin-top: 10px;
    }
  }
  .footer {
    justify-content: flex-end;
    align-items: center;
    .icon-con {
      font-size: 12px;
      line-height: 14px;
      color: #000000;
      align-items: center;
      .uni-icons {
        margin-left: 5px;
        margin-top: 2px;
      }
    }
  }
}
</style>
