<template>
  <div class="ExhibitionsList">
    <div class="conten">
      <div class="search">
        <div class="left">
          <!-- 点击放大镜 -->
          <div class="clickSearch" @click="search"></div>
          <el-input
            style="margin-right: 30px"
            suffix-icon="el-icon-search"
            v-model="txt"
          >
          </el-input>
          <el-select
            v-model="year"
            clearable
            placeholder="Select Year"
            @change="selectChange"
          >
            <el-option value="2021" label="2021"></el-option>
            <el-option value="2020" label="2020"></el-option>
            <el-option value="2019" label="2019"></el-option>
            <el-option value="2018" label="2018"></el-option>
            <el-option value="2017" label="2017"></el-option>
            <el-option value="2016" label="2016"></el-option>
            <el-option value="2015" label="2015"></el-option>
          </el-select>
        </div>
        <div class="right">
          <img
            @click="cut = false"
            :src="
              require(`@/assets/images/Exhibitions/${
                cut ? 'cut1' : 'cut1Ac'
              }.png`)
            "
            alt=""
          />
          <img
            @click="cut = true"
            :src="
              require(`@/assets/images/Exhibitions/${
                cut ? 'cut2Ac' : 'cut2'
              }.png`)
            "
            alt=""
          />
        </div>
      </div>
      <div class="null" v-if="data.length === 0">no information...</div>
      <!-- 列表详情信息 -->
      <div class="list" v-if="!cut">
        <div class="row" v-for="item in dataShow" :key="item.id" @click="toInfo(item.id)">
          <img :src="item.cover" alt="" />
          <div class="txt">
            <h3>{{ item.h3 }}</h3>
            <p>{{ item.p }}</p>
            <span>{{ 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="" />
          <p>{{ 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>
</template>

<script>
import { dataAll } from "@/views/dataAll.js";
export default {
  name: "ExhibitionsList",
  components: {},
  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}
      })
    },
    // 选择年份
    selectChange(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().lenght < 3) {
        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;
      .left {
        position: relative;
        display: flex;
        width: 820px;
        height: 48px;
        /deep/.el-input {
          height: 48px;
        }
        /deep/.el-input__inner {
          height: 48px;
          border-radius: 24px;
        }
        /deep/.el-input__suffix {
          right: 10px;
          font-size: 24px;
        }
        /deep/.el-input__icon {
          line-height: 48px;
          color: black;
        }
        .clickSearch {
          cursor: pointer;
          z-index: 999;
          position: absolute;
          width: 48px;
          height: 48px;
          border-radius: 50%;
          right: 196px;
          top: 0;
        }
      }
      .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>