<template>
  <div class="chatBIReport" :style="{ height: openMessageflag ? '' : '200px' }">
    <div class="header">
      <div class="reporter">{{ title }}</div>
      <div class="commitTime">
        <div class="label">提交时间：</div>
        <div class="value">{{ commitTime }}</div>
      </div>
    </div>
    <div class="tab">智能洞察<img :src="require('@/assets/dongcha.png')" /></div>
    <div class="content" v-if="reportAnalysisData">
      <p class="message" v-html="reportAnalysisData"></p>
      <div class="foldBtn">
        <img
          :class="[openMessageflag ? 'openMessage-img' : '']"
          :src="require('@/assets/foldBtn.png')"
          @click="openMessageflag = !openMessageflag" />
      </div>
    </div>
    <div class="mask" v-if="!reportAnalysisData">
      <van-loading type="spinner" color="#1989fa" />
    </div>
  </div>
</template>
<script>
import { reportAnalysis } from '@/api/week';
export default {
  props: {
    title: {
      type: String,
      default: '',
    },
    commitTime: {
      type: String,
      default: '',
    },
    reportId: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      openMessageflag: false,
      reportAnalysisData: null,
    };
  },
  created() {
    this.getReportAnalysis();
  },
  methods: {
    getReportAnalysis() {
      reportAnalysis({ reportId: this.reportId })
        .then((res) => {
          if (res.code == 200) {
            this.reportAnalysisData = res.msg || '';
          } else {
            this.$toast(response.msg);
          }
        })
        .catch((error) => {
          this.toastLoading().clear();
          this.$toast(error.msg);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.chatBIReport {
  margin: 10px;
  overflow-y: auto;
  position: relative;
  .header {
    background-color: #fff;
    padding: 10px 16px;
    font-size: 16px;
    margin-bottom: 10px;
  }
  .commitTime {
    display: flex;
    align-items: center;
    margin-top: 10px;
  }
  .tab {
    background-color: #fff;
    font-size: 18px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    color: #0057ba;
    border-bottom: 1px solid #999;
    img {
      width: 20px;
      margin-left: 5px;
    }
  }
  .content {
    background-color: #fff;
    .message {
      padding: 10px 16px;
      font-size: 16px;
      white-space: pre-wrap;
      line-height: 24px;
      background-color: #fff;
      margin-top: 0;
    }
    .foldBtn {
      position: sticky;
      bottom: 0px;
      text-align: right;
      margin-right: 10px;
      img {
        width: 25px;
        transform: rotate(180deg);
      }
      .openMessage-img {
        transform: rotate(0deg);
      }
    }
  }
  .mask {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
