<template>
  <view class="item-wrap" v-if="goods && goods.length > 0">
    <view v-for="(product, p) in goods" :key="p" class="item">
      <good-short
        :moudle="moudle"
        :good="product"
        :show="show"
        :imgH="img.h2"
      />
    </view>
  </view>
</template>

<script>
// 设置列表
import goodShort from "./goodShort.vue";
export default {
  components: {
    goodShort,
  },
  props: {
    moudle: {
      type: String,
      default: "goodIntegral",
    },
    arg: {
      type: String,
      default: "",
    },
    groupKey: {
      type: String,
      default: "left",
    },
    goodKey: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      goods: [],
      show: {},
      img: {},
    };
  },
  created() {
    const dataKey = `${this.groupKey}-${this.goodKey}`;
    let parent = {};
    // #ifdef H5
    parent = this.$parent.$parent.$parent;
    if (!parent.allGoods) parent = parent.$parent;
    if (!parent.allGoods) parent = parent.$parent;
    if (!parent.allGoods) parent = parent.$parent;
    // #endif
    // #ifndef H5
    parent = this.$parent;
    // #endif
    if (parent.allGoods) {
      this.goods = parent.allGoods[dataKey];
      this.img = parent.img;
      this.show = parent.show;
    }
  },
  computed: {
    scrollH() {
      if (this.arg == "scroll-two") {
        const h = parseInt((this.img.h2 || "").replace("px", "")) + 14;
        return h + "px";
      } else if (this.arg == "scroll-three") {
        const h = parseInt((this.img.h3 || "").replace("px", "")) + 14;
        return h + "px";
      }
      return "";
    },
  },
  watch: {
    goodKey(val) {
      if (val) {
        const dataKey = `${this.groupKey}-${this.goodKey}`;
        this.goods = this.$parent.allGoods[dataKey];
      }
    },
  },
};
</script>
