<template>
  <div class="HomeList">
    <!-- 输入框 -->
    <div class="inputBox" @keydown.enter="searchFu()">
      <div class="searInco">
        <van-icon name="search" />
      </div>
      <div class="searBtn" @click="searchFu()">搜索</div>
      <van-field
        maxlength="10"
        v-model="txt"
        placeholder="输入您感兴趣的内容"
      />
    </div>
    <!-- 主体内容 -->
    <div class="mainBoxNull" v-if="dataShow.length === 0">暂无内容</div>
    <div class="mainBox" v-else>
      <div
        class="row"
        @click="handlClick(item.id)"
        v-for="item in dataShow"
        :key="item.id"
      >
        <img :src="require(`@/assets/img/home/${item.id}.jpg`)" alt="" />
        <div class="name">{{ item.name }}</div>
        <div class="loc">
          <img src="../../../assets/img/home/loc.png" alt="" />
          <p>{{ item.loction }}</p>
        </div>
      </div>
    </div>

    <!-- 视频盒子 -->
    <div class="videoBox" :class="{ videoAc: videoShow }">
      <video
        muted
        x-webkit-airplay="true"
        webkit-playsinline="true"
        x5-video-player-type="h5"
        x5-video-orientation="portraint"
        controls
        src="../../../assets/media/home.mp4"
      ></video>
      <img
        v-show="videoBtnShow"
        class="videoBtn"
        src="../../../assets/img/home/videoBtn.png"
        alt=""
        @click="$router.push('/layout/construct')"
      />
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "HomeList",
  components: {},
  data() {
    return {
      txt: "",
      data: [
        { id: 1, name: "老芜湖海关旧址", loction: "滨江公园内" },
        { id: 2, name: "英驻芜领事署旧址", loction: "范罗山" },
        { id: 3, name: "总税务司公所旧址", loction: "范罗山" },
        { id: 4, name: "洋员帮办楼旧址", loction: "范罗山" },
        {
          id: 5,
          name: "英驻芜领事官邸旧址",
          loction: "吉和南路 26 号雨耕山顶",
        },
        { id: 6, name: "天主堂", loction: "吉和街28 号" },
        { id: 7, name: "神父楼", loction: "吉和街28 号" },
        { id: 8, name: "天主教主教公署旧址", loction: "狮子山马路39号" },
        { id: 9, name: "圣母院旧址", loction: "狮子山马路39号" },
        { id: 10, name: "天主教修士楼", loction: "大官山顶" },
        { id: 11, name: "内思高级工业职业学校旧址", loction: "吉和街26号" },
        { id: 12, name: "博仁堂", loction: "安师大附属外国语学校中学内" },
        { id: 13, name: "义德堂", loction: "安师大附属外国语学校中学内" },
        { id: 14, name: "经方堂", loction: "安师大附属外国语学校中学内" },
        { id: 15, name: "广济寺塔", loction: "广济寺内" },
      ],
      dataShow: [],
      videoShow: false,
      videoBtnShow: true,
    };
  },
  computed: {},
  watch: {
    videoShow(val) {
      if (val) {
        let dom = document.querySelector("video");
        dom.play();
        dom.addEventListener(
          "ended",
          () => {
            //结束
            this.$router.push("/layout/construct/1");
          },
          false
        );
        setTimeout(() => {
          this.videoBtnShow = true;
        }, 1000);
      }
    },
  },
  methods: {
    handlClick(id) {
      if (id === 1) this.videoShow = true;
      else this.$router.push(`/layout/construct/${id}`);
    },
    // 获取列表的方法
    getList() {
      if (this.txt.trim() === "") this.dataShow = this.data;
      else this.dataShow = this.data.filter((v) => v.name.includes(this.txt));
    },
    searchFu() {
      this.getList();
    },
  },
  created() {
    document.querySelector("#app").style.maxWidth = "500px";
    this.getList();
    if (this.$route.query.autoWatch) {
      this.handlClick(this.$route.query.autoWatch);
    }
  },
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.HomeList {
  width: 100%;
  height: calc(100% - 80px);
  overflow-y: auto;
  padding: 20px 15px;
  position: relative;
  .inputBox {
    margin: 0px auto;
    width: 100%;
    height: 30px;
    position: relative;

    .searBtn {
      position: absolute;
      right: 0;
      top: 0;
      width: 40px;
      height: 30px;
      border-radius: 3px;
      z-index: 2;
      background-color: #fe6e69;
      font-size: 14px;
      color: #fff;
      line-height: 30px;
      text-align: center;
    }

    .searInco {
      color: #a0a0a0;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 16px;
      position: absolute;
      top: 0;
      left: 10px;
      z-index: 3;
      width: 20px;
      height: 30px;
    }

    /deep/.van-cell {
      width: 100%;
      height: 30px;
      line-height: 30px;
      padding: 0px 0 0px 36px;
      background-color: #f4f4f4;
      border-radius: 5px;
    }
  }
  .mainBoxNull {
    width: 100%;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
  }
  .mainBox {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;

    .row {
      margin-right: 4%;
      margin-bottom: 4%;
      overflow: hidden;
      width: 48%;
      height: 250px;
      background-color: #f7f8fa;
      border-radius: 4px;
      color: #333333;

      &:nth-of-type(2n) {
        margin-right: 0;
      }

      & > img {
        width: 100%;
        height: 180px;
        object-fit: cover;
      }

      .name {
        padding: 10px 0px 3px 6px;
        font-size: 14px;
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .loc {
        width: 100%;
        padding-left: 6px;
        display: flex;
        align-items: center;
        margin-top: 8px;
        & > img {
          margin-right: 3px;
          width: 14px;
        }
        & > p {
          width: calc(100% - 18px);
          font-size: 12px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
  .videoBox {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3;
    width: 100%;
    height: 100%;
    background-color: #fff;

    video {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      // height: 100%;
    }

    .videoBtn {
      position: fixed;
      bottom: 100px;
      width: 200px;
      z-index: 999;
      left: 50%;
      transform: translateX(-50%);
    }
  }

  .videoAc {
    opacity: 1;
    pointer-events: auto;
  }
}
</style>