<template>
  <div class="son4">
    <!-- 点击视频播放的盒子 -->
    <div class="videoPlayBox" v-if="videoId">
      <video controls autoplay :src="`data/${videoId}.mp4`"></video>
      <!-- 关闭按钮 -->
      <div class="close" @click="videoId = null"></div>
    </div>

    <div class="sonBj1"></div>
    <div
      class="rowBox"
      v-for="item in data"
      :key="item.id"
      :class="{ noPad: item.pad }"
    >
      <div class="row" @click="toInfo(item.id)" :style="`width: ${item.ww};`">
        <img
          :style="`height: ${item.hh};`"
          :src="require(`@/assets/img/zhanpin/${item.id}.png`)"
          alt=""
        />
        <p>{{ item.name }}</p>
      </div>
    </div>
    <div class="sonBj2"></div>
    <!-- 视频 -->
    <div class="videoBox">
      <div class="vidPlay" @click="videoId = '3'"></div>
      <img src="../assets/img/vid3.png" alt="" />
    </div>
    <div class="shuming">《鸦片生产制作》</div>
  </div>
</template>

<script>
export default {
  name: "son4",
  components: {},
  data() {
    //这里存放数据
    return {
      videoId: null,
      data: [
        {
          id: 20,
          name: "罂粟壳",
          ww: "166px",
          hh: "90px",
          pad: true,
        },
        {
          id: 21,
          name: "东印度公司刀剑",
          ww: "218px",
          hh: "311px",
          pad: true,
        },
        {
          id: 22,
          name: "东印度旗帜",
          ww: "254px",
          hh: "161px",
          pad: true,
        },
        {
          id: 23,
          name: "1810年东印度公司伦敦总部印刷铜版画",
          ww: "232px",
          hh: "169px",
        },
        {
          id: 24,
          name: "1828年东印度公司伦敦总部印刷铜版画 ",
          ww: "233px",
          hh: "200px",
        },
      ],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    videoId(val) {
      this.$nextTick(() => {
        // 获取body，防止滚动
        let body = document.querySelector("body");
        if (val === null) body.style.overflow = "auto";
        else body.style.overflow = "hidden";
      });
    },
  },
  //方法集合
  methods: {
    toInfo(id) {
      this.$router.push(`/info/${id}`);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.son4 {
  .videoPlayBox {
    position: fixed;
    width: 100vw;
    height: 100vh;
    z-index: 999;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.9);
    video {
      position: absolute;
      width: 100%;
      max-height: 60vh;
      top: 50%;
      transform: translateY(-50%);
    }
    .close {
      position: absolute;
      bottom: 20px;
      left: 50%;
      transform: translateX(-50%);
      width: 32px;
      height: 32px;
      background: url("../assets/img/close.png");
      background-size: 100% 100%;
    }
  }
  .videoBox {
    position: relative;
    & > img {
      width: 100%;
    }
    .vidPlay {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 77px;
      height: 77px;
      background: url("../assets/img/videoPlay.png");
      background-size: 100% 100%;
    }
  }
  .rowBox {
    padding: 0;
    margin-bottom: 50px;
    display: flex;
    .row {
      & > img {
        width: 100%;
      }
      & > p {
        color: #ffffff;
        font-size: 16px;
        text-align: center;
        width: 100%;
        padding: 10px;
        line-height: 24px;
      }
    }
    &:nth-of-type(2n + 1) {
      justify-content: flex-end 
    }
  }
  .noPad {
    padding: 0 24px;
  }
}
</style>