<!-- -->
<template>
  <div class="display-detail">
    <div class="search">
      <SearchBar
        :options="options"
        :selectValue="selectValue"
        :keyword="keyword"
      />
    </div>
    <div class="wrapper">
      <div class="detail-container">
        <div class="title-container">
          <h3 class="title">{{ displayDetail.title }}</h3>
          <div class="operation">
            <svg-icon icon-class="user" style="color:red"></svg-icon>
            <el-button
              type="text"
              @click.native="handleCollect(exhibitionId)"
              >{{
                displayDetail.collectCountStatus ? "收藏" : "取消收藏"
              }}</el-button
            >
            <el-button type="text" @click.native="handleLike(exhibitionId)">{{
              displayDetail.loveCountStatus ? "点赞" : "取消点赞"
            }}</el-button>
            <el-button type="text" @click.native="handleShare(exhibitionId)"
              >转发</el-button
            >
          </div>
        </div>

        <div class="content">
          <div class="intro margin-bottom-32">{{ displayDetail.intro }}</div>
          <div
            class="images"
            v-if="displayDetail.imagesVo && displayDetail.imagesVo.length > 0"
          >
            <el-row :gutter="20">
              <el-col
                :span="24"
                v-for="item in displayDetail.imagesVo"
                :key="item.fileId"
              >
                <img :src="item.url" alt="" width="100%"/>
                <div class="name flex-center margin-bottom-32">
                  {{ item.name }}
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>

      <div class="relate-book margin-bottom-32">
        <CustomTitle text="相关文献" />
        <div
          class="book-item"
          v-for="(item, index) in displayDetail.literatureVo"
          :key="index"
        >
          <span>{{ item.name }}</span>
          <span style="margin: 0 20px">{{ item.author }}</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"
          >
            <img
              src="@/assets/imgs/display2.png"
              width="100%"
              :alt="item.title"
            />
            <div class="display-desc">
              <div class="desc-title">
                <h4>{{ item.title }}</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">
        <CustomTitle text="关联视频" />
        <el-carousel :interval="4000" type="card" height="400px">
          <el-carousel-item
            v-for="item in displayDetail.videosVo"
            :key="item.fileId"
          >
            <div class="video-container">
              <div class="video-box">
                <!-- <video
                  :src="item.url"
                  style="height: auto; width: 100%"
                  controls
                  loop
                ></video> -->
                <Video :url="item.url" />
              </div>
              <div class="info-box">
                <h4 class="name">{{ item.name.split(".")[0] }}</h4>
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div
        class="relate-video margin-bottom-32"
        v-if="
          displayDetail.exhibitionUnits &&
          displayDetail.exhibitionUnits.length > 0
        "
      >
        <CustomTitle text="布展单元" />
        <el-row :gutter="20">
          <el-col :span="8">
            <!-- 只能单开 unique-opened -->
            <menu-list
              :items="displayDetail.exhibitionUnits"
              :isCollapse="false"
              @open="handleOpenUnit"
            ></menu-list>
          </el-col>
          <el-col :span="16">
            <el-card>
              <div slot="header" class="clearfix">
                <span>单元介绍</span>
              </div>
              <div class="unit-content">
                <div class="intro text-indent" v-if="curUnit.intro">
                  {{ curUnit.intro }}
                </div>
                <div
                  class="images"
                  v-if="curUnit.imagesVo && curUnit.imagesVo.length > 0"
                >
                  <el-row :gutter="20">
                    <el-col
                      :span="24 / curUnit.imagesVo.length"
                      v-for="item in curUnit.imagesVo"
                      :key="item.euId"
                      class="margin-bottom-32"
                    >
                      <img :src="item.url" alt="" srcset="" width="100%" />
                      <div class="desc flex-center">
                        {{ item.name }}
                      </div>
                    </el-col>
                  </el-row>
                </div>
                <div
                  class="videos"
                  v-if="curUnit.videosVo && curUnit.videosVo.length > 0"
                >
                  <el-row :gutter="20">
                    <el-col
                      :span="24 / curUnit.videosVo.length"
                      v-for="item in curUnit.videosVo"
                      :key="item.euId"
                    >
                      <Video :url="item.url" />
                    </el-col>
                  </el-row>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>

    <el-dialog
      title="登录提示"
      :visible.sync="loginDialogVisible"
      width="30%"
      :before-close="handleLoginClose"
    >
      <span>读者功能需登录进行使用，是否去登录？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="loginDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleToLogin">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="分享"
      :visible.sync="shareDialogVisible"
      width="40%"
      :before-close="handleShareClose"
    >
      <div class="qrcode">
        <div>
          <img
            src="@/assets/404_images/no-pic.png"
            alt="二维码"
            width="100px"
            height="100px"
          />
        </div>
        <div>扫描左侧二维码，跳转到对应小程序页面后分享，或复制下方链接</div>
      </div>
      <div class="copy">
        <div class="link">{{ curLink }}</div>
        <el-button type="text">复制链接</el-button>
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="loginDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleToLogin">确 定</el-button>
      </span> -->
    </el-dialog>
  </div>
</template>

<script>
import SearchBar from "@/components/SearchBar";
import MenuList from "@/components/MenuList";
import CustomTitle from "@/components/CustomTitle";
import { getDisplayById } from "@/api/display";
// import { getToken } from "@/utils/auth";
import { mapGetters } from "vuex";
import Video from "@/components/Video";
export default {
  components: { SearchBar, CustomTitle, MenuList, Video },
  data() {
    return {
      options: [
        {
          value: "name",
          label: "文物名称",
        },
      ],
      selectValue: "",
      displayDetail: {},
      keyword: "",
      exhibitionId: "",
      loginDialogVisible: false,
      shareDialogVisible: false,
      curLink: "", //当前地址栏的链接
      curUnit: {}, //当前点击的单元
    };
  },
  mounted() {
    this.loadDetail();
  },
  computed: {
    ...mapGetters(["token"]),
  },
  methods: {
    async loadDetail() {
      // debugger
      console.log(this.$route.params);
      let exhibitionId = this.$route.params.exhibitionId;
      this.exhibitionId = exhibitionId;
      if (exhibitionId) {
        let res = await getDisplayById({ exhibitionId });
        if (res.code == 0) {
          this.displayDetail = res.data;
          if (
            this.displayDetail.exhibitionUnits &&
            this.displayDetail.exhibitionUnits.length > 0
          ) {
            this.curUnit = this.displayDetail.exhibitionUnits[0];
          }
          processUnit(this.displayDetail.exhibitionUnits);
          // console.log(unit);
          function processUnit(list) {
            for (let o of list || []) {
              if (o.children) {
                if (o.children.length == 0) {
                  o.children = null;
                } else {
                  processUnit(o.children);
                }
              }
            }
          }
        }
      }
    },
    // 收藏
    async handleCollect(exhibitionId) {
      if (this.token) {
        const params = {
          sourceId: exhibitionId,
          sourceType: "biz_exhibition",
          title: this.displayDetail.title,
        };
        await this.$store.dispatch("user/toggleCollect", params);
      } else {
        this.loginDialogVisible = true;
      }
    },
    // 点赞
    async handleLike(exhibitionId) {
      if (this.token) {
        const params = {
          sourceId: exhibitionId,
          sourceType: "biz_exhibition",
          title: this.displayDetail.title,
        };
        await this.$store.dispatch("user/toggleLike", params);
      } else {
        this.loginDialogVisible = true;
      }
    },

    handleShare() {
      this.curLink = window.location.href.toString();
      this.shareDialogVisible = true;
    },
    handleToLogin() {
      this.$router.push(`/login?redirect=${this.$route.fullPath}`);
    },
    handleLoginClose() {
      this.loginDialogVisible = false;
    },
    handleShareClose() {
      this.shareDialogVisible = false;
    },
    handleOpenUnit(item) {
      this.curUnit = item;
    },
  },
};
</script>

<style lang="scss" scoped>
.search {
  width: 1200px;
  margin: auto;
  margin-bottom: 32px;
}
.wrapper {
  width: 1200px;
  margin: auto;
  .detail-container {
    margin-bottom: 32px;
    .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: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
}

.margin-bottom-32 {
  margin-bottom: 32px;
}

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

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.qrcode,
.copy {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
