<!--  -->
<template>
  <div class="EventsInfo">
    <div class="conten">
      <img
        class="topBan aria-theme-independent"
        :src="`/data/About/Events/${imgInd}Ac.jpg`"
        :alt="info.h3"
        tabindex="0"
        :aria-description="info.h3"
      />
      <div class="main">
        <div
          class="pos"
          data-aria-viewport-area
          tabindex="0"
          aria-label="You've reached the path area; this area has two URLs; please use the tab key to go through the content."
        >
          <span tabindex="0">Your Position:&nbsp;</span>
          <Router-link
            replace
            to="/Layout/Home"
            tabindex="0"
            aria-description="Home"
          >
            Home>
          </Router-link>
          <Router-link
            to="/Layout/Events"
            tabindex="0"
            aria-description="Events"
          >
            Events>
          </Router-link>
        </div>
        <div
          class="mainContent"
          data-aria-viewport-area
          tabindex="0"
          aria-label="You've reached the content area of the Events sub-page, please use the tab key to go through the content."
        >
          <div class="title">
            <div class="left">
              <h3 v-html="info.h3" tabindex="0"></h3>
              <div class="txt">
                <p
                  @click="skip(val.path)"
                  @keydown.enter.passive="skip(val.path)"
                  v-for="(val, index) in info.txt"
                  :key="index"
                  tabindex="0"
                  aria-label="Link"
                >
                  {{ val.name }}
                </p>
              </div>
            </div>
            <div class="right">
              <div tabindex="0">Date:</div>
              <p tabindex="0">{{ info.i }}</p>
            </div>
          </div>
          <div class="txtMain" v-html="info.main" v-if="info.main"></div>
          <div
            class="txtMain"
            v-if="info.mainArr"
            v-html="info.mainArr[mainArr]"
          ></div>
          <!-- 分页 -->
          <div class="page" v-if="info.mainArr">
            <span
              @click="pageCut(i - 1)"
              @keydown.enter.passive="pageCut(i - 1)"
              v-for="i in 5"
              :key="i"
              :class="{ active: i === mainArr + 1 }"
              tabindex="0"
              aria-label="Link"
            >
              {{ i }}
            </span>
          </div>
        </div>
      </div>
    </div>
    <!-- 底部的更多 -->
    <div
      class="other"
      data-aria-viewport-area
      tabindex="0"
      aria-label="You've reached the View other events section of the Events sub-page; please use the tab key to go through the content."
    >
      <h2>View Other Events</h2>
      <ul>
        <li v-for="(item, index) in other" :key="index" @click="skip(item.id)">
          <img :src="`/data/About/Events/${item.id}.jpg`" alt="" />
          <div class="txt" v-html="item.h3"></div>
        </li>
      </ul>
    </div>
    <!-- 回到顶部 -->
    <div
      class="topBtn"
      @click="toTop"
      :style="{
        bottom: needMagnifyAreaSpace ? '220px' : '100px',
      }"
      tabindex="0"
      aria-label="Button"
      aria-description="Back to top"
    >
      <img src="/data/About/Events/toTop.jpg" alt="" />
    </div>
  </div>
</template>

<script>
// <p class='xx'>111111111</p> <p>111111111</p> <img src='/data/About/Events/in2/00.png'/>
// <p><i>111111111</i></p>
import { About, AboutOne } from "../dataAll";

export default {
  name: "EventsInfo",
  components: {},
  data() {
    //这里存放数据
    return {
      info: {},
      other: [],
      // 控制顶部的图片
      imgInd: 1,
      mainArr: 0,

      needMagnifyAreaSpace: false,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    $route() {
      this.getData();
    },
  },
  //方法集合
  methods: {
    requestProcessElementInTxtMain() {
      this.$nextTick(() => {
        const txtMainList = document.getElementsByClassName("txtMain");
        for (const iterator of txtMainList) {
          this.$eventBus.$emit("request-process-text-element", iterator);
          this.$eventBus.$emit("request-process-image-element", iterator);
        }
      });
    },
    pageCut(i) {
      this.mainArr = i;
      this.toTop();
      this.requestProcessElementInTxtMain();
    },
    skip(id) {
      this.$router.push(`/Layout/EventsInfo/${id}`).catch(() => {});
      this.requestProcessElementInTxtMain();
    },
    // 点击回到顶部
    toTop() {
      window.scrollTo({ top: 0, behavior: "smooth" });
    },
    // 封装获取id和改变数据的方法
    getData() {
      this.info = {};
      let id = this.$route.params.id;
      id = Number(id);
      // 控制顶部的图片
      if (id < 2) this.imgInd = 1;
      else if (id < 3) this.imgInd = 2;
      else if (id < 4) this.imgInd = 3;
      else if (id < 5) this.imgInd = 4;
      else this.imgInd = 5;
      About.Events.forEach((v) => {
        if (v.id === id) this.info = v;
      });
      // 底部更多模块
      let temp = [];
      if (id < 2) {
        temp.push(AboutOne[1]);
        temp.push(AboutOne[2]);
        temp.push(AboutOne[3]);
        temp.push(AboutOne[4]);
      } else if (id < 3) {
        temp.push(AboutOne[2]);
        temp.push(AboutOne[3]);
        temp.push(AboutOne[4]);
      } else if (id < 4) {
        temp.push(AboutOne[3]);
        temp.push(AboutOne[4]);
      } else if (id < 5) temp.push(AboutOne[4]);
      else temp.push(AboutOne[3]);

      this.other = temp;
    },
    onAriaShowMagnifyArea() {
      this.needMagnifyAreaSpace = true;
    },
    onAriaHideMagnifyArea() {
      this.needMagnifyAreaSpace = false;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getData();
    if ([...document.body.classList].includes("aria-magnifying")) {
      this.needMagnifyAreaSpace = true;
    }
    this.$eventBus.$on("aria-show-magnify-area", this.onAriaShowMagnifyArea);
    this.$eventBus.$on("aria-hide-magnify-area", this.onAriaHideMagnifyArea);
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$eventBus.$emit(
      "request-read",
      `You've reached the sub-page of the Events page.This page contains one navigation section, four window sections, and one interactive section. To choose an section, please hit the shortcut key.`
    );
    this.requestProcessElementInTxtMain();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {
    this.$eventBus.$off("aria-show-magnify-area", this.onAriaShowMagnifyArea);
    this.$eventBus.$off("aria-hide-magnify-area", this.onAriaHideMagnifyArea);
  }, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.EventsInfo {
  .topBtn {
    margin-left: 450px;
    position: fixed;
    left: 50%;
    z-index: 9999;
    cursor: pointer;
  }
  .conten {
    clear: both;
    width: 100%;
    padding-top: 240px;
    .topBan {
      position: absolute;
      left: 50%;
      top: 40px;
      transform: translateX(-50%);
      width: 1180px;
      height: 450px;
      object-fit: cover;
    }
    .main {
      width: 900px;
      margin: 0 auto;
      position: relative;
      z-index: 1;
      .pos {
        font-size: 12px;
        background: #fff;
        padding: 5px 0 5px 30px;
      }
      .title {
        width: 100%;
        display: flex;
        .left {
          background-color: #f4f4f4;
          width: 606px;
          & > h3 {
            font-weight: 700;
            font-family: helvetica;
            font-size: 36px;
            color: #000;
            line-height: 36px;
            padding: 40px 30px 15px 30px;
            /deep/ span {
              color: rgb(255, 0, 0);
            }
          }
          .txt {
            font-family: Georgia;
            font-size: 16px;
            line-height: 20px;
            padding: 0 30px 20px 30px;
            /deep/ p {
              cursor: pointer;
              width: 350px;
              text-align: left;
              color: #000;
              margin: 0 auto;
            }
          }
        }
        .right {
          background-color: #353535;
          width: 294px;
          font-family: Georgia;
          font-size: 30px;
          color: #fff;
          line-height: 30px;
          padding: 40px 20px;
          & > div {
            font-size: 36px;
            line-height: 40px;
            margin-bottom: 30px;
          }
        }
      }
      .txtMain {
        background-color: #fff;
        font-family: arial, helvetica, sans-serif;
        font-size: 16px;
        color: #000;
        line-height: 2em;
        text-align: justify;
        box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
        clear: both;
        padding: 40px 30px;
        /deep/ i {
          font-weight: 700;
        }
        /deep/ p {
          margin-bottom: 30px;
        }
        /deep/ .xx {
          font-weight: 700;
          text-align: center;
        }
        /deep/img {
          display: block;
          margin: 0px auto 30px;
        }
        /deep/ video {
          width: 600px;
          display: block;
          margin: 0px auto 30px;
        }
        /deep/ a {
          font-weight: 700;
          text-decoration: underline;
        }
      }
      .mainContent {
        position: relative;
        .page {
          position: absolute;
          bottom: 10px;
          left: 50%;
          transform: translateX(-50%);
          display: flex;
          justify-content: center;
          & > span {
            width: 30px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            margin-right: 15px;
            border-radius: 50%;
            cursor: pointer;
          }
          .active {
            background-color: #bf2323;
            color: #fff;
            pointer-events: none;
          }
        }
      }
    }
  }
  .other {
    width: 900px;
    overflow: hidden;
    margin: 60px auto;
    & > h2 {
      font-weight: 700;
      font-family: Helvetica;
      font-size: 30px;
      line-height: 54px;
      text-align: center;
      border-bottom: 5px solid #bb1b21;
      margin-bottom: 20px;
    }
    & > ul {
      width: 930px;
      display: flex;
      flex-wrap: wrap;
      & > li {
        cursor: pointer;
        background-color: #fff;
        width: 435px;
        margin-right: 30px;
        margin-bottom: 30px;
        & > img {
          width: 100%;
          height: 210px;
          object-fit: cover;
        }
        .txt {
          font-weight: 700;
          font-family: Helvetica;
          font-size: 24px;
          color: #000;
          line-height: 30px;
          padding: 30px 20px 20px 20px;
          /deep/ span {
            color: rgb(255, 0, 0);
          }
        }
      }
    }
  }
}
</style>