<script setup lang='ts'>
import { ActiveBookingApi } from '@/api/api/activeBooking';
import { showToast } from 'vant';
import {baseIMGUrl} from '@/api/request.ts'


const route = useRoute()
const router = useRouter()

export type activeDetailType = {
  createTime: string,
  creatorId: number,
  creatorName: string,
  dirCode: string,
  fileIds: string,
  id: number,
  isNeed: number,
  name: string,
  publishDate: string,
  rtf: string,
  thumb: string,
  type: string,
  updateTime: string
}

const activeDetail = ref({} as activeDetailType)

const videos = ref([] as any)

const getDetailById = async () => {
  const res: any = await ActiveBookingApi.getDetailById(Number(route.params.id))
  if (res.code == 0) {
    activeDetail.value = res.data.entity

    videos.value = res.data.file.filter((item: any) => {
      return item.filePath.includes('mp4')
    })
  } else {
    showToast(res.msg)
  }
}

const goBooking = () => {
  router.push({
    name: 'activeBookInfo',
    params: {
      id: activeDetail.value.id,
      title: activeDetail.value.name
    }
  })
}



const formatrtf = computed(() => {
  return activeDetail.value.rtf.replace(
    /<img /g,
    '<img style="width: 100%;" '
  ).replace(
    /<p\b[^>]*>/g,
    '<p style="width: 100%; word-wrap: break-word;">'
  );
})


onBeforeMount(() => {
  getDetailById()
})
</script>

<template>
  <div class='detail-box'>
    <img class="themb-box" :src=" baseIMGUrl + activeDetail.thumb" alt="">
    <div class="content-box">
      <div class="title-box">{{ activeDetail.name }}</div>
      <div class="time-box">发布时间：{{ activeDetail.publishDate }}</div>
      <div class="rtf-box" v-html="formatrtf"></div>
      <div class="video-box">
        <video :src="baseIMGUrl + item.filePath" controls v-for="(item, index) in videos" :key="index"></video>
      </div>
    </div>
    <div class="booking-btn" v-if="activeDetail.isNeed" @click="goBooking()">
      发起预约
    </div>
    <img class="back-icon" @click="() => { router.back() }" src="@/assets/images/back.png" alt="">
  </div>
</template>

<style lang='less' scoped>
.detail-box {
  width: 100%;
  background: #F7F3E8;
  min-height: 100%;
  overflow: auto;


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

  }

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

    .title-box {
      font-size: 1.4em;
      font-weight: bold;
      line-height: 1.5em;
      color: #333333;
      margin-bottom: 10px;
      padding: 0 10px;
      font-family: 'SourceHanSansCN-Medium';
      margin-bottom: 5px;

    }

    .time-box {
      color: #9D4F0B;
      font-size: 0.9em;
      margin-bottom: 15px;
      padding: 0 10px;
      font-family: 'SourceHanSansCN-Regular';
    }

    .abstract-box {
      color: rgba(128, 128, 128, 0.664);
      font-size: 1em;
      margin-bottom: 10px;
      padding: 0 10px;

    }

    .rtf-box {
      // white-space: pre;
      margin-bottom: 10px;
      padding: 0 10px;
      color: #88866F;
    }
  }



  .video-box {
    width: 100%;

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

  }

  .booking-btn {
    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;
  }
}
</style>