product-group-item.vue 6.25 KB
<template>
  <div
    class="product-item"
    :class="itemClass">
    <div class="product-content" @click="onClick">
      <div class="product-image">
        <div v-if="!hasStock" class="no-stock-cover">
          <span>已售罄</span>
        </div>
        <ImageFormat class="image" :lazy="lazy" :src="product.productImage" :width="136" :height="180"></ImageFormat>
      </div>
      <div class="product-info">
        <p class="product-name">{{product.productName}}</p>
        <div class="price-wrap">
          <div class="price-left">
            <label v-if="product.collage_activity_id" class="collage-tag">
              <span>拼团价</span>
            </label>
            <span class="price">¥{{salesPrice}}</span>
          </div>
          <div class="btn-right btn-buy hover-opacity" :class="{'btn-disable': !hasStock}">
            <span class="iconfont icon-cart"></span>购买
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import YAS from 'utils/yas-constants';

export default {
  name: 'ProductGroupItem',
  props: {
    single: Boolean,
    lazy: Boolean,
    product: Object,
    share: Boolean,
    thumb: Boolean,
    posId: Number,
    articleId: [String, Number],
    index: Number,
    model: String
  },
  data() {
    return {
      posting: false,
      favorite: this.product.favorite
    };
  },
  watch: {
    'product.favorite'(val) {
      this.favorite = val;
    }
  },
  computed: {
    itemClass() {
      return {
        single: this.single,
        [`product-model-${this.model}`]: this.model
      };
    },
    favClass() {
      return {
        'btn-is-fav': this.favorite,
        loading: this.posting,
        invisible: this.thumb
      };
    },
    favText() {
      return this.favorite ? '已收藏' : '收藏';
    },
    hasStock() {
      return this.product.has_stock !== 'N';
    },
    salesPrice() {
      return this.product.collage_activity_id ? this.product.collage_price : this.product.salesPrice;
    }
  },
  methods: {
    onClick(e) {
      if (e.timeStamp - this._lastTime < 1200) {
        return;
      }

      this._lastTime = e.timeStamp;

      let skn = this.product.productSkn;

      if (!skn) {
        return;
      }

      let name = this.$yoho.isiOS ? 'iFP_ArticleList' : 'aFP_ArticleList';

      if (this.product.productType === 1) {
        this.$yoho.goProductDetail({skn, name, articleId: this.articleId});
      } else if (this.product.productType === 2) {
        this.$yoho.goUfoProductDetail({skn, name, articleId: this.articleId});
      }

      this.reportProduct(skn);
    },
    reportProduct(skn) {
      this.$store.dispatch('reportYas', {
        params: {
          appop: YAS.eventName.productClick,
          param: {
            POS_ID: this.posId,
            ARTICLE_ID: this.articleId,
            PRD_SKN: skn,
          }
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.product-item {
  margin-right: 20px;
  margin-left: 30px;
  height: 180px;
  width: 580px;
  background-color: #fff;
  display: inline-block;
  white-space: initial;
  overflow: hidden;
  vertical-align: top;

  &:last-child {
    margin-right: 50px;
  }

  &.single {
    width: 690px;
    margin-right: 0;
  }
}

.product-content {
  display: flex;
  align-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid #f0f0f0;
}

.product-image {
  width: 136px;
  height: 100%;
  display: flex;
  align-items: center;
  position: relative;

  .no-stock-cover {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    color: #fff;
    font-weight: 300;
    line-height: 1;
    background-color: rgba(34, 34, 34, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;

    > span {
      display: inline-block;
      font-size: 24px;
      transform: scale(0.85, 0.85);
    }
  }

  .image {
    max-width: 100%;
    max-height: 100%;
  }
}

.product-info {
  padding-left: 20px;
  flex: 1;

  .product-name {
    font-size: 24px;
    line-height: 36px;
    color: #9b9b9b;
    height: 72px;
    padding-right: 10px;
    margin-bottom: 26px;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .price-wrap {
    font-size: 28px;
    color: #222;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .price-left {
    display: flex;
    align-items: center;
  }

  .collage-tag {
    width: 94px;
    height: 28px;
    margin-right: 16px;
    background-color: #ff5660;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;

    > * {
      font-size: 24px;
      font-weight: 300;
      transform: scale(0.7, 0.7);
    }
  }
}

.btn-right {
  width: 120px;
  height: 50px;
  font-size: 24px;
  background-size: contain;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  letter-spacing: 0.2PX;
  margin-right: -1px;
}

.btn-buy {
  background-color: #222;

  .iconfont {
    font-size: 30px;
    margin-right: 5px;
  }
}

.btn-fav {
  background-color: #444;

  &.btn-is-fav {
    background-color: #b0b0b0;
  }

  & /deep/ .iconfont {
    margin: 0;
  }
}

.btn-disable {
  background-color: #b0b0b0;
}

.product-model-2 {
  width: 170px;
  height: auto;
  overflow: visible;
  margin-left: 20px;
  margin-right: 0;

  .product-content {
    display: block;
    border: 0;
    position: relative;
  }

  .product-image {
    width: 100%;
    height: 226px;
  }

  .product-info {
    padding: 0;
    margin-top: 12px;

    .product-name {
      height: 66px;
      font-size: 25px;
      line-height: 1.4;
      padding-right: 0;
      margin-bottom: 0;
      color: #444;
      letter-spacing: 1PX;
      width: 213px;
      transform: translateX(-21px) scale(0.8);
    }

    .price {
      width: 126px;
      height: 50px;
      color: #fff;
      font-size: 25px;
      line-height: 1;
      font-weight: 300;
      position: absolute;
      top: 166px;
      right: -22px;
      background-color: #444;
      display: flex;
      justify-content: center;
      align-items: center;
      transform: scale(0.8);


      > * {
        display: none;
      }

      > span {
        display: inline;
      }
    }
  }

}
</style>