<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}.png`)" alt="" />
        <div class="name">{{ item.name }}</div>
        <div class="loc">
          <img src="../../../assets/img/home/loc.png" alt="" />
          {{ item.loction }}
        </div>
      </div>
    </div>

    <!-- 视频盒子 -->
    <div class="videoBox" :class="{ videoAc: videoShow }">
      <video muted 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: "芜湖市镜湖区滨江路桥口" },
      ],
      dataShow: [],
      videoShow: false,
      videoBtnShow: false,
    };
  },
  computed: {},
  watch: {
    videoShow(val) {
      if (val) {
        let dom = document.querySelector("video");
        dom.play();
        dom.addEventListener(
          "ended",
          () => {
            //结束
            this.$router.push("/layout/construct");
          },
          false
        );
        setTimeout(() => {
          this.videoBtnShow = true;
        }, 1000);
      }
    },
  },
  methods: {
    handlClick(id) {
      if (id === 2) this.videoShow = true;
      else return Toast("敬请期待!");
    },
    // 获取列表的方法
    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() {
    this.getList();
  },
  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 10px 5px;
        font-size: 14px;
        font-weight: 700;
      }

      .loc {
        padding-left: 10px;
        display: flex;
        align-items: center;
        margin-top: 6px;
        font-size: 12px;
        & > img {
          margin-right: 3px;
          width: 14px;
        }
      }
    }
  }
  .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: absolute;
      bottom: 40px;
      width: 200px;
      z-index: 2;
      left: 50%;
      transform: translateX(-50%);
    }
  }

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