<!-- -->
<template>
  <div class="display-detail">
    <div class="wrapper">
      <div class="back">
        <el-button
          type="text"
          icon="el-icon-arrow-left"
          @click.native="handleBack"
          >返回上页</el-button
        >
      </div>
      <el-row class="detail-container" :gutter="10">
        <el-col class="cr-images" :span="18">
          <el-carousel
            indicator-position="outside"
            :autoplay="false"
            height="600px"
          >
            <el-carousel-item
              v-for="(item, index) in CRDetail.imagesVo"
              :key="index"
            >
              <el-image
                class="el-image-container"
                :src="$getFullUrl(item.url)"
                fit="contain"
              ></el-image>
            </el-carousel-item>
          </el-carousel>
          <div class="enlarge" @click="handelPreviewImages">
            <img src="@/assets/imgs/enlarge-s.png" alt="" />
          </div>
        </el-col>
        <el-col class="relic-info" :span="8">
          <div class="info-title">
            <div
              class="title-container"
            >
              <h3>
                {{ CRDetail.name }}
              </h3>
              <span class="view-container">
                <svg-icon
                  icon-class="view"
                  class="view-svg-icon"
                ></svg-icon>
                <span class="view-text">{{ CRDetail.browseCount }}</span>
              </span>
            </div>

            <AudioPlayer
              :url="$getFullUrl(CRDetail.audiosVo[0].url)"
              ref="AudioPlayer"
              v-if="CRDetail.audiosVo && CRDetail.audiosVo.length > 0"
            />
          </div>
          <div class="info-body">
            <div class="basic-info">
              <div class="body-item">
                <span class="label">年份</span>
                <span class="value">{{ CRDetail.yearsLabel }}</span>
              </div>
              <div class="body-item">
                <span class="label">类别</span>
                <span class="value">
                  {{ CRDetail.typeLabel }}
                </span>
              </div>
              <div class="body-item">
                <span class="label">级别</span>
                <span class="value">{{ CRDetail.levelLabel }}</span>
              </div>
              <div class="body-item">
                <span class="label">质地</span>
                <span class="value">{{ CRDetail.textureTypeLabel }}</span>
              </div>
              <div class="body-item">
                <span class="label">尺寸</span>
                <span class="value">{{ CRDetail.detailSize }}</span>
              </div>
              <div class="body-item">
                <span class="label">馆藏单位</span>
                <span class="value">{{ CRDetail.deptName }}</span>
              </div>
            </div>
            <!-- <div class="qrcode" ref="qrCodeUrl"></div> -->
          </div>
          <div class="view-3d" @click="handleTo3D" v-if="CRDetail.url3d">
            <img
              src="@/assets/imgs/cr/3d-black.png"
              alt=""
              srcset=""
              width="24px"
              height="24px"
            />
            <span>查看3D模型</span>
          </div>
          <ReaderOperations
            :loveCount="CRDetail.loveCount"
            :loveCountStatus="Boolean(CRDetail.loveCountStatus)"
            :collectCount="CRDetail.collectCount"
            :collectCountStatus="Boolean(CRDetail.collectCountStatus)"
            :sourceId="CRDetail.crId"
            :title="CRDetail.name"
            :sourceType="'biz_cultural_relic'"
            @reload="loadDetail"
          />
        </el-col>
      </el-row>

      <div class="margin-bottom-32">
        <CustomTitle text="文物简介" />
        <div class="intro text-indent">
          {{ CRDetail.intro }}
        </div>
      </div>

      <div class="relate-book margin-bottom-32">
        <CustomTitle text="相关文献" />
        <div
          class="book-item"
          v-for="(item, index) in CRDetail.literatureVo"
          :key="index"
        >
          <span class="mr-20">{{ item.name }}</span>
          <span class="mr-20">{{ item.author }}</span>
          <span>{{ item.source }}</span>
        </div>
      </div>
      <div class="relate-cultual-relic margin-bottom-32">
        <CustomTitle text="关联文物" />
        <div class="display-group">
          <div
            class="display-item"
            v-for="(item, index) in relateRelics"
            :key="index"
            @click="handleToDetail(item.crId)"
          >
            <img :src="$getFullUrl(item.faceImageUrl)" width="100%" :alt="item.title" />
            <div class="display-desc">
              <div class="desc-title">
                <h4>{{ item.name }}</h4>
              </div>
              <!-- <div class="desc-time">
                <span>{{ item.time }}</span>
              </div>
              <a class="desc-content" :alt="item.content">
                {{ item.content }}
              </a> -->
            </div>
          </div>
        </div>
      </div>
      <div
        class="relate-video margin-bottom-32"
        v-if="CRDetail.videosVo && CRDetail.videosVo.length > 0"
      >
        <CustomTitle text="关联视频" />
        <el-carousel :interval="4000" type="card" height="400px">
          <el-carousel-item
            v-for="item in CRDetail.videosVo"
            :key="item.fileId"
          >
            <div class="video-container">
              <div class="video-box">
                <Video :url="$getFullUrl(item.url)" />
              </div>
              <div class="info-box">
                <h4 class="name">{{ item.name.split(".")[0] }}</h4>
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
    <el-image-viewer
      v-if="imgViewerVisible"
      :on-close="closeImgViewer"
      :url-list="imgList"
    />
  </div>
</template>

<script>
import SearchBar from "@/components/SearchBar";
import AudioPlayer from "@/components/AudioPlayer";
import CustomTitle from "@/components/CustomTitle";
import ReaderOperations from "@/components/ReaderOperations";
import QRCode from "qrcodejs2";
import { getRCDetailById, crRecommendByPage } from "@/api/culturalRelic";
export default {
  components: {
    SearchBar,
    CustomTitle,
    AudioPlayer,
    ReaderOperations,
    "el-image-viewer": () =>
      import("element-ui/packages/image/src/image-viewer"),
  },

  data() {
    return {
      options: [
        {
          value: "name",
          label: "文物名称",
        },
      ],
      selectValue: "",
      keyword: "",
      CRDetail: {},
      slideImageWidth: "",
      imgViewerVisible: false,
      relateRelics: [],
      imgList:[]
    };
  },
  mounted() {
    // this.creatQrCode();
    this.loadDetail();
  },
  methods: {
    creatQrCode() {
      this.$nextTick(() => {
        var qrcode = new QRCode(this.$refs.qrCodeUrl, {
          text: "http://www.gzmuseum.com/", // 需要转换为二维码的内容
          width: 100,
          height: 100,
          colorDark: "#000000",
          colorLight: "#ffffff",
          correctLevel: QRCode.CorrectLevel.H,
        });
      });
    },
    async loadDetail() {
      let crId = this.$route.params.crId;
      if (crId) {
        let res = await getRCDetailById({ crId });
        if (res.code == 0) {
          this.CRDetail = res.data;
          // debugger
          // 获取关联文物
          this.loadCrRecommend();
          this.$nextTick(() => {
            // this.$message.info("正在播放当前文物讲解音频，点击按钮可关闭");
            // this.$refs.AudioPlayer.play();
          });
        }
      }
    },

    async loadCrRecommend() {
      const {
        crId,
        deptId,
        directory,
        level,
        name,
        regionCode,
        remark,
        sourceWay,
        status,
        textureType,
        themeWord,
        type,
        years,
      } = this.CRDetail;
      // debugger
      const params = {
        crId,
        // deptId,
        // directory,
        // level,
        // name,
        // regionCode,
        // remark,
        // sourceWay,
        // status,
        // textureType,
        // themeWord,
        type,
        // years,
        page: 1,
        limit: 5,
      };
      let res = await crRecommendByPage(params);
      this.relateRelics = res.data.records;
      console.log("res", res);
    },
    handleBack() {
      this.$router.go(-1);
    },

    handleTo3D() {
      window.open(this.CRDetail.url3d, "_blank");
    },

    closeImgViewer() {
      this.imgViewerVisible = false;
    },

    handelPreviewImages() {
      this.imgViewerVisible = true;
      this.imgList = this.CRDetail.imagesVo.map((item) => this.$getFullUrl(item.url));
    },
    handleToDetail(crId) {
      console.log(crId);
      this.$router.replace({ name: "culturalRelicDetail", params: { crId } });
    },
  },
};
</script>

<style lang="scss" scoped>
.mr-20 {
  margin-right: 20px;
}
$label: #9f9c9a;
.search {
  width: 1200px;
  margin: auto;
  margin-bottom: 32px;
}
.wrapper {
  width: 1200px;
  margin: 60px auto;
  background-color: #fff;
  padding: 40px;
  .back {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 40px;
    .el-button {
      color: $label;
    }
  }
  .detail-container {
    margin-bottom: 32px;
    // display: flex;
    img {
      max-width: 100%;
      height: auto;
    }
    .cr-images {
      width: 700px;
      margin-right: 32px;
      position: relative;
      .el-image {
        background-color: #f5f5f9;
      }
      .enlarge {
        position: absolute;
        bottom: 60px;
        right: 40px;
        display: flex;
        z-index: 9;
        background-color: #c1925b;
        width: 40px;
        height: 40px;
        border-radius: 12px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 10px;
        cursor: pointer;
        img {
          width: 24px;
          height: 24px;
        }
      }
    }
    .relic-info {
      .info-title {
        display: flex;
        // align-items: center;
        flex-direction: column;
        margin-bottom: 40px;
        .title-container{
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        .play {
          margin-left: 10px;
          font-size: 32px;
          cursor: pointer;
        }
      }
      .info-body {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;

        .basic-info {
          .body-item {
            display: flex;
            .label {
              display: block;
              width: 80px;
              margin-right: 26px;
              margin-bottom: 10px;
              font-weight: bold;
              color: #9f9c9a;
            }
          }
        }
      }

      .view-3d {
        margin-top: 32px;
        padding: 6px 10px;
        width: 100%;
        background-color: #c1925b;
        border-radius: 48px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
        cursor: pointer;
        img {
          margin-right: 10px;
        }
      }
    }

    .title-container {
      display: flex;
      justify-content: center;
      position: relative;
      .operation {
        position: absolute;
        right: 0;
        display: flex;
        align-items: center;
        height: 100%;
      }
    }
    .content {
      text-indent: 32px;
    }
  }
  .relate-book {
    .book-item {
      margin-bottom: 10px;
    }
  }
  .relate-cultual-relic {
    .display-group {
      margin-top: 24px;
      display: flex;
      flex-flow: row wrap;

      .display-item {
        width: 282px;
        margin-bottom: 32px;
        border-radius: 16px;
        border: 1px solid rgba(0, 0, 0, 0.1);
        // padding: 0 0 32px 0;
        background-color: #fff;
        margin-right: 10px;
        cursor: pointer;
        img {
          border-radius: 16px 16px 0 0;
        }
        .display-desc {
          padding: 0 16px;
          .desc-content {
            text-indent: 16px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            display: block;
          }
        }
        .display-source {
          margin-top: 8px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 16px;
        }
      }
    }
  }

  .relate-video {
    .video-container {
      display: flex;
      flex-direction: column;
      align-items: center;
      .video-box {
        display: flex;
        justify-content: center;
        border: 1px solid #000;
        video {
          width: 800px;
        }
      }
      .info-box {
        width: 800px;
        display: flex;
        justify-content: space-between;
      }
    }
  }
}

.text-indent {
  text-indent: 28px;
}

.margin-bottom-32 {
  margin-bottom: 32px;
}
.el-image-container {
  width: 100%;
  height: 100%;
}
</style>
