<template>
  <div class="son5">
    <div class="sonBj1"></div>
    <div
      class="rowBox"
      v-for="item in data"
      :key="item.id"
      :class="{ noPad: item.pad, centenAc: item.centen }"
    >
      <div
        class="rowinfo"
        :class="{ move: item.move }"
        @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>
</template>

<script>
export default {
  name: "son5",
  components: {},
  props: {
    scrool: {
      type: Number,
      default: 0,
    },
  },
  data() {
    //这里存放数据
    return {
      data: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    scrool(val) {
      this.data.forEach((v) => {
        if (v.move) return;
        else if (val > v.moveNum) v.move = true;
      });
    },
  },
  //方法集合
  methods: {
    toInfo(id) {
      window.lodingGoods = false;
      this.$router.push(`/info/${id}`);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    if (window.lodingGoods) {
      this.data = [
        {
          id: 25,
          name: "清鹤顶骨嘴犀角杆竹节形鸦片烟枪",
          ww: "200px",
          hh: "43px",
          move: false,
        },
        {
          id: 26,
          name: "清玉嘴竹杆包铜“光庭写”款瓷斗鸦片烟枪",
          ww: "184px",
          hh: "60px",
          move: false,
        },
        {
          id: 27,
          name: "清玉嘴铜杆“庚午夏”款瓷斗鸦片烟枪",
          ww: "207px",
          hh: "45px",
          move: false,
        },
        {
          id: 28,
          name: "清玻璃罩铜底座青花菊花纹瓷鸦片烟灯",
          ww: "118px",
          hh: "237px",
          move: false,
        },
        {
          id: 29,
          name: "清玻璃罩富贵寿考花鸟纹铜鸦片烟灯",
          ww: "128px",
          hh: "231px",
          move: false,
        },
        {
          id: 30,
          name: "19世纪掐丝洋花卉纹铜胎珐琅木底盖鸦片烟具",
          ww: "179px",
          hh: "107px",
          move: false,
        },
        {
          id: 31,
          name: "清代铜鸦片烟具",
          ww: "152px",
          hh: "120px",
          move: false,
        },
        {
          id: 32,
          name: "清佚名画家绘吸食鸦片图通草纸水彩画",
          ww: "233px",
          hh: "183px",
          pad: true,
          move: false,
        },
        {
          id: 33,
          name: "19世纪吸食鸦片的中国人印刷铜版画",
          ww: "237px",
          hh: "208px",
          pad: true,
          move: false,
        },
        {
          id: 34,
          name: "1850年吸食鸦片的中国人彩色印刷铜版画",
          ww: "251px",
          hh: "226px",
          pad: true,
          move: false,
        },
        {
          id: 35,
          name: "19世纪鸦片危害漫画",
          ww: "227px",
          hh: "316px",
          pad: true,
          centen: true,
          move: false,
        },
        {
          id: 36,
          name: "1922年陈乐琴愁城十二景四条屏",
          ww: "100%",
          hh: "auto",
          pad: true,
          move: false,
        },
      ];
      this.$nextTick(() => {
        setTimeout(() => {
          let doms = document.querySelectorAll(".rowinfo");
          let temp = 0;
          doms.forEach((v, i) => {
            if (i === 0) temp = v.getBoundingClientRect().top / 2;
            this.data[i].moveNum = v.getBoundingClientRect().top - temp - 100;
          });
        }, 100);
      });
    }
  }, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
.son5 {
  .rowBox {
    padding: 0 24px;
    margin-bottom: 50px;
    display: flex;
    .rowinfo {
      opacity: 0;
      transition: all 1s ease-out;
      transform: translateX(-400px);
      & > img {
        width: 100%;
      }
      & > p {
        color: #ffffff;
        font-size: 16px;
        text-align: center;
        width: 100%;
        padding: 10px;
        line-height: 24px;
      }
    }
    .move {
      opacity: 1;
      transform: translateX(0px) !important;
    }
    &:nth-of-type(2n + 1) {
      justify-content: flex-end;
      .rowinfo {
        transform: translateX(400px);
      }
    }
  }
  .noPad {
    padding: 0;
  }
  .centenAc {
    justify-content: center !important;
  }
}
</style>