<template>
  <div>
    <scroll-view
        scroll-y
        class="commentList"
        @scrolltolower="page.current++, getComments()"
    >
      <div class="comments-list" v-if="commentList.length">
        <div
            class="comments-item flex-row"
            v-for="(item, i) in commentList"
            :key="i"
        >
          <div class="user-avatar">
            <image v-if="item.avatar" :src="item.avatar"></image>
            <image v-else src="https://cdn.cunwuyun.cn/img/personal.png"></image>
          </div>
          <div class="content flex-column">
            <div class="flex-row" style="justify-content: space-between">
              <text>{{ item.createUser }}</text>
              <text class="commentTime">{{ item.commentTime }}</text>
            </div>
            <div>{{ item.content }}</div>
          </div>
        </div>
      </div>
      <AiEmpty v-else/>
      <view class="tips" v-if="commentList.length"> 已加载全部评论</view>
    </scroll-view>
  </div>
</template>

<script>
export default {
  name: "commentList",
  props: {
    detail: Object,
  },
  data() {
    return {
      commentList: [],
      page: {
        current: 1,
        size: 10000,
      },
    };
  },
  methods: {
    getComments() {
      this.$instance.post(`/app/apppartyhistorycomment/list?partyHistoryId=${this.detail.id}&size=10000`).then((res) => {
        if (res && res.data) {
          this.commentList = res.data.records;
          this.$emit("comments", res.data.total);
        }
      });
    },
  },
  mounted() {
    this.$nextTick(() => this.getComments());
  },
};
</script>

<style lang="scss" scoped>
.commentList {
  width: 100%;
  margin-bottom: 135px;
  overflow-y: auto;

  .comments-list {
    width: 100%;
    overflow-y: auto;
    box-sizing: border-box;

    .user-avatar {
      display: inline-block;
      width: 80px;
      margin: 46px 20px 0 0;

      image {
        width: 80px;
        height: 80px;
        border-radius: 50%;
      }

      .user-bg {
        display: inline-block;
        width: 80px;
        height: 80px;
        border-radius: 50%;
        line-height: 80px;
        text-align: center;
        background-color: #26f;
        color: #fff;
        font-size: 28px;
      }
    }

    .comments-item {
      border-bottom: 1px solid #f7f7f7;
      padding: 0 32px;
      color: #333;
      font-size: 28px;
      background-color: #fff;

      & + .comments-item {
        border-top: 4px solid #eee;
      }

      .content {
        display: inline-block;
        width: calc(100% - 120px);
        background-color: #fff;
        padding: 46px 0 32px 0;
        box-sizing: border-box;

        .name {
          margin-bottom: 10px;
        }
      }

      .commentTime {
        color: #999;
        font-size: 24px;
      }
    }
  }

  .tips {
    line-height: 90px;
    width: 100%;
    color: #999;
    font-size: 24px;
    text-align: center;
    background-color: #f3f6f9;
  }

  .no-comment-list {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px;
  }
}
</style>
