<template>
  <div class="ExhibitionsList">
    <div class="conten">
      <div class="search" data-aria-interaction-area tabindex="0"
        aria-label aria-description="You've reached search box under the Exhibitions page; please use the tab key to go through the content."
      >
        <div class="left">
          <div
            class="text-input-wrapper"
            @keydown.enter.passive="search"
          >
            <input
              type="text"
              autocomplete="off"
              v-model="txt"
              tabindex="0"
              :aria-description="txt || 'search'"
            />
            <img v-if="themeIdx === 0" :src="require('@/assets/images/search-default-color.svg')" alt=""
              @click="search"
              tabindex="0"
              aria-label="Link"
              aria-description="search"
            >
            <img v-if="[1, 3].includes(themeIdx)" :src="require('@/assets/images/search-black.svg')" alt=""
              @click="search"
              tabindex="0"
              aria-label="Link"
              aria-description="search"
            >
            <img v-if="[2, 4].includes(themeIdx)" :src="require('@/assets/images/search-yellow.svg')" alt=""
              @click="search"
              tabindex="0"
              aria-label="Link"
              aria-description="search"
            >
          </div>
          <!-- 使用el-select组件会无法在选择年份过程中得到选项的无障碍信息，所以改用原生元素 -->
          <select
            id="year-selector"
            v-model="year"
            @change="onSelectorChange"
            tabindex="0"
            class="yearSelector"
            aria-label="Select"
            aria-description="Select Year"
          >
            <option value="">Select Year</option>
            <option value="2024">2024</option>
            <option value="2021">2021</option>
            <option value="2020">2020</option>
            <option value="2019">2019</option>
            <option value="2018">2018</option>
            <option value="2017">2017</option>
            <option value="2016">2016</option>
            <option value="2015">2015</option>
          </select>
        </div>
        <div class="right">
          <img
            @click="cut = false"
            @keydown.enter.passive="cut = false"
            :src="
              require(`@/assets/images/Exhibitions/${
                cut ? 'cut1' : 'cut1Ac'
              }.png`)
            "
            alt="Button: List mode"
            tabindex="0"
            aria-label="Button"
            aria-description="List mode"
          />
          <img
            @click="cut = true"
            @keydown.enter.passive="cut = true"
            :src="
              require(`@/assets/images/Exhibitions/${
                cut ? 'cut2Ac' : 'cut2'
              }.png`)
            "
            alt="Button: Big image mode"
            tabindex="0"
            aria-label="Button"
            aria-description="Big image mode"
          />
        </div>
      </div>
      <div class="null" v-if="data.length === 0" tabindex="0">no information...</div>
      <!-- 列表详情信息 -->
      <div class="listAreaWrapper" data-aria-viewport-area tabindex="0"
        aria-label :aria-description="`You've reached the content area of the ${$parent.topLi[$route.params.id - 1].name} page. To browse the content, please use the tab key.`">
        <div class="list" v-if="!cut">
          <div
            class="row"
            v-for="item in dataShow"
            :key="item.id"
            @click="toInfo(item.id)"
            @keydown.enter.passive="toInfo(item.id)"
          >
            <img :src="item.cover" :alt="item.h3"
              tabindex="0"
              aria-label="Image link"
              :aria-description="item.h3"
            />
            <div class="txt">
              <h3 tabindex="0"
                aria-label="Link"
              >
                {{ item.h3 }}
              </h3>
              <p tabindex="0"
                aria-label="Link"
              >
                {{ item.p }}
              </p>
              <span v-if="item.yrahTxt" tabindex="0">{{ item.yrahTxt }}</span>
            </div>
          </div>
        </div>
        <!-- 列表图片信息 -->
        <div class="listImg" v-else>
          <div class="rowImg" v-for="item in dataShow" :key="item.id" @click="toInfo(item.id)">
            <img :src="item.cover" alt="" 
              tabindex="0"
              aria-label="Image link"
              :aria-description="item.h3"
            />
            <p tabindex="0">{{ item.h3 }}</p>
          </div>
        </div>
        <!-- 点击显示更多 -->
        <div class="more" v-show="data.length>9&&dataShow.length<data.length" @click="dataShowArr(dataShow.length+9)">Show More</div>
      </div>
    </div>
  </div>
</template>

<script>
import { dataAll } from "@/views/dataAll.js";
import accessibilityMixin from "/src/views/accessibilityMixin.js"

export default {
  name: "ExhibitionsList",
  components: {},
  mixins: [accessibilityMixin],
  data() {
    //这里存放数据
    return {
      txt: "",
      year: "",
      // 切换图像信息或文章信息---默认详情
      cut: false,
      topId: null,
      data: [],
      dataShow: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    // 监听地址栏参数变化
    $route() {
      // 改变数据
      this.getIdChangeData();
      this.dataShowArr(9);
      // 把试图变成详情
      this.cut = false;
      // 清空输入框和下拉框
      this.txt = this.year = "";
    },
  },
  //方法集合
  methods: {
    // 点击单个文章跳转详情
    toInfo(id){
     let k = this.$route.params.id;
      this.$router.push({
        name:'ExhibitionsInfo',
        query:{id,k}
      })
    },
    // 选择年份
    onSelectorChange() {
      this.$eventBus.$emit('request-magnify', {
        elemType: 'Text',
        elemDisc: this.year,
      })
      if (!this.year) {
        this.getIdChangeData();
        this.dataShowArr(9);
        return;
      }
      this.getIdChangeData();
      this.txt = "";
      this.data = this.data.filter((v) => {
        return v.year.includes(this.year) || v.year === "";
      });
      this.dataShowArr(9);
    },
    elSelectChange(val) {
      if (!val) {
        this.getIdChangeData();
        this.dataShowArr(9);
        return;
      }
      this.getIdChangeData();
      this.txt = "";
      this.data = this.data.filter((v) => {
        return v.year.includes(val) || v.year === "";
      });
      this.dataShowArr(9);
    },
    // 点击搜索
    search() {
      if (this.txt.trim() === "" || this.txt.trim().length < 4) {
        this.getIdChangeData();
        this.dataShowArr(9);
        return;
      }
      this.data = this.data.filter((v) => {
        return v.h3.includes(this.txt) || v.p.includes(this.txt);
      });
      this.dataShowArr(9);
    },
    // 封装通过地址栏参数改变数据的方法
    getIdChangeData() {
      // 拿到路由参数id
      let temp = this.$route.params.id;
      if (temp === "1") this.data = dataAll.Exhibitions.Current;
      else if (temp === "2") this.data = dataAll.Exhibitions.Permanent;
      else if (temp === "3") this.data = dataAll.Exhibitions.Past;
      else if (temp === "4") this.data = dataAll.Exhibitions.Overseas;
    },
    // 处理显示在页面的数组初始数据为9
    dataShowArr(val) {
      let temp = [];
      this.data.forEach((v, i) => {
        if (i < val) temp.push(v);
      });
      this.dataShow = temp;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getIdChangeData();
    this.dataShowArr(9);
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.ExhibitionsList {
  .conten {
    width: 1180px;
    margin: 0 auto;
    .search {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        position: relative;
        display: flex;
        width: 820px;
        height: 48px;
        .text-input-wrapper {
          height: 48px;
          background: white;
          border: 1px solid #c7c7c7;
          display: flex;
          align-items: center;
          margin-right: 30px;
          > input {
            height: 100%;
            font-size: 24px;
            border: none;
            padding: 0px 10px;
            width: 500px;
            box-sizing: border-box;
            border: none;
            margin: 0;
            outline: none;
          }
          > img {
            height: 30px;
            width: 30px;
            margin-left: 10px;
            margin-right: 10px;
            cursor: pointer;
          }
        }
        .yearSelector {
          border-color: #c0c4cc;
          width: 180px;
          padding-left: 10px;
          cursor: pointer;
          font-size: 18px;
          option {
            cursor: pointer;
            color: #606266;
            font-size: 18px;
          }
        }
      }
      .right {
        & > img {
          cursor: pointer;
          width: 48px;
          height: 48px;
        }
      }
    }
    .null {
      font-size: 30px;
      margin-top: 50px;
      text-align: center;
    }
    .list {
      margin: 20px 0 40px;
      .row {
        cursor: pointer;
        display: flex;
        height: 240px;
        background-color: #fff;
        & > img {
          width: 240px;
          height: 240px;
          object-fit: cover;
        }
        .txt {
          flex: 1;
          border: 1px solid #c7c7c7;
          border-left: 0;
          padding: 0 25px;
          position: relative;
          & > h3 {
            font-size: 18px;
            line-height: 22px;
            padding: 16px 0;
            margin-bottom: 13px;
            font-weight: bold;
          }
          & > p {
            font-size: 14px;
            line-height: 20px;
            color: #666;
          }
          & > span {
            display: block;
            position: absolute;
            left: 25px;
            bottom: 15px;
            font-size: 14px;
            line-height: 20px;
            font-weight: bold;
          }
        }
      }
    }
    .listImg {
      margin: 20px 0 40px;
      display: flex;
      flex-wrap: wrap;
      .rowImg {
        overflow: hidden;
        position: relative;
        cursor: pointer;
        width: 393px;
        height: 393px;
        & > img {
          width: 393px;
          height: 393px;
        }
        & > p {
          font-weight: 700;
          width: 100%;
          font-size: 16px;
          line-height: 32px;
          color: #fff;
          overflow: hidden;
          transition: all 0.3s;
          position: absolute;
          left: 0;
          bottom: -300px;
          padding: 15px 25px;
          background-color: rgba(0, 0, 0, 0.8);
        }
        &:hover {
          & > p {
            bottom: 0;
          }
        }
      }
    }
    .more {
      height: 38px;
      width: 160px;
      margin: 0 auto 60px;
      border: 1px solid #000;
      font-size: 16px;
      line-height: 38px;
      text-align: center;
      font-weight: bold;
      cursor: pointer;
    }
  }
}
</style>