<script setup lang='ts'>
import { ExhibitionApi } from '@/api/api/exhibition';
import { showToast } from 'vant';


const route = useRoute()

export type ExhibitionDetailType = {
  createTime: string,
  creatorId: number,
  creatorName: string,
  dateEnd: string,
  dateStart: string,
  description: string,
  id: number,
  link: string,
  location: string,
  name: string,
  publishDate: string,
  rtf: string,
  thumb:
  string,
  type: string,
  updateTime: string,
  videos: any[]
}

const exhibitionDetail = ref({} as ExhibitionDetailType)

const isShowScene = ref(false)

const getDetailById = async () => {
  const res: any = await ExhibitionApi.getDetailById(Number(route.params.id))
  if (res.code == 0) {
    exhibitionDetail.value = res.data.entity
    exhibitionDetail.value.videos = res.data.file.filter((item: any) => {
      return item.type == 'video'
    })
  } else {
    showToast(res.msg)
  }
}

onBeforeMount(() => {
  getDetailById()
})

</script>

<template>
  <div class='detail-box'>
    <img class="thumb-box" :src="exhibitionDetail.thumb" alt="">
    <div class="content-box">
      <div class="name-box">{{ exhibitionDetail.name }}</div>
      <div class="time-box">
        <div class="location-box"> {{ exhibitionDetail.location }}</div>
        <div>{{ exhibitionDetail.dateStart }} - {{ exhibitionDetail.dateEnd }}</div>
      </div>
      <div class="rtf-box" v-html="exhibitionDetail.rtf"></div>
      <video :src="item" v-for="(item, index) in exhibitionDetail.videos" :key="index" controls></video>
    </div>

    <div class="online-box" @click="() => { isShowScene = true }">体验线上展厅</div>
    <div v-if="isShowScene" class="iframe-box">
      <img src="@/assets/images/sceneBack.png" @click="isShowScene = false" alt="">
      <iframe :src="exhibitionDetail.link" frameborder="0"></iframe>
    </div>
  </div>
</template>

<style lang='less' scoped>
.detail-box {
  width: 100%;
  height: 100vh;
  max-width: 500px;
  position: relative;
  overflow: auto;

  .thumb-box {
    width: 100%;
    margin-bottom: 10px;
    height: 30vh;
  }

  .content-box {
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    height: calc(70vh + 25px);
    overflow: auto;
    border-radius: 20px 20px 0 0;
    margin-top: -40px;
    position: relative;
    z-index: 2;
    background: #F7F3E8;
    padding: 25px 20px;
    box-sizing: border-box;


    .name-box {
      width: 100%;
      font-size: 1.2em;
      font-weight: bold;
      color: #333333;
      font-family: 'SourceHanSansCN-Medium';
      line-height: 1.5em;
      margin-bottom: 10px;
    }

    .time-box {
      width: 100%;
      display: flex;
      justify-content: space-between;
      color: #9D4F0B;
      margin: 10px auto;
      font-size: 0.8em;
      align-items: center;

      .location-box {
        max-width: 50vw;
      }

    }

    .rtf-box {
      color: #88866F;
    }

  }

  video {
    width: 100%;
    margin-top: 10px;
  }

  .online-box {
    width: 80%;
    max-width: 400px;
    height: 60px;
    border-radius: 50px;
    background: url(@/assets/images/onlineBg.png);
    background-size: 100% 100%;
    color: #F1E9D4;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 3vh;
    display: flex;
    justify-content: center;
    align-items: center;
    letter-spacing: 2px;
    font-weight: bold;
    z-index: 2;
  }

  .back-icon {
    width: 40px;
    position: fixed;
    right: 10px;
    bottom: 10vh;
  }

  .iframe-box {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;

    iframe {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }

    img {
      width: 30px;
      height: 30px;
      position: absolute;
      top: 3%;
      left: 3%;
      z-index: 11;
    }
  }
}
</style>